#include <bits/stdc++.h>
using namespace std;
int t, a[30], n, b[2010], r;
vector<int> aux[30];
int val(int x, int y) {
  int hr = 0, hxt = 0;
  for (int i = 1; i <= aux[x].size() / 2; i++) {
    hxt = lower_bound(aux[y].begin(), aux[y].end(), aux[x][aux[x].size() - i]) -
          upper_bound(aux[y].begin(), aux[y].end(), aux[x][i - 1]);
    if (hxt > 0) hr = max(hr, 2 * i + hxt);
  }
  return hr;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= 26; i++) aux[i].clear();
    r = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &b[i]);
      aux[b[i]].push_back(i);
      int h = aux[b[i]].size();
      r = max(r, h);
    }
    for (int i = 1; i < 26; i++)
      for (int j = i + 1; j <= 26; j++) r = max(r, max(val(i, j), val(j, i)));
    printf("%d\n", r);
  }
  return 0;
}
