#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int max3(long long int a, long long int b, long long int c) {
  return max(max(a, b), c);
}
long long int nCr(long long int n, long long int r) {
  long long int x = n - r, y = 0, z = 1;
  while (y < r) {
    z = (z * (x + 1)) / (y + 1);
    x++;
    y++;
  }
  return z;
}
long long int maxm = 1000000;
vector<long long int> v[201], v1;
long long int n, mx = -1;
void solve(long long int a, long long int b) {
  long long int i = 0, j = 0, sza = v[a].size(), szb = v[b].size();
  while (i < sza && j < szb) {
    if (v[a][i] < v[b][j]) {
      v1.push_back(a);
      i++;
    } else {
      v1.push_back(b);
      j++;
    }
  }
  while (i < sza) {
    v1.push_back(a);
    i++;
  }
  while (j < szb) {
    v1.push_back(b);
    j++;
  }
  i = 0, j = v1.size() - 1;
  long long int ca = 0, cb = szb;
  mx = max(mx, cb);
  while (i <= j) {
    if (v1[i] == b) {
      cb--;
      i++;
    } else if (v1[j] == b) {
      cb--;
      j--;
    } else {
      ca++;
      if (i == j) ca--;
      mx = max(mx, 2 * ca + cb);
      i++;
      j--;
    }
  }
  v1.clear();
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (long long int i = 0; i < n; i++) {
      long long int x;
      cin >> x;
      v[x].push_back(i);
    }
    for (long long int i = 1; i < 201; i++)
      for (long long int j = 1; j < 201; j++)
        if (v[i].size() != 0 && v[j].size() != 0) solve(i, j);
    cout << mx << endl;
    for (long long int i = 0; i < 201; i++) v[i].clear();
    mx = -1;
  }
}
