#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, n, num;
  cin >> t;
  while (t--) {
    cin >> n;
    bool flag = false;
    unordered_map<int, vector<int>> m;
    for (int i = 0; i < n; ++i) {
      cin >> num;
      m[num].push_back(i);
    }
    for (auto& k : m) {
      if (k.second.back() - k.second.front() >= 2) {
        flag = true;
        break;
      }
    }
    if (flag)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
