CF1343D.Constant Palindrome Sum

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

Constant Palindrome Sum

You are given an array aa consisting of nn integers (it is guaranteed that nn is even, i.e. divisible by 22). All aia_i does not exceed some integer kk.

Your task is to replace the minimum number of elements (replacement is the following operation: choose some index ii from 11 to nn and replace aia_i with some integer in range [1;k][1; k]) to satisfy the following conditions:

  • after all replacements, all aia_i are positive integers not greater than kk;
  • for all ii from 11 to n2\frac{n}{2} the following equation is true: ai+ani+1=xa_i + a_{n - i + 1} = x, where xx should be the same for all n2\frac{n}{2} pairs of elements.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases. Then tt test cases follow.

The first line of the test case contains two integers nn and kk (2n2105,1k21052 \le n \le 2 \cdot 10^5, 1 \le k \le 2 \cdot 10^5) — the length of aa and the maximum possible value of some aia_i correspondingly. It is guratanteed that nn is even (i.e. divisible by 22). The second line of the test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1aik1 \le a_i \le k), where aia_i is the ii-th element of aa.

It is guaranteed that the sum of nn (as well as the sum of kk) over all test cases does not exceed 21052 \cdot 10^5 (umn2105um n \le 2 \cdot 10^5, umk2105um k \le 2 \cdot 10^5).

Output

For each test case, print the answer — the minimum number of elements you have to replace in aa to satisfy the conditions from the problem statement.

Samples

4
4 2
1 2 1 2
4 3
1 2 2 1
8 7
6 1 1 7 6 3 4 6
6 6
5 2 6 1 3 4
0
1
4
2

在线编程 IDE

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