#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<vector<long long int>> loca(201);
    vector<vector<long long int>> preffix(n, vector<long long int>(201, 0));
    vector<long long int> pos(201, 0);
    vector<long long int> arr(n);
    for (long long int i = 0; i < n; i++) {
      cin >> arr[i];
      loca[arr[i]].push_back(i);
      if (i == 0) {
        preffix[i][arr[i]]++;
      } else {
        for (int j = 1; j <= 200; j++) {
          preffix[i][j] = preffix[i - 1][j];
        }
        preffix[i][arr[i]]++;
      }
    }
    long long int ans = 1;
    for (long long int i = 0; i < n; i++) {
      long long int strt = i;
      long long int end = loca[arr[i]][loca[arr[i]].size() - 1 - pos[arr[i]]];
      if (strt >= end)
        continue;
      else {
        strt++;
        end--;
        long long int ma = 0;
        if (strt <= end) {
          for (long long int j = 1; j <= 200; j++) {
            long long int cnt = 0;
            if (strt == 0) {
              cnt = cnt + preffix[end][j];
            } else {
              cnt = cnt + (preffix[end][j] - preffix[strt - 1][j]);
            }
            ma = ma > cnt ? ma : cnt;
          }
        }
        ans =
            ans > 2 * (pos[arr[i]] + 1) + ma ? ans : 2 * (pos[arr[i]] + 1) + ma;
      }
      pos[arr[i]]++;
    }
    cout << ans << '\n';
  }
  return 0;
}
