#include <bits/stdc++.h>
using namespace std;
int t;
int n;
int ai;
int main() {
  cin >> t;
  for (int i = 0; i < t; ++i) {
    cin >> n;
    vector<int> a(n + 1, 0);
    int ans = 0;
    for (int j = 1; j <= n; ++j) {
      cin >> ai;
      if (a[ai] == 0)
        a[ai] = j;
      else if (a[ai] + 1 < j)
        ans = 1;
    }
    if (ans == 0)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
