#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> sum(201);
    vector<vector<int>> c(201);
    vector<int> first(n, 0);
    for (int i = 1; i <= 200; i++) sum[i] = first;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum[a[i]][i] = 1;
      c[a[i]].push_back(i);
    }
    for (int i = 1; i <= 200; i++) {
      for (int j = 1; j < n; j++) sum[i][j] += sum[i][j - 1];
    }
    int ans = 1;
    for (int i = 1; i <= 200; i++) {
      int kol = c[i].size();
      int k = c[i].size() / 2;
      for (int j = 1; j <= k; j++) {
        int tek = 2 * j;
        int l = c[i][j - 1] + 1;
        int r = c[i][kol - j] - 1;
        int max1 = 0;
        for (int z = 1; z <= 200; z++)
          max1 = max(max1, sum[z][r] - sum[z][l - 1]);
        ans = max(ans, tek + max1);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
