Crazy GCD#12230

Crazy GCD

2 seconds
256 megabytes
Medium

You are given an array of positive integers.

First, choose an integer (1 \le k \le n). Partition the array into groups according to indices modulo : for each c = 0,1,\dots,k-1, let \text{group}_c = \{ a_i \mid i \equiv c \pmod{k} \}.

Within each group, you may repeatedly perform the following operation:

After performing any number of operations (possibly zero), compute for each group the greatest common divisor g_c = \gcd(\text{group}_c). Collect them into a multiset M = \{ g_c \mid 0 \le c < k \}.

Your goal is to choose and apply operations so as to maximize

Input

The first line contains a positive integer (1 \le t \le 10^4) — the number of test cases.

The first line of each test case contains only a single positive integer (1 \le n \le 2000) — the length of the array .

The second line of each test case contains separated integers a_1,a_2,..,a_n (1 \le a_i \le 10^{9}) — the array .

It's guaranteed that \sum n \le 2000 overall tests

Output

For each test case, output on a separate line: Print the maximum that you can achieve in the multiset.

Examples

Example 1

Loading
Loading

Note

In the first test case , choose k=2 then

  • \text{group}_1=\{a_1\}=\{4\}

  • \text{group}_2=\{a_2\}=\{20\}

and thus \min(M)=\gcd(\{4\})=4.

In the second test case , choose k=1 then \text{group}_1=\{a_1,a_2,a_3,a_4\}=\{245,8575,1715,875\} , Initially \gcd(a)=35 but it can be improved with performing operations :

  1. Pick i=2 and j=4 with d=7 :

    • a_2 \leftarrow \frac{8575}{7}=1225

    • a_4 \leftarrow 875 \times 7=6125

Now the array becomes a=[245, 1225, 1715, 6125] and we've \gcd(a)=245 and it can be shown that's the minimum across all possible .

and thus \min(M)=\gcd(a)=245.

Scoring

  1. Subtask ( points) : (n=1).

  2. Subtask ( points) : (a_1=a_2=a_3...=a_n).

  3. Subtask ( points) : (\sum n \le 100) and (1 \le a_i \le 10^6).

  4. Subtask ( points) : (1 \le a_i \le 10^6)

  5. Subtask ( points) : (\sum n \le 1000).

  6. Subtask ( points) : No additional constraints