CF1826B.Lunatic Never Content

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Lunatic Never Content

You have an array aa of nn non-negative integers. Let's define $f(a, x) = [a_1 \bmod x, a_2 \bmod x, \dots, a_n \bmod x]$ for some positive integer xx. Find the biggest xx, such that f(a,x)f(a, x) is a palindrome.

Here, amodxa \bmod x is the remainder of the integer division of aa by xx.

An array is a palindrome if it reads the same backward as forward. More formally, an array aa of length nn is a palindrome if for every ii (1in1 \leq i \leq n) ai=ani+1a_i = a_{n - i + 1}.

Input

The first line contains a single integer tt (1t1051 \leq t \leq 10^5) — the number of test cases.

The first line of each test case contains a single integer nn (1n1051 \leq n \leq 10^5).

The second line of each test case contains nn integers aia_i (0ai1090 \leq a_i \leq 10^9).

It's guaranteed that the sum of all nn does not exceed 10510^5.

Output

For each test case output the biggest xx, such that f(a,x)f(a, x) is a palindrome. If xx can be infinitely large, output 00 instead.

Note

In the first example, f(a,x=1)=[0,0]f(a, x = 1) = [0, 0] which is a palindrome.

In the second example, f(a,x=2)=[1,0,1,0,0,1,0,1]f(a, x = 2) = [1, 0, 1, 0, 0, 1, 0, 1] which is a palindrome.

It can be proven that in the first two examples, no larger xx satisfies the condition.

In the third example, f(a,x)=[0]f(a, x) = [0] for any xx, so we can choose it infinitely large, so the answer is 00.

Samples

4
2
1 2
8
3 0 1 2 0 3 2 1
1
0
3
100 1 1000000000
1
2
0
999999900

在线编程 IDE

建议全屏模式获得最佳体验