#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> arr(n);
    for (long long &x : arr) cin >> x;
    string ans = "NO";
    for (long long i = 0; i < n; i++) {
      for (long long j = i + 2; j < n; j++) {
        if (arr[i] == arr[j]) ans = "YES";
      }
    }
    cout << ans << '\n';
  }
}
