#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n;
  cin >> t;
  while (t > 0) {
    cin >> n;
    long long a[n];
    vector<long long> ind[26];
    long long freq[n][26];
    memset(freq, 0, n * 26 * sizeof(long long));
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      ind[a[i] - 1].push_back(i);
      for (long long j = 0; j < 26; j++) {
        if (i > 0) {
          freq[i][j] = freq[i - 1][j];
        }
      }
      freq[i][a[i] - 1]++;
    }
    long long ans = 0;
    for (long long i = 0; i < 26; i++) {
      ans = max(ans, (long long)ind[i].size());
      for (long long j = 0; j < ind[i].size() / 2; j++) {
        long long x = 2 * (j + 1);
        long long lb = ind[i][j] + 1;
        long long rb = ind[i][ind[i].size() - 1 - j] - 1;
        long long y = 0;
        for (long long k = 0; k < 26; k++) {
          y = max(y, freq[rb][k] - freq[lb - 1][k]);
        }
        ans = max(ans, x + y);
      }
    }
    cout << ans << endl;
    t--;
  }
}
