#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a;
    std::vector<int> v(a);
    for (int i = 0; i < a; ++i) {
      cin >> v[i];
    }
    int f = 0;
    for (int i = 0; i < a - 2; ++i) {
      if (count(v.begin() + i, v.end(), v[i]) > 1 && (v[i] != v[i + 1])) {
        f = 1;
        break;
      }
      if (count(v.begin() + i, v.end(), v[i]) > 2 && (v[i] == v[i + 1])) {
        f = 1;
        break;
      }
    }
    if (f) {
      cout << "YES\n";
    } else
      cout << "NO\n";
  }
  return 0;
}
