The only difference between easy and hard versions is constraints.

You are given a sequence a consisting of n positive integers.

Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements are a and b, a can be equal b) and is as follows: [\underbrace{a, a, ..., a}_{x}, \underbrace{b, b, ..., b}_{y}, \underbrace{a, a, ..., a}_{x}]. There x, y are integers greater than or equal to 0. For example, sequences [], [2], [1, 1], [1, 2, 1], [1, 2, 2, 1] and [1, 1, 2, 1, 1] are three block palindromes but [1, 2, 3, 2, 1], [1, 2, 1, 2, 1] and [1, 2] are not.

Your task is to choose the maximum by length subsequence of a that is a three blocks palindrome.

You have to answer t independent test cases.

Recall that the sequence t is a a subsequence of the sequence s if t can be derived from s by removing zero or more elements without changing the order of the remaining elements. For example, if s=[1, 2, 1, 3, 1, 2, 1], then possible subsequences are: [1, 1, 1, 1], [3] and [1, 2, 1, 3, 1, 2, 1], but not [3, 2, 3] and [1, 1, 1, 1, 2].

Input

The first line of the input contains one integer t (1 ≤ t ≤ 2000) — the number of test cases. Then t test cases follow.

The first line of the test case contains one integer n (1 ≤ n ≤ 2000) — the length of a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 26), where a_i is the i-th element of a. Note that the maximum value of a_i can be up to 26.

It is guaranteed that the sum of n over all test cases does not exceed 2000 (∑ n ≤ 2000).

Output

For each test case, print the answer — the maximum possible length of some subsequence of a that is a three blocks palindrome.

Example

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


Output


7
2
4
1
1
3
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1335E
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int T = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         while(T-->0)
         {
            int N = Integer.parseInt(infile.readLine());
            int[] arr = new int[N];
            st = new StringTokenizer(infile.readLine());
            for(int i=0; i < N; i++)
               arr[i] = Integer.parseInt(st.nextToken());
            int res = 0;
            for(int v=1; v <= 200; v++)
            {
               int left = 0;
               int right = N-1;
               int lc = 0;   int rc = 0;
               //lmao
               SegmentTree rmq = new SegmentTree(0, 201);
               for(int x: arr)
                  rmq.update(x, rmq.query(x,x)+1);
               res = Math.max(res, rmq.query(1, 200));
               for(int x=1; x <= N; x++)
               {
                  while(left < N && lc < x)
                  {
                     if(arr[left] == v)
                        lc++;
                     rmq.update(arr[left], rmq.query(arr[left],arr[left])-1);
                     left++;
                  }
                  while(right >= 0 && rc < x)
                  {
                     if(arr[right] == v)
                        rc++;
                     rmq.update(arr[right], rmq.query(arr[right],arr[right])-1);
                     right--;
                  }
                  if(left > right || left == N || right == -1)
                     break;
                  res = Math.max(res, (x<<1)+rmq.query(1, 200));
               }  
            }
            sb.append(res+"\n");
         }
         System.out.print(sb);
      }
   }
   class SegmentTree 
   {
        //range max query, non lazy
        final int[] val;
        final int treeFrom;
        final int length;
    
        public SegmentTree(int treeFrom, int treeTo) 
        {
            this.treeFrom = treeFrom;
            int length = treeTo - treeFrom + 1;
            int l;
            for (l = 0; (1 << l) < length; l++);
            val = new int[1 << (l + 1)];
            this.length = 1 << l;
        }
        public void update(int index, int delta) 
        {
            //replaces value
            int node = index - treeFrom + length;
            val[node] = delta;
            for (node >>= 1; node > 0; node >>= 1) 
                val[node] = Math.max(val[node << 1], val[(node << 1) + 1]);
        }
        public int query(int from, int to) 
        {
            //inclusive bounds
            if (to < from)
                return 0;
            from += length - treeFrom;
            to += length - treeFrom + 1;
            int res = 0;
            for (; from + (from & -from) <= to; from += from & -from) 
                res = Math.max(res, val[from / (from & -from)]);
            for (; to - (to & -to) >= from; to -= to & -to)
                res = Math.max(res, val[(to - (to & -to)) / (to & -to)]);
            return res;
        }
   }