#include <bits/stdc++.h>
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return (y > x) ? x = y, 1 : 0; }
using namespace std;
int n;
int a[200000];
int cnt[200000][201];
int f(int x) {
  int mx = -1;
  int len = 0;
  int i = 0;
  int j = n - 1;
  while (i < j) {
    while (i < j - 1 && a[i] != x) i++;
    if (i >= j) break;
    while (i < j - 1 && a[j] != x) j--;
    if (a[i] == x && a[j] == x) {
      len += 2;
      int extra = 0;
      for (int k = (1); k < (201); ++k) {
        extra = max(extra, cnt[j - 1][k] - cnt[i][k]);
      }
      mx = max(mx, len + extra);
    }
    if (i >= j) break;
    i++;
    j--;
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  int T;
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = (0); i < (n); ++i) cin >> a[i];
    for (int i = (0); i < (n); ++i)
      for (int j = (0); j < (201); ++j) cnt[i][j] = 0;
    cnt[0][a[0]] = 1;
    for (int i = (1); i < (n); ++i) {
      for (int j = (1); j < (201); ++j) cnt[i][j] = cnt[i - 1][j];
      cnt[i][a[i]]++;
    }
    int ans = 1;
    for (int i = (1); i < (201); ++i) ans = max(ans, f(i));
    cout << ans << '\n';
  }
  return 0;
}
