#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    vector<int> rec;
    vector<int> a;
    vector<int> flag;
    int num, pre;
    int x;
    cin >> num;
    rec.resize(num + 1, 0);
    flag.resize(num + 1, 0);
    for (int i = 0; i < num; i++) {
      cin >> x;
      a.push_back(x);
    }
    pre = -1;
    for (int j = 0; j < num; j++) {
      if (pre == a[j] && flag[a[j]] == 1) {
        rec[a[j]]++;
        flag[a[j]]++;
        if (j == num - 1) {
          cout << "NO" << endl;
          break;
        }
        continue;
      }
      rec[a[j]]++;
      flag[a[j]]++;
      if (rec[a[j]] >= 2) {
        cout << "YES" << endl;
        break;
      } else if (j == num - 1) {
        cout << "NO" << endl;
      }
      pre = a[j];
    }
  }
}
