#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int tc;
  cin >> tc;
  while (tc--) {
    long long int n;
    cin >> n;
    vector<long long int> a(n);
    for (int i = 0; i < (n); ++i) cin >> a[i];
    vector<long long int> c[n + 1];
    for (int i = 0; i < (n); ++i) {
      c[a[i]].push_back(i);
    }
    bool f = 0;
    for (int i = 0; i < (n + 1); ++i) {
      if (c[i].size() > 2) {
        f = 1;
        cout << "YES" << '\n';
        break;
      } else if (c[i].size() == 2 && abs(c[i][0] - c[i][1]) > 1) {
        f = 1;
        cout << "YES" << '\n';
        break;
      }
    }
    if (f == 0) {
      cout << "NO" << '\n';
    }
  }
  return 0;
}
