#include <bits/stdc++.h>
using namespace std;
const int MaxN = 5010;
int test, n;
int a[MaxN];
vector<int> B[MaxN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> test;
  while (test--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
      B[i].clear();
    }
    for (int i = 1; i <= n; i++) {
      B[a[i]].push_back(i);
    }
    bool flag = false;
    for (int i = 1; i <= n; i++) {
      if (B[i].size() >= 3) {
        flag = true;
        break;
      } else if (B[i].size() == 2) {
        if (B[i][1] - B[i][0] >= 2) {
          flag = true;
          break;
        }
      }
    }
    cout << (flag ? "YES\n" : "NO\n");
  }
  return 0;
}
