CF1732A.Bestie

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

Bestie

You are given an array aa consisting of nn integers a1,a2,,ana_1, a_2, \ldots, a_n. Friends asked you to make the greatest common divisor (GCD) of all numbers in the array equal to 11. In one operation, you can do the following:

  • Select an arbitrary index in the array 1in1 \leq i \leq n;
  • Make ai=gcd(ai,i)a_i = \gcd(a_i, i), where gcd(x,y)\gcd(x, y) denotes the GCD of integers xx and yy. The cost of such an operation is ni+1n - i + 1.

You need to find the minimum total cost of operations we need to perform so that the GCD of the all array numbers becomes equal to 11.

Input

Each test consists of multiple test cases. The first line contains an integer tt (1t50001 \leq t \leq 5\,000) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (1n201 \leq n \leq 20) — the length of the array.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \leq a_i \leq 10^9) — the elements of the array.

Output

For each test case, output a single integer — the minimum total cost of operations that will need to be performed so that the GCD of all numbers in the array becomes equal to 11.

We can show that it's always possible to do so.

Note

In the first test case, the GCD of the entire array is already equal to 11, so there is no need to perform operations.

In the second test case, select i=1i = 1. After this operation, a1=gcd(2,1)=1a_1 = \gcd(2, 1) = 1. The cost of this operation is 11.

In the third test case, you can select i=1i = 1, after that the array aa will be equal to [1,4][1, 4]. The GCD of this array is 11, and the total cost is 22.

In the fourth test case, you can select i=2i = 2, after that the array aa will be equal to [3,2,9][3, 2, 9]. The GCD of this array is 11, and the total cost is 22.

In the sixth test case, you can select i=4i = 4 and i=5i = 5, after that the array aa will be equal to [120,60,80,4,5][120, 60, 80, 4, 5]. The GCD of this array is 11, and the total cost is 33.

Samples

9
1
1
1
2
2
2 4
3
3 6 9
4
5 10 15 20
5
120 60 80 40 80
6
150 90 180 120 60 30
6
2 4 6 9 12 18
6
30 60 90 120 125 125
0
1
2
2
1
3
3
0
1

在线编程 IDE

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