#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      mp[a[i]]++;
    }
    int cache = -1;
    bool ans = false;
    for (int i = 0; i < n; ++i) {
      if (mp[a[i]] > 2) {
        ans = true;
        break;
      } else if (cache == -1 && mp[a[i]] > 1) {
        cache = a[i];
      } else if (cache != -1) {
        if (cache != a[i]) {
          ans = true;
          break;
        }
        cache = -1;
      }
    }
    if (ans) {
      cout << "YES";
    } else {
      cout << "NO";
    }
    cout << "\n";
  }
  return 0;
}
