#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    int n, i, flag = 0, k;
    cin >> n;
    vector<int> v, b[5001];
    vector<int>::iterator j;
    for (i = 0; i < n; i++) {
      cin >> k;
      v.push_back(k);
      b[k].push_back(i);
    }
    for (i = 0; i < n; i++) {
      for (j = b[v[i]].begin(); j != b[v[i]].end(); j++) {
        if (abs(*j - i) >= 2) {
          flag = 1;
          break;
        }
      }
      if (flag == 1) break;
    }
    if (flag == 1)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
}
