Manmohan seeing the present conditions of Congress for the upcoming elections, came up with a brilliant idea for getting the attention of public. Well the idea neither controls inflation nor it's about the Petrol price. It's all about Time Travelling which enables to stop the terrorist attacks that happened in the past. The idea seems very crazy though but the congressmen are really serious. So, Rahul Gandhi asked Sachin Pilot to build a Time Machine. The Time machine is more complex and it involves 2D algebraic mathematical equations that needs to be solved precisely. Since Pilot is not good at solving equations he is in need of your help. So please help him solve those equations. The equations are represented in an MXN matrix form in infix format.
The matrix needs to be evaluated according to the following priority :
These are binary(not unary) operators which means it requires two operands to work.
The equation is evaluated both row-wise and column-wise.
Associativity is right-to-left for row and bottom-to-top for column.
Note :
1) An Operator can even occur at the start/end of a row, ignore it for evaluation of that row but you have to consider it during the evaluation of a column.
Eg :
Rows Sum
22 22
-3 3 [It's not -3]
34 34
[Same also applicable when the operator occur at the start/end of a column.]
Input :
Number of Test Cases T
For each Test Case, Two integer follows M and N.
Then a MXN matrix follows.
1<=M<=10 , 1<=N<=10
Output:
Evaluate rows and columns according to the above rules and print their sum.
2 5 7 ~3~1233 3*4+2*3 12+3*16 ~36*424 1242~45 10 9 663815145 8~3/814-7 63*13422- 7321/38~6 9-9358*61 84-625125 3643195~8 993664831 19-2857-7 323455515
First Test Case 31233 -> 31233 34+23 -> 54 12+316 -> 240 ~36424 -> 15264 1242~45 ->124245 Row Sum=171036 Likewise for the 7 columns : 311 696 68 8 88 372 33645 Column sum=35188 Total Sum=206224