Beautiful Partition

Split an array into two non-empty parts and maximize the smaller of the two part gcds.

Medium7Number theoryMathBrute forceGreedyNo attempts yetTime limit2sMemory limit256 MB

Problem

Peter has just learned what the greatest common divisor of a set of integers is. He likes the idea so much that now he looks for it in everything he sees.

During today's computer science lesson the teacher wrote an array of integers on the blackboard, and Peter noticed that its elements can be divided into two parts M1M_1 and M2M_2 so that gcd(M1)\gcd(M_1) and gcd(M2)\gcd(M_2) are both quite big. Here gcd(M)\gcd(M) is the greatest common divisor of all numbers in MM.

Peter has decided to generalize the problem. For a given array, divide all of its elements into two non-empty parts M1M_1 and M2M_2, with every element going into exactly one part, so that min(gcd(M1),gcd(M2))\min(\gcd(M_1), \gcd(M_2)) is as large as possible. Print that largest value.

Input

The input contains several tests. The first line contains the number of tests tt (1t10001 \le t \le 1000).

Each test is given on two lines. The first line contains an integer nn (2n5×1042 \le n \le 5 \times 10^4), the size of the array. The second line contains nn integers aia_i (1ai1091 \le a_i \le 10^9), the elements of the array.

The sum of the values of nn over all tests in one input does not exceed 5×1045 \times 10^4.

Output

For each test print one integer on its own line: the largest possible value of min(gcd(M1),gcd(M2))\min(\gcd(M_1), \gcd(M_2)).