#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int n, x, ans = 1, freq[27][2001] = {};
    vector<vector<int>> pos(27);
    scanf("%d", &n);
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
      scanf("%d", &v[i]);
      freq[v[i]][i] = true;
      pos[v[i]].push_back(i);
    }
    for (int i = 1; i < 27; ++i) {
      for (int j = 1; j < n; ++j) freq[i][j] += freq[i][j - 1];
      ans = max(ans, freq[i][n - 1]);
    }
    int l, r, diff;
    for (int nm = 1; nm < 27; ++nm) {
      if (pos[nm].size() < 2) continue;
      l = pos[nm][0], r = pos[nm][pos[nm].size() - 1];
      while (l < r) {
        diff = freq[nm][l] - (freq[nm][n - 1] - freq[nm][r - 1]);
        if (diff > 0)
          --r;
        else if (diff < 0)
          ++l;
        else {
          for (int i = 1; i < 27; ++i)
            ans = max(ans, freq[nm][l] * 2 + freq[i][r - 1] - freq[i][l]);
          ++l;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
