Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the trail and notices that two consecutive stones have a difference of either or . Legend has it that there is a treasure trove at the end of the trail and if Manasa can guess the value of the last stone, the treasure would be hers. Given that the number on the first stone was , find all the possible values for the number on the last stone.
Note: The numbers on the stones are in increasing order.
The first line contains an integer , i.e. the number of test cases. test cases follow; each has 3 lines. The first line contains (the number of stones). The second line contains , and the third line contains .
Space-separated list of numbers which are the possible values of the last stone in increasing order.
2 3 4
30 120 210 300
All possible series for the first test case are given below:
Hence the answer 2 3 4.
Series with different number of final steps for second test case are the following: