#include <bits/stdc++.h>
using namespace std;
int t, n, maks, dp[205][200005], a[200005], x, y, z;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    vector<int> v[205];
    maks = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      for (int j = 1; j <= 26; j++) {
        dp[j][i] = dp[j][i - 1];
      }
      dp[a[i]][i]++;
      v[a[i]].push_back(i);
    }
    for (int i = 1; i <= 26; i++) {
      maks = max(maks, dp[i][n]);
      z = v[i].size();
      for (int j = 1; j <= z / 2; j++) {
        x = v[i][j - 1];
        y = v[i][z - j];
        for (int k = 1; k <= 26; k++) {
          maks = max(maks, j + j + dp[k][y - 1] - dp[k][x]);
        }
      }
    }
    cout << maks << '\n';
  }
  return 0;
}
