#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int ins[n];
  for (int i = 0; i < n; i++) {
    cin >> ins[i];
  }
  for (int i = 0; i < n; i++) {
    if ((i + 2) < n) {
      for (int j = i + 2; j < n; j++) {
        if (ins[i] == ins[j]) {
          cout << "YES" << endl;
          return;
        }
      }
    }
  }
  cout << "NO" << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    solve();
  }
}
