#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<int> v;
int a;
bool pln() {
  for (int i = 0; i < n - 1; ++i) {
    for (int j = n - 1; j > i; --j) {
      if (v[i] == v[j] && j - i > 1) return 1;
    }
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; ++i) {
      cin >> a;
      v.push_back(a);
    }
    if (pln())
      cout << "YES\n";
    else
      cout << "NO\n";
    v.clear();
  }
  return 0;
}
