#include <bits/stdc++.h>
using namespace std;
const int MAX_INT = (1ll << 31) - 1;
const int INF = 2e9 + 10;
const long long inf = 9e18 + 10;
const int MO = 1e9 + 7;
const double eps = 1e-8;
void err() { cout << endl; }
template <typename T, typename... Args>
void err(T a, Args... args) {
  cout << a << " ";
  err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &...args) {
  for (auto &it : arg) cout << it << " ";
  err(args...);
}
template <typename T>
void err(T a[], int l, int r) {
  for (int i = (l); i <= (r); ++i) cout << a[i] << " ";
  cout << endl;
}
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  x *= f;
  return;
}
const int N = 2e5 + 3;
int pre[203][N], z[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int tot = 200;
    int n;
    scanf("%d", &n);
    for (int i = (1); i <= (n); ++i) scanf("%d", z + i);
    for (int x = (1); x <= (tot); ++x) pre[x][0] = pre[x][n + 1] = 0;
    for (int i = (n); i >= (0); --i) {
      for (int x = (1); x <= (tot); ++x) pre[x][i] = pre[x][i + 1];
      pre[z[i]][i] += 1;
    }
    vector<int> r[203];
    for (int a = (1); a <= (tot); ++a) {
      for (int len = (0); len <= (pre[a][1]); ++len) {
        int rr =
            upper_bound(pre[a], pre[a] + n + 1, len, greater<int>()) - pre[a];
        if (pre[a][rr] != len) rr -= 1;
        r[a].push_back(rr);
      }
    }
    for (int x = (1); x <= (tot); ++x) pre[x][0] = 0;
    for (int i = (1); i <= (n); ++i) {
      for (int x = (1); x <= (tot); ++x) pre[x][i] = pre[x][i - 1];
      pre[z[i]][i] += 1;
    }
    int ans = 0;
    for (int a = (1); a <= (tot); ++a) {
      for (int len = (0); len <= (pre[a][n]); ++len) {
        int l = lower_bound(pre[a], pre[a] + n + 1, len) - pre[a];
        int R = r[a][len];
        if (l >= R) break;
        for (int b = (1); b <= (tot); ++b) {
          ans = max(ans, pre[b][R - 1] - pre[b][l] + 2 * len);
        }
      }
    }
    printf("%d\n", ans);
    puts("");
  }
  return 0;
}
