#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int a[n];
    int pos;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] == 1) pos = i;
    }
    bool flag1 = true, flag2 = true;
    for (int i = 1; i < n; i++) {
      if (i == pos) continue;
      if (a[i] != a[i - 1] + 1) flag1 = false;
    }
    for (int i = 1; i < n; i++) {
      if (i == pos + 1) continue;
      if (a[i] != a[i - 1] - 1) flag2 = false;
    }
    if (flag1 || flag2)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
