#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long double pi = acos(-1);
const long long maxn = 200001;
template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
  for (auto x : A) out << x << " ";
  return out;
}
template <class T1, class T2>
T1 powr(T1 a, T2 b) {
  T1 res = 1;
  for (long long i = 1; i < b + 1; i++) res = res * a;
  return res;
}
int32_t main() {
  long long Q;
  cin >> Q;
  while (Q--) {
    long long n, pos;
    cin >> n;
    vector<long long> A(n);
    for (long long i = 0; i < n; i++) {
      cin >> A[i];
      if (A[i] == 1) pos = i;
    }
    bool okl = true, okr = true;
    for (long long j = 1; j < n; j++) {
      okl &= (A[(pos - j + n) % n] == j + 1);
      okr &= (A[(pos + j + n) % n] == j + 1);
    }
    puts(okl or okr ? "YES" : "NO");
  }
}
