#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 7;
const double eps = 1e-18;
int n;
long long a[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int f = 0;
    if (n == 1) {
      cout << "YES" << endl;
      continue;
    }
    int fx = -1;
    int next;
    int in = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == 1) {
        if (i + 1 < n) {
          next = a[i + 1];
        } else
          next = a[0];
        in = i;
        break;
      }
    }
    if (next == 2) {
      fx = 1;
    }
    int b[1001];
    if (fx == 1) {
      for (int i = in, cnt = 0; cnt < n; i++, cnt++) {
        b[cnt] = a[i % n];
      }
      for (int i = 1; i < n; i++) {
        if (b[i] != b[i - 1] + fx) {
          f = 1;
          break;
        }
      }
      if (f)
        cout << "NO" << endl;
      else
        cout << "YES" << endl;
    } else {
      int inn;
      for (int i = 0; i < n; i++) {
        if (a[i] == n) {
          inn = i;
          break;
        }
      }
      for (int i = inn, cnt = 0; cnt < n; i++, cnt++) {
        b[cnt] = a[i % n];
      }
      for (int i = 1; i < n; i++) {
        if (b[i] != b[i - 1] + fx) {
          f = 1;
          break;
        }
      }
      if (f)
        cout << "NO" << endl;
      else
        cout << "YES" << endl;
    }
  }
}
