#include <bits/stdc++.h>
using namespace std;
int t, n, freq[201][212345];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    vector<int> pos[201];
    for (int i = 0; i < 201; ++i)
      for (int j = 0; j <= n; ++j) freq[i][j] = 0;
    for (int x, i = 1; i <= n; ++i)
      scanf("%d", &x), freq[x][i] = 1, pos[x].push_back(i);
    map<pair<int, int>, int> mp;
    for (int i = 1; i < 201; ++i) {
      int ctr = 0;
      for (int j = n; j > 0; --j)
        if (freq[i][j]) mp[{i, ++ctr}] = j;
      for (int j = 1; j <= n; ++j) freq[i][j] += freq[i][j - 1];
    }
    int ans = 1;
    for (int i = 1; i < 201; ++i)
      for (int j = 1; j < 201; ++j)
        if (i == j)
          ans = max(ans, freq[i][n]);
        else if (freq[i][n] > 1) {
          for (int idx1, idx2, p = 0; p < pos[i].size(); ++p) {
            idx1 = pos[i][p];
            idx2 = mp[{i, freq[i][idx1]}];
            if (idx1 >= idx2) break;
            ans =
                max(ans, 2 * freq[i][idx1] + freq[j][idx2 - 1] - freq[j][idx1]);
          }
        }
    printf("%d\n", ans);
  }
  return 0;
}
