#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = 1, id, p = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == 1) {
        id = i;
        break;
      }
    }
    if (ans) {
      int k = 1;
      for (int i = id; i < n; i++) {
        if (a[i] != k) p = 1;
        k++;
      }
      for (int i = 0; i < id; i++) {
        if (a[i] != k) p = 1;
        k++;
      }
    }
    if (p == 0)
      cout << "YES\n";
    else {
      int k = 1;
      for (int i = id; i >= 0; i--) {
        if (a[i] != k) ans = 0;
        k++;
      }
      for (int i = n - 1; i > id; i--) {
        if (a[i] != k) ans = 0;
        k++;
      }
      if (ans)
        cout << "YES\n";
      else
        cout << "NO\n";
    }
  }
}
