#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    bool flag = 0;
    for (int 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\n";
    else {
      for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
          if (j < n - 2 && a[j] == a[j + 1] && a[j + 2] == a[i]) {
            flag = 1;
            break;
          }
        }
      }
      if (flag == 1)
        cout << "YES\n";
      else
        cout << "NO\n";
    }
  }
  return 0;
}
