#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, flag = false;
    cin >> n;
    long long int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
      mp[a[i]]++;
      if (i > 0 and mp[a[i]] > 1 and a[i - 1] != a[i]) flag = true;
      if (mp[a[i]] > 2) flag = true;
    }
    if (!flag)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
