#include <bits/stdc++.h>
using namespace std;
long long int fast_expo(long long int x, long long int p) {
  if (p == 0)
    return 1;
  else if (p % 2 == 0) {
    long long int t = fast_expo(x, p / 2) % 1000000007;
    return (t * t) % 1000000007;
  } else
    return (x * (fast_expo(x, p - 1)) % 1000000007) % 1000000007;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int a[n];
    int i, c = 1, c1 = 1, ind;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] == 1) ind = i;
    }
    i = ind;
    while (c != n) {
      if (a[i] == c) {
        c++;
        if (i == n - 1)
          i = 0;
        else
          i++;
      } else
        break;
    }
    i = ind;
    while (c1 != n) {
      if (a[i] == c1) {
        c1++;
        if (i == 0)
          i = n - 1;
        else
          i--;
      } else
        break;
    }
    if (c == n || c1 == n)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
