#CF2230C. C. Arrange the Numbers in a Circle
C. Arrange the Numbers in a Circle
C. Arrange the Numbers in a Circle
You have cards with numbers: cards with the number , cards with the number , ..., cards with the number .
You must take at least three cards from the ones you have and arrange them in a circle so that the following condition holds:
-
in every triple of consecutive cards, there are at least two equal cards. Formally, if the numbers on the chosen cards are in the order they are arranged in a circle, then the following condition must hold:
-
for every from to , there are at least two equal numbers among . What is the maximum number of cards you can arrange?
The first line contains one integer () — the number of test cases.
Each test case consists of two lines:
- the first line contains one integer ();
- the second line contains integers (). Additional constraint on the input: the sum of over all test cases does not exceed .
For each test case, output one integer — the maximum number of cards you can arrange. If it is impossible to choose three or more cards and arrange them in a circle so that the condition holds, output .
ExampleNoteIn the first example, you can choose and arrange the cards as follows: . You cannot arrange more than cards. For example, the arrangement does not work, because the cards must be arranged in a circle, and the condition also applies to the triple consisting of the second-to-last, last, and first cards.
In the second example, you can arrange all the cards: .
In the third example, you can choose and arrange the cards as follows: .
Input
InputThe first line contains one integer () — the number of test cases.
Each test case consists of two lines:
- the first line contains one integer ();
- the second line contains integers (). Additional constraint on the input: the sum of over all test cases does not exceed .
Output
OutputFor each test case, output one integer — the maximum number of cards you can arrange. If it is impossible to choose three or more cards and arrange them in a circle so that the condition holds, output .
Samples
3
4
1 1 1 3
3
2 3 4
3
1 1 2
4
9
3
Note
NoteIn the first example, you can choose and arrange the cards as follows: . You cannot arrange more than cards. For example, the arrangement does not work, because the cards must be arranged in a circle, and the condition also applies to the triple consisting of the second-to-last, last, and first cards.
In the second example, you can arrange all the cards: .
In the third example, you can choose and arrange the cards as follows: .