#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& el : a) {
      cin >> el;
    }
    int res = 0;
    for (int i = 0; i <= 26; ++i) {
      for (int j = 0; j <= 26; ++j) {
        if (i == 0) {
          int r = count(begin(a), end(a), j);
          res = max(res, r);
        } else if (j == 0) {
          int r = count(begin(a), end(a), i);
          if (r % 2 == 0) {
            --r;
          }
          res = max(res, r);
        } else {
          int ca1 = 0, ca2 = 0, cb = count(begin(a), end(a), j);
          int l = -1, r = n;
          while (l < r) {
            while (ca1 != ca2 and l < r) {
              if (ca1 < ca2) {
                ++l;
                if (l < r) {
                  if (a[l] == i) ++ca1;
                  if (a[l] == j) --cb;
                }
              } else {
                --r;
                if (l < r) {
                  if (a[r] == i) ++ca2;
                  if (a[r] == j) --cb;
                }
              }
            }
            if (ca1 == ca2) res = max(res, ca1 * 2 + cb);
            ++l;
            if (l < r) {
              if (a[l] == i) ++ca1;
              if (a[l] == j) --cb;
            }
            --r;
            if (l < r) {
              if (a[r] == i) ++ca2;
              if (a[r] == j) --cb;
            }
          }
        }
      }
    }
    cout << res << endl;
  }
}
