#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
set<int> st;
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int x;
    vector<int> vt;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      vt.push_back(x);
    }
    int res = -1;
    for (int i = 1; i <= 26; i++) {
      for (int j = 1; j <= 26; j++) {
        int a = i, b = j;
        int idx1 = 0, idx2 = n - 1, idx = 0;
        int cont = 0, flag1 = 0, flag2 = 0, t = 1;
        for (int k = 0; k < n; k++) {
          if (vt[k] == b) cont++;
        }
        if (a == b) {
          res = max(res, cont);
          continue;
        }
        while (true) {
          for (int k = 0; k < n; k++) {
            if (vt[idx1] == a && flag1 == 0) {
              flag1 = 1;
            } else if (vt[idx1] == b && flag1 == 0) {
              cont--;
              idx1++;
            } else if (flag1 == 0)
              idx1++;
            if (vt[idx2] == a && flag2 == 0) {
              flag2 = 1;
            } else if (vt[idx2] == b && flag2 == 0) {
              cont--;
              idx2--;
            } else if (flag2 == 0)
              idx2--;
            if (flag1 == 1 && flag2 == 1 && idx1 < idx2) {
              res = max(res, t + t + cont);
              break;
            }
          }
          if (flag1 == 0 || flag2 == 0 || idx1 >= idx2) break;
          flag1 = 0;
          flag2 = 0;
          t++;
          idx1++;
          idx2--;
        }
      }
    }
    cout << res << endl;
  }
}
