
You are given an array 'A' of length 'N' consisting of three-digit integers in ascending order. You can construct a binary tree from these integers. All integers are of form DPV (3 digits), where 'D' tells depth in the tree, 'P' tells position in the tree, and 'V' tells value in this position.

For Example:
215 means value 5 is in position 1 at depth 2.
Your task in the problem is to find the sum of all paths from node to leaf.
Note:
The maximum depth allowed is 4, i.e. the maximum number of positions can be 8 ( or 2 ^ (4 - 1)).
The first line of the input contains ‘T’ denoting the number of test cases.
The first line of each test case contains an integer ‘N’, representing the length of the array.
The second line of each test case contains N space-separated integers of the array A.
Output Format:
For each test case print a single line containing a single integer denoting the sum of all paths from the root node.
The output of each test case is printed on a new line.
1 <= T <= 10
1 <= N <= 150
100 <= A[i] <= 999
1 <= D <= 4
1 <= P <= 8
0 <= V <= 9
Where ‘T’ denotes the number of test cases and 'N' denotes the length of array 'A'.
Time limit: 1 sec.
2
3
113 215 221
2
113 221
12
4
For test case 1:

The path sum is (3 + 5) + (3 + 1) = 12.
For test case 2:

The path sum is (3 + 1) = 4.
2
3
115 217 322
4
117 212 313 421
14
13
Can we use DFS approach?
Explanation:
Algorithm:
O(N), where ‘N’ is the length of the array.
As we will only be traversing the array and the tree, which contains ‘N’ nodes. The time complexity will be O(N).
O(N), where ‘N’ is the length of the array.
The only space required will be to make a map/hash, which is O(N) in space.