#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
int a[N];
int dp[N][205];
int find_mid(int k, int l, int r) { return dp[r + 1][k] - dp[l][k]; }
int find_side(int k, int l, int r) {
  return 2 * min(dp[l][k] - dp[0][k], dp[n + 1][k] - dp[r + 1][k]);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int T;
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    memset(dp, 0, sizeof(n));
    for (int i = 1; i <= 200; i++) {
      dp[0][i] = 0;
    }
    for (int i = 1; i <= 200; i++) {
      int cur = 0;
      for (int j = 1; j <= n; j++) {
        dp[j][i] = cur;
        if (a[j] == i) cur++;
      }
      dp[n + 1][i] = cur;
    }
    int ans = INT_MIN;
    map<int, vector<int>> mp;
    for (int i = 1; i <= n; i++) {
      mp[a[i]].push_back(i);
      int xx = mp[a[i]].size();
      ans = max(ans, xx);
    }
    for (int i = 1; i <= 200; i++) {
      if (mp[i].size() < 2) continue;
      int k = mp[i].size();
      int l = 0;
      int r = k - 1;
      int cur;
      while (l < r) {
        cur = 2 * (l + 1);
        int temp = INT_MIN;
        for (int j = 1; j <= 200; j++) {
          temp = max(temp, find_mid(j, mp[i][l] + 1, mp[i][r] - 1));
        }
        ans = max(ans, cur + temp);
        l++;
        r--;
      }
    }
    cout << ans << "\n";
  }
}
