#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long M = 1e9 + 7;
int32_t main() {
  ;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n, 0);
    for (long long i = 0; i < n; i++) cin >> v[i];
    bool flag = false;
    for (long long i = 0; i < n; i++)
      for (long long j = i + 1; j < n; j++) {
        if (v[i] == v[j] and abs(i - j) > 1) flag = true;
      }
    if (flag == true)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
