#include <bits/stdc++.h>
#pragma gcc optimize(2)
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    f = ch == '-' ? -1 : 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
const int N = 2e5 + 5;
int tree[205][N];
int n, a[N], ans;
int ma[205];
inline int lowbit(int x) { return x & -x; }
inline void add(int x, int i, int num) {
  while (i <= n) {
    tree[num][i] += x;
    i += lowbit(i);
  }
}
inline int ask(int i, int num) {
  int ans = 0;
  while (i) {
    ans += tree[num][i];
    i -= lowbit(i);
  }
  return ans;
}
int main() {
  int T = read();
  while (T--) {
    n = read();
    for (int i = 1; i <= 200; i++) ma[i] = 0;
    for (int i = 1; i <= n; i++) a[i] = read(), ma[a[i]] = 1;
    for (int i = 1; i <= 200; i++) {
      if (ma[i]) {
        for (int j = 1; j <= n; j++) tree[i][j] = 0;
      }
    }
    for (int i = 1; i <= n; i++) {
      add(1, i, a[i]);
    }
    ans = 1;
    for (int n1 = 1; n1 <= 200; n1++) {
      if (!ma[n1]) continue;
      int l = 1, r = n;
      int temp = 0;
      for (int i = 1; i <= n; i++) {
        while (a[l] != n1 && l < r) l++;
        if (l >= r) {
          break;
        }
        while (a[r] != n1 && r > l) r--;
        if (l == r) {
          break;
        }
        int tnum = 0;
        for (int n2 = 1; n2 <= 200; n2++) {
          if (!ma[n2]) continue;
          tnum = max(ask(r - 1, n2) - ask(l, n2), tnum);
        }
        temp = max(temp, 2 * i + tnum);
        l++;
        r--;
      }
      ans = max(ans, temp);
    }
    printf("%d\n", ans);
  }
}
