#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, a[2000], p[2001][26];
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < 26; ++i) p[0][i] = 0;
    for (int i = 0; i < n; ++i) {
      for (int k = 0; k < 26; ++k) p[i + 1][k] = p[i][k];
      cin >> a[i];
      ++p[i + 1][a[i] - 1];
    }
    int ans = 0;
    for (int k = 1; k <= 26; ++k) {
      int low = 0, high = n - 1, m = 0;
      while (low < high) {
        while (low < n && a[low] != k) ++low;
        while (high >= low && a[high] != k) --high;
        if (low < high) {
          m += 2;
          ++low;
          --high;
          for (int i = 0; i < 26; ++i)
            ans = max(ans, m + p[high + 1][i] - p[low][i]);
        }
      }
    }
    cout << max(ans, 1) << '\n';
  }
  return 0;
}
