#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {
  cout << '\n';
  ;
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
template <typename T>
inline void Int(T &n) {
  n = 0;
  int f = 1;
  register int ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
template <typename T, typename TT>
inline void Int(T &n, TT &m) {
  Int(n);
  Int(m);
}
template <typename T, typename TT, typename TTT>
inline void Int(T &n, TT &m, TTT &l) {
  Int(n, m);
  Int(l);
}
double ind() {
  double x;
  scanf("%lf", &x);
  return x;
}
int set_1(int n, int pos) { return n = (n | (1 << pos)); }
int reset_0(int n, int pos) { return n = n & ~(1 << pos); }
bool check_bit(int n, int pos) { return n = n & (1 << pos); }
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int N = (int)2e5 + 5;
const int M = (int)1e9 + 7;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
int a[N], ps[N][201];
int main() {
  int t = 1, te = 0;
  Int(t);
  while (t--) {
    int n;
    Int(n);
    int res = 0;
    for (int i = 1; i <= n; ++i) {
      Int(a[i]);
      for (int j = 1; j <= 200; ++j) {
        ps[i][j] = ps[i - 1][j];
        if (j == a[i]) ps[i][j] += 1;
        res = max(res, ps[i][j]);
      }
    }
    for (int i = n; i > 1; --i) {
      int j = a[i];
      int have = ps[n][j] - ps[i - 1][j];
      if (have == 0) continue;
      int l = 1, r = i - 1, in = -1;
      while (l <= r) {
        int mid = (l + r) / 2;
        int ha = ps[mid][j];
        if (ha >= have) {
          in = mid;
          r = mid - 1;
        } else {
          l = mid + 1;
        }
      }
      if (in != -1) {
        int ma = 0;
        for (int k = 1; k <= 200; ++k) {
          if (k == j) continue;
          int h = ps[i - 1][k] - ps[in][k];
          ma = max(ma, h);
        }
        res = max(res, ps[in][j] + ps[in][j] + ma);
      }
    }
    printf("%d\n", res);
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= 200; ++j) {
        ps[i][j] = 0;
      }
    }
  }
  return 0;
}
