#include <bits/stdc++.h>
using namespace std;
long long q;
long long n;
long long a[2000];
int main() {
  cin >> q;
  while (q--) {
    bool flag = 1;
    int mark = -1;
    cin >> n;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] == 1) mark = i;
    }
    if (n == 1 || n == 2 || n == 3) {
      cout << "YES\n";
      continue;
    }
    if (mark != -1) {
      if (a[(mark + 1) % n] == 2) {
        int temp = (mark + 1) % n;
        int tempnum = 2;
        while (temp != (mark - 1 + n) % n) {
          temp = (temp + 1) % n;
          if (a[temp] == ++tempnum)
            continue;
          else {
            cout << "NO\n";
            break;
          }
        }
        if (temp == (mark - 1 + n) % n) cout << "YES\n";
      } else if (a[(mark - 1 + n) % n] == 2) {
        int temp = (mark - 1 + n) % n;
        int tempnum = 2;
        while (temp != (mark + 1) % n) {
          temp = (temp - 1 + n) % n;
          if (a[temp] == ++tempnum)
            continue;
          else {
            cout << "NO\n";
            break;
          }
        }
        if (temp == (mark + 1) % n) cout << "YES\n";
      } else {
        cout << "NO\n";
        continue;
      }
    }
  }
  return 0;
}
