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