#include <bits/stdc++.h>
const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
using namespace std;
int a[5005];
void run() {
  int n;
  cin >> n;
  map<int, vector<int>> re;
  for (int i = 0; i < n; ++i) cin >> a[i], re[a[i]].push_back(i);
  for (auto each : re) {
    if (each.second.size() >= 2) {
      auto f = each.second.begin(), s = each.second.begin() + 1;
      for (; s != each.second.end(); ++s) {
        if ((*s) - (*f) >= 2) {
          cout << "YES"
               << "\n";
          return;
        }
      }
    }
  }
  cout << "NO"
       << "\n";
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int _ = 1;
  cin >> _;
  for (int i = 0; i < _; ++i) run();
  return 0;
}
