#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
  int t, cnt, sum, x, n;
  cin >> t;
  while (t--) {
    int flag = 0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        if (a[j] == a[i] && (j - i) > 1) {
          flag = 1;
        }
      }
      if (flag == 1) break;
    }
    if (flag == 0)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
