#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, x, loc;
  bool found;
  vector<int> vec;
  cin >> t;
  while (t--) {
    cin >> n;
    found = true;
    for (int i = 0; i < n; i++) {
      cin >> x;
      if (x == 1) {
        loc = i;
      }
      vec.push_back(x);
    }
    for (int i = 1, j = loc; i <= n; i++, j++) {
      if (vec.at(j % n) != i) {
        found = false;
        break;
      }
    }
    if (!found) {
      found = true;
      for (int i = 1, j = loc; i <= n; i++, j--) {
        if (vec.at((j + n) % n) != i) {
          found = false;
          break;
        }
      }
    }
    (found == true) ? cout << "YES\n" : cout << "NO\n";
    vec.clear();
  }
  return 0;
}
