#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      v.push_back(a);
    }
    bool ans = false;
    for (int i = 0; i < n - 2; i++) {
      for (int j = i + 2; j < n; j++) {
        if (v[i] == v[j]) {
          ans = true;
          break;
        }
      }
      if (ans == true) {
        printf("YES\n");
        break;
      }
    }
    if (ans == false) printf("NO\n");
    v.clear();
  }
  return 0;
}
