#d2711. 三回文序列
三回文序列
Triple Palindrome Sequence
Problem Description
You are given a sequence of length .
We define a triple palindrome sequence as a sequence of the form $\underbrace{a\dots a}_{k_1}\ \underbrace{b\dots b}_{k_2}\ \underbrace{a\dots a}_{k_1}$. For example: is a triple palindrome sequence, while and are not.
Now, find the length of the longest triple palindrome subsequence in the sequence .
Note that may be .
Input Format
The first line gives an integer , the number of test cases.
For each test case:
The first line gives the length of the sequence.
The second line gives .
Output Format
For each test case, output the length of the longest triple palindrome subsequence.
Sample Input
6
8
1 1 2 2 3 2 1 1
3
1 3 3
4
1 10 10 1
1
26
2
2 1
3
1 1 1
Sample Output
7
2
4
1
1
3
Constraints