

There can be 4 operators: +,-,*,/. For division, you need to return the floor(a/b).
Consider the following expression tree:

While evaluating the expression tree we replace the value at a node with any operation OP by evaluating LEFTCHILD (OP) RIGHTCHILD
Here, the expression will be evaluated as 20 - 10 = 10 (FOR β-β), then β-β will be replaced by 10 (symbolic), then we evaluate for nodeβ+β, 10 + 10 = 20.
The first line of input contains an integer βTβ representing the number of test cases. Then the test cases follow.
The only line of each test case contains elements in the level order form. The line consists of values of nodes separated by a single space. In case a node is null, we take -1 in its place.
For example, the input for the tree depicted in the below image would be:

+
- -
20 10 30 10
-1 -1 -1 -1 -1 -1 -1 -1
Level 1:
The root node of the tree is β+β.
Level 2:
Left child of β+β = β-β
Right child of β+β = β-β
Level 3:
Left child of β-β = 20
Right child of β-β = 10
Left child of β-β = 30
Right child of β-β = 10
Level 4:
Left child of 20 = null (-1)
Right child of 20 = null(-1)
Left child of 10 = null (-1)
Right child of 10 = null (-1)
Left child of 30 = null (-1)
Right child of 30 = null (-1)
Left child of 10 = null (-1)
Right child of 10 = null (-1)
The first not-null node(of the previous level) is treated as the parent of the first two nodes of the current level. The second not-null node (of the previous level) is treated as the parent node for the next two nodes of the current level and so on.
The input ends when all nodes at the last level are null(-1).
The above format was just to provide clarity on how the input is formed for a given tree.
The sequence will be put together in a single line separated by a single space. Hence, for the above-depicted tree, the input will be given as:
+ - - 20 10 30 10 -1 -1 -1 -1 -1 -1 -1 -1
For each test case, the output will be the evaluated value for the expression tree.
The output for each test case will be in a separate line.
You do not need to print anything; it has already been taken care of.
1 <= T <= 100
1 <= N <= 2047
1 <= data <= 1000
Time Limit: 1 second
Consider function EVALUATEEXPRESSION that accepts as a parameter, a BinaryTreeNode of Strings, ROOT and do:
Maximum Island Size in a Binary Tree
Equal Subtree Sums
Sorted Doubly Linked List to Balanced BST
Longest Substring with K-Repeating Characters
Expression Add Operators