#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long res = 1;
  a = a % 1000000007;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % 1000000007;
      b--;
    }
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int T = 1;
  cin >> T;
  while (T--) {
    int n, m, u, v;
    cin >> n;
    int a[n];
    int p1 = -1, p2 = -1;
    for (int i = 0; i <= n - 1; i++) {
      cin >> a[i];
      if (a[i] == 1)
        p1 = i;
      else if (a[i] == n)
        p2 = i;
    }
    int fl1 = 0;
    int fl2 = 0;
    for (int i = 1; i <= n - 1; i++) {
      if (a[(p1 + i) % n] != i + 1) fl1 = 1;
    }
    for (int i = 1; i <= n - 1; i++) {
      if (a[(p2 + i) % n] != n - i) fl2 = 1;
    }
    if (fl1 == 0 || fl2 == 0)
      cout << "YES" << '\n';
    else {
      cout << "NO" << '\n';
    }
  }
  return 0;
}
