

The first line contains 'T', denoting the number of test cases.
For each Test :
The first line contains one integer, Num.
The second line contains an array A of Num space separated integers, with a positive integer representing a node and -1 representing a NULL value. The input is given in 'Level Order'. See samples explanation for more detail.
( Note that Num is not the number of nodes, and number of nodes = number of positive integers in A.)
For each test case, print one integer, that is, the total money you can earn from the longest path.
You are not required to print the expected output. It has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= Num <= 10^5
1 <= A[i] <= 10^4 or A[i] = -1, i ∈ (1,Num)
Note - The sum of 'Num’ over all test cases does not exceed 10^5.
Time Limit: 1 sec
We can store a pair of values, denoting the maximum length from that path, and its sum. If there are multiple paths of the same length, we choose the one with the maximum sum.
Algorithm: