#include <bits/stdc++.h>
using namespace std;
const long double PI = atan(1.0) * 4;
const int64_t INF = INT64_MAX;
const int32_t LOG = 21;
const int MOD = 1e9 + 7;
vector<int> v[205];
int find1(int ind, int x) {
  int siz = v[ind].size();
  if (siz == 0) return -1;
  int l = 0, r = siz - 1;
  int ans = siz;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (v[ind][mid] >= x) {
      ans = min(ans, mid);
      r = mid - 1;
    } else
      l = mid + 1;
  }
  if (ans == siz) ans = -1;
  return ans;
}
int find2(int ind, int x) {
  int siz = v[ind].size();
  if (siz == 0) return -1;
  int l = 0, r = siz - 1;
  int ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (v[ind][mid] <= x) {
      ans = max(ans, mid);
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int tests = 1;
  cin >> tests;
  for (int ii = 0; ii < tests; ii++) {
    for (int i = 0; i < 201; i++) v[i].clear();
    int n;
    cin >> n;
    int a[n];
    set<int> second;
    vector<int> v1;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      v[a[i]].push_back(i);
      second.insert(a[i]);
    }
    for (auto it : second) v1.push_back(it);
    int ans = 0;
    for (auto it : v1) {
      int cur = it;
      int siz = v[it].size();
      ans = max(ans, siz);
      for (int j = 0; j < siz; j++) {
        int l = v[cur][j];
        int r = v[cur][siz - 1 - j];
        if (l >= r) break;
        for (auto it1 : v1) {
          if (it1 == cur) continue;
          int l1 = find1(it1, l);
          int l2 = find2(it1, r);
          if (l1 != -1 && l2 != -1) ans = max(ans, 2 * (j + 1) + l2 - l1 + 1);
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
