#include <bits/stdc++.h>
inline int in();
inline void wr(int);
const int N = (int)4e2 + 5;
int n, a[N];
inline bool check(int, int);
int main(int argc, char** argv) {
  register int T = in();
  while (T--) {
    n = in();
    for (register int i = 1; i <= n; ++i) a[i + n] = a[i] = in();
    register bool tp = 0;
    for (register int p = 1; p + n - 1 <= (n << 1) && !tp; ++p) {
      if (a[p] != 1 && a[p] != n) continue;
      tp = check(p, a[p]);
    }
    puts(tp ? "YES" : "NO");
  }
}
inline bool check(int p, int x) {
  if (x == 1)
    for (register int i = p; i <= p + n - 1; ++i)
      if (a[i] != i - p + 1) return 0;
  if (x == n)
    for (register int i = p; i <= p + n - 1; ++i)
      if (a[i] != p + n - i) return 0;
  return 1;
}
inline int in() {
  register char c = getchar();
  register int x = 0, f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 1) + (x << 3) + (c & 15);
  return x * f;
}
inline void wr(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x / 10) wr(x / 10);
  putchar(x % 10 + '0');
}
