#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[1000000];
long long A[10000], n, i, x, y, k, j, flag, t;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    flag = 0;
    cin >> n;
    long long A[n + 2];
    memset(A, 0, sizeof(A));
    for (i = 1; i <= n; i++) {
      cin >> A[i];
      if (A[i] == 1) x = i;
    }
    if (x == n)
      y = 1;
    else
      y = x + 1;
    if (x == 1)
      k = n;
    else
      k = x - 1;
    if (A[y] == 2) {
      j = 1;
      for (i = x; i <= n; i++) {
        if (A[i] == (j++))
          continue;
        else {
          flag = 1;
          break;
        }
      }
      for (i = 1; i < x; i++) {
        if (A[i] == (j++))
          continue;
        else {
          flag = 1;
          break;
        }
      }
    } else if (A[k] == 2) {
      j = 1;
      for (i = x; i >= 1; i--) {
        if (A[i] == (j++))
          continue;
        else {
          flag = 1;
          break;
        }
      }
      for (i = n; i > x; i--) {
        if (A[i] == (j++))
          continue;
        else {
          flag = 1;
          break;
        }
      }
    } else {
      if (n != 1) flag = 1;
    }
    if (flag)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
    }
  }
}
