#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
int T, n;
int a[N], l[N], r[N];
int num[205][N];
vector<int> vt[205], kk;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= 200; ++i) vt[i] = kk;
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i) {
      for (int t = 1; t <= 200; ++t) num[t][i] = num[t][i - 1];
      ++num[a[i]][i];
      vt[a[i]].emplace_back(i);
    }
    int ans = 1;
    for (int i = 1; i <= 200; ++i) {
      int cnt = vt[i].size();
      for (int j = 1; j <= cnt / 2; ++j) {
        int l = vt[i][j - 1] + 1, r = vt[i][cnt - j] - 1;
        if (l > r) {
          ans = max(ans, 2 * j);
          continue;
        }
        for (int t = 1; t <= 200; ++t) {
          ans = max(ans, num[t][r] - num[t][l - 1] + 2 * j);
        }
      }
    }
    printf("%d\n", ans);
  }
}
