#include <bits/stdc++.h>
using namespace std;
vector<int> v, v1, v2, v3, v4, v5, v6;
vector<pair<long long int, long long int> > vec, vec1, vec2, vec3;
vector<int> adj[205];
map<long long int, long long int> Mp, Mp1;
set<long long int> st, st1;
queue<long long int> Q;
stack<long long int> Stk;
multiset<pair<long long int, long long int> > S;
int n, m, k, T, t, cnt;
void Reset() {
  for (int i = 1; i <= 200; i++) {
    adj[i].clear();
  }
  v.clear();
}
void Input() {
  cin >> n;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    adj[a].push_back(i);
  }
}
void Calculation() {
  for (int i = 1; i <= 200; i++) {
    int siz = adj[i].size();
    v.push_back(siz);
    int left = 0, right = siz - 1;
    while (left < right) {
      int idx1 = adj[i][left++];
      int idx2 = adj[i][right--];
      for (int j = 1; j <= 200; j++) {
        if (i == j) continue;
        int a = (left - 1) + (siz - right);
        int b =
            (lower_bound(adj[j].begin(), adj[j].end(), idx2) - adj[j].begin()) -
            (upper_bound(adj[j].begin(), adj[j].end(), idx1) - adj[j].begin());
        v.push_back(a + b);
      }
    }
  }
  cout << *max_element(v.begin(), v.end()) << endl;
}
void solve() {
  Reset();
  Input();
  Calculation();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    T++;
    solve();
  }
  return 0;
}
