#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    int f = 0;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < n - 1; i++) {
      for (int j = n - 1; j > i + 1; j--) {
        if (v[i] == v[j]) {
          cout << "YES" << endl;
          f = 1;
          break;
        }
      }
      if (f == 1) break;
    }
    if (f == 0) cout << "NO" << endl;
  }
}
