#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int inf = 4e18;
const int N = 5e5 + 5;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tt = 1;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; ++i) cin >> arr[i];
    vector<int> idx[205];
    for (int i = 0; i < n; ++i) {
      idx[arr[i]].push_back(i);
    }
    int maxx = 0;
    for (int i = 1; i <= 200; ++i) {
      if (!idx[i].size()) continue;
      for (int j = 1; j <= 200; ++j) {
        if (!idx[j].size()) continue;
        int nya = idx[i].size();
        if (i == j) {
          maxx = max(maxx, nya);
        } else {
          int xxx = 0, yyy = nya - 1;
          while (xxx < yyy) {
            int first = upper_bound(begin(idx[j]), end(idx[j]), idx[i][xxx]) -
                        begin(idx[j]);
            int last = upper_bound(begin(idx[j]), end(idx[j]), idx[i][yyy]) -
                       begin(idx[j]);
            maxx = max(maxx, 2 * xxx + 2 + last - first);
            ++xxx;
            --yyy;
          }
        }
      }
    }
    cout << maxx << "\n";
  }
  return 0;
}
