#include <bits/stdc++.h>
using namespace std;
const int N = 1e9 + 7;
long long power(long long x, long long y) {
  long long res = 1;
  x = x % N;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % N;
    y = y >> 1;
    x = (x * x) % N;
  }
  return res;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long &x : a) cin >> x;
  for (long long i = 0; i < n - 2; i++) {
    for (long long j = i + 2; j < n; j++) {
      if (a[i] == a[j]) {
        cout << "YES\n";
        return;
      }
    }
  }
  cout << "NO\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
