#include <bits/stdc++.h>
using namespace std;
int n, m, ct, ans, s, a[500000];
void work() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  if (n == 1) {
    printf("YES\n");
    return;
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] == 1) {
      if (a[(i - 1 + n) % n] == 2) {
        for (int j = (i - 1 + n) % n; j != i; j = (j - 1 + n) % n) {
          if (a[j] != a[(j + 1) % n] + 1) {
            printf("NO\n");
            return;
          }
        }
        printf("YES\n");
      } else if (a[(i + 1) % n] == 2) {
        for (int j = (i + 1) % n; j != i; j = (j + 1) % n) {
          if (a[(j - 1 + n) % n] + 1 != a[j]) {
            printf("NO\n");
            return;
          }
        }
        printf("YES\n");
      } else {
        printf("NO\n");
      }
      return;
    }
  }
}
int main() {
  int TestCase = 1;
  scanf("%d", &TestCase);
  while (TestCase--) {
    work();
  }
  return 0;
}
