#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 7;
const int NAX = (int)1e6 + 5;
const int MOD = (int)1e9 + 7;
template <class T>
inline T rem(const T &n) {
  T p = (-MOD <= n && n <= MOD) ? n : n % MOD;
  if (p < 0) p += MOD;
  return p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    vector<int> v(n);
    int pos, mn = MOD;
    for (int i = 0; i < (int)(n); ++i) {
      cin >> v[i];
      if (v[i] < mn) {
        mn = v[i];
        pos = i;
      }
    }
    if (n == 1) {
      cout << "YES\n";
      continue;
    }
    if (v[0] == 1 && is_sorted(v.begin(), v.end())) {
      cout << "YES\n";
      continue;
    }
    int p = mn, i = pos, flag = 0, fi = 1;
    while (1) {
      if (p != v[i]) {
        flag = 1;
        break;
      }
      if (!fi && i == pos) break;
      ++i;
      i %= n;
      ++p;
      if (p > n) p = 1;
      fi = 0;
    }
    if (!flag) {
      cout << "YES\n";
      continue;
    }
    p = mn, i = pos, fi = 1, flag = 0;
    while (1) {
      if (p != v[i]) {
        flag = 1;
        break;
      }
      if (!fi && i == pos) break;
      i = (i + n - 1) % n;
      ++p;
      if (p > n) p = 1;
      fi = 0;
    }
    if (!flag)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
