#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    long long a[n];
    for (int j = 0; j < n; j++) {
      cin >> a[j];
    }
    int flag = 0;
    for (int j = 0; j < n; j++) {
      for (int u = n - 1; u > j; u--) {
        if (a[j] == a[u] && j + 1 < u) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 1)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
