#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int a[2 * n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      a[i + n] = a[i];
    }
    int m = 2 * n;
    bool flag = 0;
    for (int i = 0; i < m; i++) {
      if (a[i] == 1) {
        int x = 1;
        for (int j = i; (j >= 0 && x <= n); j--) {
          if (a[j] == x)
            x++;
          else
            break;
        }
        if (x == n + 1) {
          flag = 1;
          break;
        }
        x = 1;
        for (int j = i; (j < m && x <= n); j++) {
          if (a[j] == x)
            x++;
          else
            break;
        }
        if (x == n + 1) {
          flag = 1;
          break;
        }
      }
    }
    if (flag) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
