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