


1. Do not print anything, just return an integer which is the maximum possible sum for the three stacks.
2.It is guaranteed that the elements in the stack are positive integers.
3.It can be proved that a non-negative integer answer always exists.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next ‘3*T’ lines represent the ‘T’ test cases.
The first line of each test case contains a stream of integers which are in the order of which the elements are pushed in ‘stack1’. The stream ends when the input is -1. The top of the stack is the element just before -1. Note that -1 is not pushed in the stack.
The second line of each test case contains a stream of integers which are in the order of which the elements are pushed in ‘stack2’. The stream ends when the input is -1. The top of the stack is the element just before -1. Note that -1 is not pushed in the stack.
The third line of each test case contains a stream of integers which are in the order of which the elements are pushed in ‘stack3’. The stream ends when the input is -1. The top of the stack is the element just before -1. Note that -1 is not pushed in the stack.
For each test case, return a single integer denoting the maximum equal sum for the three stacks.
1 <= T <= 50
1<= N <=10^4
1<= stackData <=10^9
Where ‘T’ is the total number of test cases, ‘N’ denotes the number of elements in any of the stacks and ‘stackData’ represents the data in the stacks.
Time limit: 1 second
2
2 4 1 9 -1
1 6 3 -1
5 2 1 -1
8 2 1 -1
1 1 1 -1
6 3 -1
7
0
Test Case 1:
The stacks are:

We can see that currently,
the sum of stack 1 is:9+1+4+2=16
the sum of stack 2 is: 3+6+1=10
the sum of stack 3 is: 5+2+1=8
So they are not equal.
However, if we pop {9,1} from stack 1 {3} from stack 2 and {1} from stack 3,
We get the sum as :
Stack 1: 16-9-1=7
Stack 2: 10-3=7
Stack 3: 8-1=7
We can see that now the sum of all 3 stacks are equal which is 7 and it is the highest possible, hence we return 7.
Test Case 2:

We can see that currently,
the sum of stack 1 is: 6+3=9
the sum of stack 2 is: 1+1+1=3
the sum of stack 3 is: 1+2+8=11
So they are not equal.
Now, no matter what we do we can never make the sum equal to any number for all the three stacks except 0. So, in this case, we return 0.
2
2 2 4 6 -1
14 6 8 1 -1
7 7 6 4 -1
9 9 9 9 -1
20 7 -1
5 6 7 9 -1
14
27
Keeping the above example in mind, we can write the following Recursive solution:
Keeping the above example in mind, we can write the following Recursive solution:
We can take the following approach: