#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#pragma GCC optimize("03")
const int nax = 2e5 + 5;
vector<int> a(nax), b[205];
int cnt[nax][205];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    for (int i = 1; i <= 200; i++) {
      b[i].clear();
    }
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      for (int j = 1; j <= 200; j++) {
        cnt[i][j] = cnt[i - 1][j] + (a[i] == j);
        ans = max(ans, cnt[i][j]);
      }
      b[a[i]].emplace_back(i);
    }
    for (int i = 1; i <= 200; i++) {
      for (int len = 1; len <= n; len++) {
        if ((int)b[i].size() >= 2 * len) {
          int x = b[i][len - 1];
          int y = b[i][(int)b[i].size() - len];
          for (int j = 1; j <= 200; j++) {
            int m = cnt[y - 1][j] - cnt[x][j];
            ans = max(ans, 2 * len + m);
          }
        } else
          break;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
