#include <bits/stdc++.h>
using namespace std;
int n, t, a[205], b[205], c[205], u, v, vt;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    u = 0, v = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      if (a[i] == 1) vt = i;
    }
    u++;
    b[u] = a[vt];
    v++;
    c[v] = a[vt];
    for (int j = vt + 1; j <= n; j++) {
      u++;
      b[u] = a[j];
    }
    for (int j = 1; j <= vt - 1; j++) {
      u++;
      b[u] = a[j];
    }
    for (int j = vt - 1; j >= 1; j--) {
      v++;
      c[v] = a[j];
    }
    for (int j = n; j >= vt + 1; j--) {
      v++;
      c[v] = a[j];
    }
    bool ok1 = true;
    bool ok2 = true;
    for (int i = 1; i <= u - 1; i++) {
      if (b[i] > b[i + 1]) {
        ok1 = false;
        break;
      }
    }
    for (int i = 1; i <= v - 1; i++) {
      if (c[i] > c[i + 1]) {
        ok2 = false;
        break;
      }
    }
    if (ok1 == true || ok2 == true) cout << "YES" << '\n';
    if (ok1 == false && ok2 == false) cout << "NO" << '\n';
  }
  return 0;
}
