#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 9;
const long long inf = 1e18 + 18;
const int max6 = 1e6 + 6;
const int modx = 1e9 + 7;
const int mody = 997;
const int base = 137;
vector<int> pos[1000];
int a[max6];
int s[200001][201];
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= 200; ++i) pos[i].clear();
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      for (int j = 1; j <= 200; ++j) s[i][j] = s[i - 1][j];
      s[i][a[i]]++;
      pos[a[i]].push_back(i);
    }
    int res = 0;
    for (int i = 1; i <= 200; ++i) {
      int len = pos[i].size();
      res = max(res, len);
      for (int j = 1; 2 * j <= len; ++j) {
        int be = pos[i][j - 1] + 1;
        int en = pos[i][len - j] - 1;
        for (int k = 1; k <= 200; ++k)
          res = max(res, 2 * j + s[en][k] - s[be - 1][k]);
      }
    }
    cout << res << "\n";
  }
}
