#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, i, j, x, t, a, b;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> v(n);
    long long res = 0;
    unordered_map<int, vector<int> > pos;
    unordered_map<int, vector<int> > occ;
    for (i = 1; i <= 200; i++) {
      vector<int> aux(n, 0);
      occ[i] = aux;
    }
    for (i = 0; i < n; i++) {
      cin >> v[i];
      pos[v[i]].push_back(i);
      for (j = 1; j <= 200; j++) {
        if (j == v[i]) {
          if (i == 0)
            occ[j][i] = 1;
          else
            occ[j][i] = occ[j][i - 1] + 1;
        } else if (i > 0) {
          occ[j][i] = occ[j][i - 1];
        }
      }
    }
    for (unordered_map<int, vector<int> >::iterator it = pos.begin();
         it != pos.end(); it++) {
      long long val = it->first;
      vector<int> v = it->second;
      res = max(res, (long long)v.size());
      if (v.size() >= 2) {
        for (j = 0; j < v.size(); j++) {
          long long start = pos[val][j];
          long long finish = pos[val][v.size() - j - 1];
          for (unordered_map<int, vector<int> >::iterator it2 = pos.begin();
               it2 != pos.end(); it2++) {
            i = it2->first;
            if (finish > start && i != val)
              res = max(res, 2 * (j + 1) + occ[i][finish] - occ[i][start]);
          }
        }
      }
    }
    cout << res;
    cout << endl;
  }
  return 0;
}
