#include <bits/stdc++.h>
using namespace std;
const int MAX = 200005;
int a[MAX];
int b[MAX];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    map<int, vector<int>> s;
    bool flag = false;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      s[a[i]].push_back(i);
    }
    for (auto &i : s) {
      if (i.second.size() >= 3) {
        flag = true;
        break;
      }
      if (i.second.size() == 2) {
        if (i.second[0] != i.second[1] - 1) {
          flag = true;
          break;
        }
      }
    }
    if (flag) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
