#include <bits/stdc++.h>
using namespace std;
int z[5005];
int pos[5005];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      cin >> z[i];
      pos[z[i]] = i;
    }
    int fl = 0;
    for (int i = 1; i <= n; ++i) {
      if (pos[z[i]] > i + 1) {
        fl = 1;
        break;
      }
    }
    if (fl)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
