#include <bits/stdc++.h>
using namespace std;
int getLower(vector<int>& inp, int st, int ed, int val) {
  if (st > ed) return -1;
  int mid = (st + ed) / 2;
  if (inp[mid] <= val) {
    int k = getLower(inp, mid + 1, ed, val);
    if (k != -1) return k;
    return mid;
  }
  return getLower(inp, st, mid - 1, val);
}
int getUpper(vector<int>& inp, int st, int ed, int val) {
  if (st > ed) return -1;
  int mid = (st + ed) / 2;
  if (inp[mid] >= val) {
    int k = getUpper(inp, st, mid - 1, val);
    if (k != -1) return k;
    return mid;
  }
  return getUpper(inp, mid + 1, ed, val);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<vector<int> > allvals(27, vector<int>());
    for (int i = 0; i < n; i++) {
      int k;
      cin >> k;
      allvals[k].push_back(i);
    }
    int gmax = -1;
    for (int i = 1; i < 27; i++) {
      int vmax = allvals[i].size();
      if (vmax >= 2) {
        int start = 0, end = allvals[i].size() - 1;
        int len = 2;
        while (start < end) {
          for (int k = 1; k < 27; k++) {
            if (k == i) continue;
            int vsize = allvals[k].size();
            int st = getUpper(allvals[k], 0, allvals[k].size() - 1,
                              allvals[i][start]);
            int ed =
                getLower(allvals[k], 0, allvals[k].size() - 1, allvals[i][end]);
            if (st != -1 && ed != -1 && st <= ed) {
              int m = len + (ed - st + 1);
              vmax = max(vmax, m);
            }
          }
          start++;
          end--;
          len += 2;
        }
      }
      gmax = max(gmax, vmax);
    }
    cout << gmax << endl;
  }
  return 0;
}
