There is a grid with $$$n \times m$$$ cells (arranged in $$$n$$$ rows and $$$m$$$ columns). Initially, each cell contains the number $$$0$$$.
There are $$$q$$$ operations performed, where each operation consists of replacing the number written in each of the cells of a given row or column with a number $$$x$$$.
Output the sum of the numbers in the grid after performing the $$$q$$$ operations.
The input begins with a line containing the number of cases $$$T$$$.
Each case starts with a line containing three integers $$$n, m, q$$$. This is followed by $$$q$$$ lines, each containing a character $$$c_i$$$, which is "F" if the operation is on a row and "C" if it is on a column, an integer $$$a_i$$$, which indicates the row or column on which the operation is applied, and an integer $$$x_i$$$, the number to be written.
For each case, print a line with the sum of all the numbers written in the grid after performing the $$$q$$$ operations.
$$$1 \leq T \leq 500$$$
$$$1 \leq n, m, q \leq 5 \cdot 10^5$$$, the sum of $$$n$$$, the sum of $$$m$$$, and the sum of $$$q$$$ for all cases are all less than $$$3 \cdot 10^6$$$.
For operations where $$$c_i = F$$$, $$$1 \leq a_i \leq n$$$. For operations where $$$c_i = C$$$, $$$1 \leq a_i \leq m$$$.
$$$0 \leq x_i \leq 10^6$$$ for $$$i = 1, \ldots, q$$$.
14 points: $$$n, m, x_i, q \leq 1000$$$, the sum of $$$n \cdot m + q \cdot (n + m)$$$ for all cases is less than $$$5 \cdot 10^6$$$.
28 points: $$$n, m, x_i \leq 1000$$$, the sum of $$$n \cdot m$$$ for all cases is less than $$$5 \cdot 10^6$$$.
11 points: $$$n = 1$$$.
22 points: $$$x_i = 1$$$ for $$$i = 1, \ldots, q$$$.
25 points: No additional restrictions.
4 2 2 3 F 1 1 C 1 2 C 2 3 3 4 4 F 1 2 F 2 4 C 3 3 F 1 5 1 1 1 F 1 0 1 500000 1 F 1 1000000
10 38 0 500000000000