#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int q, n, i;
  cin >> q;
  while (q--) {
    cin >> n;
    int a[n + 10], c = 0, f = 0;
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = 0; i < n - 1; i++) {
      if (a[i + 1] > a[i])
        c++;
      else
        f++;
    }
    if (a[n - 1] > a[0])
      f++;
    else
      c++;
    if (c == 1 || f == 1)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
