#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, f, i, pos;
  cin >> n;
  long long a[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) pos = i;
  }
  if (n == 1 && a[1] == 1) {
    cout << "YES" << endl;
    return;
  }
  long long clo = 0, anti = 0;
  if (pos == n) {
    if (a[1] == 2) clo = 1;
  } else if (a[pos + 1] == 2)
    clo = 1;
  if (pos == 1) {
    if (a[n] == 2) anti = 1;
  } else if (a[pos - 1] == 2)
    anti = 1;
  if (clo == 0 && anti == 0) {
    cout << "NO" << endl;
    return;
  }
  if (clo == 1) {
    long long p = 2;
    for (i = pos + 1; p <= n; i++) {
      if (i == n + 1) i = 1;
      if (a[i] == p) {
        p++;
        continue;
      } else {
        cout << "NO" << endl;
        return;
      }
    }
  }
  if (anti == 1) {
    long long p = 2;
    for (i = pos - 1; p <= n; i = i - 1) {
      if (i == 0) i = n;
      if (a[i] == p) {
        p++;
        continue;
      } else {
        cout << "NO" << endl;
        return;
      }
    }
  }
  cout << "YES" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
