#include <bits/stdc++.h>
using namespace std;
int q, n, x, s, maxx;
int v[6000], fr[6000];
int main() {
  cin >> q;
  for (; q--;) {
    cin >> n;
    int ok = 0;
    for (int i = 1; i <= n; i++) fr[i] = 0;
    for (int i = 1; i <= n; i++) cin >> v[i];
    for (int i = 1; i <= n; i++) {
      if (fr[v[i]] == 0) {
        fr[v[i]] = i;
      } else {
        if (i - fr[v[i]] > 1) {
          ok = 1;
          break;
        }
      }
    }
    if (ok == 0)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
}
