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