#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    vector<vector<int> > v(201);
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      v[x].push_back(i);
    }
    int answer = 0;
    for (int i = 0; i < 201; ++i) {
      answer = max(answer, (int)v[i].size());
    }
    for (int i = 1; i < 201; ++i) {
      for (int j = 1; j < 201; ++j) {
        if (!v[i].empty() && !v[j].empty() && i != j) {
          for (int prefix = 1; prefix <= (int)v[i].size() / 2; ++prefix) {
            int len =
                distance(v[j].begin(),
                         lower_bound(v[j].begin(), v[j].end(),
                                     v[i][(int)v[i].size() - prefix])) -
                distance(v[j].begin(), upper_bound(v[j].begin(), v[j].end(),
                                                   v[i][prefix - 1]));
            answer = max(answer, 2 * prefix + len);
          }
        }
      }
    }
    cout << answer << '\n';
  }
  return 0;
}
