#include <bits/stdc++.h>
using namespace std;
const long long N = 501;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n + 1);
    vector<long long> a[201];
    for (long long i = 1; i <= n; i++) {
      cin >> v[i];
      a[v[i]].push_back(i);
    }
    long long p[n + 1][201];
    for (long long i = 0; i <= n; i++) {
      for (long long j = 0; j < 201; j++) p[i][j] = 0;
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 0; j < 201; j++) {
        p[i][j] = p[i - 1][j];
      }
      p[i][v[i]]++;
    }
    long long ans = 0;
    for (long long i = 1; i <= n; i++) {
      long long x = p[i][v[i]];
      long long nxt = a[v[i]][a[v[i]].size() - x];
      nxt--;
      long long cur = 0;
      if (i + 1 <= nxt) {
        for (long long j = 0; j < 201; j++) {
          cur = max(cur, p[nxt][j] - p[i][j]);
        }
        ans = max(ans, cur + 2 * x);
      }
    }
    for (long long j = 0; j < 201; j++) {
      ans = max(ans, p[n][j]);
    }
    cout << ans << endl;
  }
}
