#include <bits/stdc++.h>
using namespace std;
int a[2005], br[2005][30];
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(br, 0, sizeof(br));
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      for (int j = 1; j <= 26; j++) {
        if (j == a[i])
          br[i][j] = br[i - 1][j] + 1;
        else
          br[i][j] = br[i - 1][j];
      }
    }
    if (n == 1) {
      cout << 1 << endl;
      continue;
    }
    int gl = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i; j <= n; j++) {
        int x = 0, y = 0;
        for (int g = 1; g <= 26; g++) {
          if (br[i][g] == 0 && br[n][g] - br[j][g] == 0 && br[j][g] == 0 &&
              br[i][g] == 0)
            continue;
          if (x < min((br[i][g]), (br[n][g] - br[j][g])))
            x = min((br[i][g]), (br[n][g] - br[j][g]));
          if (y < (br[j][g] - br[i][g])) y = (br[j][g] - br[i][g]);
        }
        if (gl < 2 * x + y) gl = 2 * x + y;
      }
    }
    cout << gl << endl;
  }
}
