#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    vector<int> p(n);
    int id = -1;
    for (int i = 0; i < n; ++i) {
      cin >> p[i];
      if (p[i] == 1) id = i;
    }
    bool f1 = 0, f2 = 0;
    int val = 0;
    for (int i = id, j = 0; j < n; ++i, ++j) {
      ++val;
      if (p[i % n] != val) f1 = 1;
    }
    val = 0;
    for (int i = id, j = 0; j < n; --i, ++j) {
      ++val;
      if (i < 0) i += n;
      if (p[i % n] != val) f2 = 1;
    }
    if (f1 == 0 || f2 == 0)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
