#include <bits/stdc++.h>
using namespace std;
template <class L, class R>
ostream& operator<<(ostream& cout, pair<L, R> P) {
  return cout << '(' << P.first << ',' << P.second << ')';
}
template <class T>
ostream& operator<<(ostream& cout, vector<T> V) {
  cout << "[ ";
  for (auto v : V) cout << v << ' ';
  return cout << ']';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    std::vector<int> inp(n);
    for (int i = 0; i < n; ++i) {
      cin >> inp[i];
    }
    vector<int> next(n), tot(n);
    for (int num = 1; num <= 200; ++num) {
      int pres = 0;
      vector<int> revsuffix(n + 1);
      for (int i = n - 1; i >= 0; --i) {
        if (inp[i] == num) {
          ++pres;
          revsuffix[pres] = i;
        } else {
        }
      }
      pres = 0;
      for (int i = 0; i < n; ++i) {
        if (inp[i] == num) {
          ++pres;
          tot[i] = pres;
          int lft = i;
          int rgt = revsuffix[pres];
          next[lft] = rgt;
        }
      }
    }
    int ans = 0;
    for (int centre = 1; centre < 201; ++centre) {
      int pres = 0;
      std::vector<int> psum(n);
      for (int i = 0; i < n; ++i) {
        pres += inp[i] == centre;
        psum[i] = pres;
      }
      ans = max(ans, pres);
      for (int lft = 0; lft < n; ++lft) {
        int rgt = next[lft];
        if (rgt <= lft) {
          continue;
        }
        ans = max(2 * tot[lft] + (psum[rgt - 1] - psum[lft]), ans);
      }
    }
    cout << ans << "\n";
  }
}
