#include <bits/stdc++.h>
using namespace std;
int n, k, x, t;
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n;
    unordered_map<int, vector<int> > pl;
    bool b = 0;
    for (int i = 0; i < n; i++) {
      cin >> x;
      pl[x].push_back(i);
      if (pl[x][pl[x].size() - 1] - pl[x][0] > 1) {
        b = 1;
      }
    }
    cout << (b ? "YES" : "NO") << '\n';
  }
}
