#include <bits/stdc++.h>
using namespace std;
vector<int> freq[5005];
class Solution {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int t;
    in >> t;
    while (t--) {
      int x;
      in >> x;
      for (int i = 0; i < x; i++) {
        int y;
        in >> y;
        freq[y].push_back(i);
      }
      bool flag = false;
      for (int i = 0; i < 5001; i++) {
        if ((int)freq[i].size() >= 2) {
          int a = freq[i][0];
          int b = freq[i][(int)freq[i].size() - 1];
          if (b - a > 1) {
            flag = true;
            break;
          }
        }
      }
      if (flag) {
        out << "YES" << '\n';
      } else {
        out << "NO" << '\n';
      }
      for (int i = 0; i < 5001; i++) freq[i].clear();
    }
    return;
  }
};
void solve(std::istream& in, std::ostream& out) {
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  istream& in = cin;
  ostream& out = cout;
  solve(in, out);
  return 0;
}
