#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
  cin >> t;
  while (t--) {
    int n, ans = 0;
    cin >> n;
    vector<int> a[201];
    for (int i = 0, ai; i < n; i++) {
      cin >> ai;
      a[ai - 1].push_back(i);
    }
    for (int i = 0; i < 200; i++) {
      if (a[i].empty()) continue;
      int m = a[i].size();
      ans = max(ans, m);
      for (int j = 0; j < m / 2; j++) {
        int c = a[i][j], b = a[i][m - j - 1], l;
        for (int k = 0; k < 200; k++) {
          if (a[k].empty()) continue;
          int lo = 0, hi = a[k].size() - 1;
          while (lo < hi) {
            int mid = (lo + hi) / 2;
            if (a[k][mid] > c)
              hi = mid;
            else
              lo = mid + 1;
          }
          l = lo, lo = 0, hi = a[k].size() - 1;
          while (lo < hi) {
            int mid = (lo + hi + 1) / 2;
            if (a[k][mid] < b)
              lo = mid;
            else
              hi = mid - 1;
          }
          int dif = lo - l + 1;
          if (a[k][l] < c || a[k][lo] > b) dif = 0;
          ans = max(ans, (j + 1) * 2 + dif);
        }
      }
    }
    cout << ans << "\n";
  }
}
