CF1761B.Elimination of a Ring

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

Elimination of a Ring

Define a cyclic sequence of size nn as an array ss of length nn, in which sns_n is adjacent to s1s_1.

Muxii has a ring represented by a cyclic sequence aa of size nn.

However, the ring itself hates equal adjacent elements. So if two adjacent elements in the sequence are equal at any time, one of them will be erased immediately. The sequence doesn't contain equal adjacent elements initially.

Muxii can perform the following operation until the sequence becomes empty:

  • Choose an element in aa and erase it.

For example, if ring is [1,2,4,2,3,2][1, 2, 4, 2, 3, 2], and Muxii erases element 44, then ring would erase one of the elements equal to 22, and the ring will become [1,2,3,2][1, 2, 3, 2].

Muxii wants to find the maximum number of operations he could perform.

Note that in a ring of size 11, its only element isn't considered adjacent to itself (so it's not immediately erased).

Input

Each test contains multiple test cases. The first line contains a single integer tt (1t1001\leq t\leq 100) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (1n1001\leq n\leq 100) — the size of the cyclic sequence.

The second line of each test case contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1ain1\leq a_i\leq n) — the sequence itself.

It's guaranteed that aiai+1a_i\ne a_{i+1} for 1i<n1\leq i \lt n.

It's guaranteed that ana1a_n\ne a_1 when n>1n \gt 1.

Output

For each test case, output a single integer — the maximum number of operations Muxii can perform.

Note

In the first test case, you can erase the second element first, then erase the remaining elements one by one in any order. In total, you can perform the operation 44 times. Note that if you erase the first element first, then the sequence will be turned into [2,3,2][2,3,2] and then immediately become [2,3][2,3].

In the second test case, you can erase the first element first, then the sequence becomes [2,1][2,1]. Then you can erase all remaining elements one by one in any order.

Samples

3
4
1 2 3 2
4
1 2 1 2
1
1
4
3
1

在线编程 IDE

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