#include <bits/stdc++.h>
using namespace std;
void solve(string &s, int c, int &ans) {
  int i = 0, j = s.size() - 1;
  int c0 = 0, c1 = 0;
  while (i <= j) {
    if (c0 < c1) {
      if (s[i] == '1') {
        c0++;
      }
      if (s[i] == '0') {
        c--;
      }
      i++;
    } else if (c0 > c1) {
      if (s[j] == '1') {
        c1++;
      }
      if (s[j] == '0') {
        c--;
      }
      j--;
    } else {
      ans = max(ans, c0 * 2 + c);
      if (s[i] == '1') {
        c0++;
      }
      if (s[i] == '0') {
        c--;
      }
      i++;
    }
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[200 + 1] = {0};
    vector<int> vv[200 + 1];
    for (int i = 0; i < n; i++) {
      int aa;
      cin >> aa;
      vv[aa].push_back(i);
      a[aa]++;
    }
    int ans = 0;
    vector<int> v;
    for (int i = 1; i <= 200; i++) {
      ans = max(ans, a[i]);
      if (a[i]) {
        v.push_back(i);
      }
    }
    int m = v.size();
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j < m; j++) {
        string s, ss;
        int ii = 0, jj = 0;
        while (ii < vv[v[i]].size() && jj < vv[v[j]].size()) {
          if (vv[v[i]][ii] < vv[v[j]][jj]) {
            s.push_back('1');
            ss.push_back('0');
            ii++;
          } else {
            s.push_back('0');
            ss.push_back('1');
            jj++;
          }
        }
        while (ii < vv[v[i]].size()) {
          s.push_back('1');
          ss.push_back('0');
          ii++;
        }
        while (jj < vv[v[j]].size()) {
          s.push_back('0');
          ss.push_back('1');
          jj++;
        }
        solve(s, a[v[j]], ans);
        solve(ss, a[v[i]], ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
