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