#CF2236E. 友好的礼物 / E. Friendly Gifts

友好的礼物 / E. Friendly Gifts

E. Friendly Gifts

Source: Codeforces 2236E
Contest: Codeforces Round 1103 (Div. 3)
Time limit: 3 seconds
Memory limit: 512 megabytes

Statement

Arseniy decided to make his friends Dabir and Egor happy. For this, he decided to give each of them an array of numbers of the same length. An array bb is called good if its elements can be rearranged so that for all i>1i \gt 1 the condition bibi1=1b_i - b_{i - 1} = 1 holds.

Arseniy wants Dabir and Egor to be able to play with these arrays. For this, the following conditions must be satisfied:

  • Each of the given arrays is good.
  • If you write one array after the other (in other words, concatenate them), the resulting array is also good.

Arseniy already has an array aa of length nn. He plans to cut both arrays from aa, that is, to choose two non-overlapping subsegments of the same length. Help Arseniy determine the maximum possible length of the resulting arrays.

Input

The first line contains a single integer tt (1t1000)(1 \le t \le 1000) — the number of test cases.

Then tt test cases follow.

The first line of each test case contains a single integer nn (1n6000)(1 \le n \le 6000).

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ain)(1 \le a_i \le n).

It is guaranteed that the sum of nn over all test cases does not exceed 60006000.

Output

For each test case, output a single integer — the maximum possible length of the arrays.

Note

In the first sample, it is impossible to select 22 arrays, so the answer is 00.

In the second sample, the maximum length of the selected arrays is 11. Arrays [11] and [22] can be selected.

In the fourth sample, the maximum length of the selected arrays is 22. You can select arrays [2,12, 1] and [4,34, 3].

In the fifth sample, the maximum length of the selected arrays is 11. One way to select arrays is [11] and [22]. Other methods are arrays [22] and [33], [33] and [44], or [44] and [55].

Examples

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