#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int k = 0; k < n; k++) {
    int x;
    cin >> x;
    int arr[x];
    bool flag = false;
    for (int i = 0; i < x; i++) {
      cin >> arr[i];
    }
    for (int i = 0; i < x; i++) {
      for (int j = 0; j < x; j++) {
        if (arr[i] == arr[j] && abs(i - j) >= 2) {
          flag = true;
          break;
        }
      }
    }
    if (flag == true)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
