#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e19;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, a, b, c, r, d, k, x, y, i, j;
    vector<long long> v[201];
    int arr[201] = {0};
    cin >> n;
    int dp[n + 1][201];
    memset(dp, 0, sizeof(dp));
    for (i = 1; i <= n; i++) {
      cin >> m;
      v[m].push_back(i);
      for (j = 1; j <= 200; j++) dp[i][j] = dp[i - 1][j];
      dp[i][m]++;
    }
    x = 0;
    for (i = 1; i <= 200; i++) {
      if (v[i].size()) {
        a = 0, b = v[i].size() - 1;
        x = max(x, (long long)v[i].size());
        c = 0;
        while (a < b) {
          c = c + 2;
          for (j = 1; j <= 200; j++) {
            if (j == i) continue;
            d = c + dp[v[i][b]][j] - dp[v[i][a]][j];
            x = max(x, d);
          }
          a++, b--;
        }
      }
    }
    cout << x << '\n';
  }
}
