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