Gogi, Tapu, and Sonu are elite members of the Tapu Sena. Gogi, in one of his rare moments of seriousness, posed an interesting question to Tapu. Tapu wants to impress Sonu by solving this problem.
Given an array of length ( N ), Tapu is allowed to perform the following operations exactly once:
Remove any contiguous subarray from the given array, provided that the resulting array after removal is non-empty.
Reverse the entire array.
The goal is to determine the maximum possible GCD (Greatest Common Divisor) of all the numbers in the resulting array after applying the above operations.
Input Format
The first line contains an integer ( T ) (the number of test cases).
For each test case:
The first line contains an integer ( N ) (the length of the array).
The second line contains ( N ) integers, which are the elements of the array.
Output Format
For each test case, output a single integer: the maximum possible GCD after performing the allowed operations.
Constraints
( 1 \leq T \leq 100 )
( 1 \leq N \leq 10^4 )
( 1 \leq a[i] \leq 10^9 )
The summation of ( N ) for all test cases is less than ( 10^6 ).
Example
Sample Input
text
1
1
2
Sample Output
text
2
Explanation
In this sample, when there is only one element in the array, Tapu cannot remove any subarray without making the resulting array empty. Therefore, the maximum GCD possible remains the only element itself, which is 2.
Solution Submission
Please implement your solution in the /app/ directory.
Important: place your implementation at /app/solution.py so the verifier can run it.