SIMPLFYIT - Simplify IT

no tags 

Nowadays computer can do a lot of things, can't it? But how? Yes, you are the answer. The biggest secret behind capability of the computer is some programmer like you. They wrote some programs and computer only follow these. That's it.

Anyway, your task is to write some program that will be followed by the computer to simplify an algebraic expression.

The initial expression is 0. There will be 3 types of command. These are:

1 <expression>

2 <expression>

3

 

For command-type 1, you have to add <expression> to the existing expression. For command-type 2, you have to subtract <expression> from the existing expression. For command-type 3, you have to print the existing expression.

 

For simplicity the <expression> will contain 2 variables, such as 'a' and 'b'. and the <expression> will be in the following format:

CaPbQ

where 'C' is a constant, 'a' and 'b' are variable and 'P' and 'Q' are the power of 'a' and 'b' respectively.

Nowadays computer can do a lot of things, can't it? But how? Yes, you are the answer. The biggest secret behind capability of the computer is some programmer like you. They wrote some programs and computer only follow these. That's it.
Anyway, your task is to write some program that will be followed by the computer to simplify an algebraic expression.
The initial expression is 0. There will be 3 types of command. These are:
1 <expression>
2 <expression>
3
 
For command-type 1, you have to add <expression> to the existing expression. For command-type 2, you have to subtract <expression> from the existing expression. For command-type 3, you have to print the existing expression.
 
For simplicity the <expression> will contain 2 variables, such as 'a' and 'b'. and the <expression> will be in the following format:
CaPbQ
where 'C' is a constant, 'a' and 'b' are variable and 'P' and 'Q' are the power of 'a' and 'b' respectively.

 

Input

The first line will contain an integer T which denotes the number of test cases. For T cases, there will be a number N which denotes the number of command for this case. Then the following N lines contain commands for the case mentioned above.

The absolute value of 'C', 'P' and 'Q' is less than or equal to 10. T and N will be a positive integer less than or equal to 101.

Output

For each command type 3, print the current expression. Print the part first which has the lower power of 'a'. If the power of 'a' is equal then print the part first which has the lower power of 'b'.

Example

Input:
1
11
3
1 2a1b1
3
1 1a2b0
3
2 1a0b2
3
2 1a5b1
3
1 1a2b0
3
Output:
0
2ab
2ab+a2
-b2+2ab+a2
-b2+2ab+a2-a5b
-b2+2ab+2a2-a5b
 
Note: In "-b2+2ab+2a2-a5b", 1st part has 'a' with power 0, 2nd part has 'a' with power 1, 3rd part has 'a' with power 2, 4th part has 'a' with power 5.


Added by:Sarwar
Date:2018-05-26
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All