#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    cin >> n;
    vector<int> str(n);
    for (int i = 0; i < n; ++i) {
      cin >> str[i];
    }
    vector<vector<int> > a;
    vector<int> temp;
    for (int i = 0; i < str.size(); ++i) {
      temp.clear();
      vector<int> temp(str.size());
      a.push_back(temp);
    }
    for (int i = 0; i < str.size(); ++i) {
      a[i][i] = 1;
    }
    for (int i = 0; i < str.size() - 1; ++i) {
      int t = 0;
      for (int j = 1 + i; j < str.size(); ++j) {
        if (str[t] != str[j]) {
          a[t][j] = max(a[t + 1][j], a[t][j - 1]);
        } else {
          a[t][j] = a[t + 1][j - 1] + 2;
        }
        ++t;
      }
    }
    if (a[0][str.size() - 1] > 2)
      cout << "YES";
    else
      cout << "NO";
    cout << endl;
  }
  return 0;
}
