#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    if (n == 1 && arr[0]) {
      cout << "YES" << endl;
      continue;
    }
    int tmp = n, x = 0, prev = 0, nxt = 0, flag = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] == 1) {
        x = i;
        break;
      }
    }
    if (x - 1 < 0) {
      prev = n - 1;
      nxt = x + 1;
    } else if (x + 1 == n) {
      nxt = 0;
      prev = x - 1;
    } else {
      nxt = x + 1;
      prev = x - 1;
    }
    if (arr[nxt] == 2 || arr[prev] == 2) {
      if (arr[nxt] == 2) {
        flag = -5;
      } else if (arr[prev] == 2)
        flag = 5;
    } else {
      cout << "NO" << endl;
      continue;
    }
    int check = 0;
    if (flag == -5) {
      int i = 2;
      while (i < n) {
        if (arr[nxt] != i++) {
          cout << "NO" << endl;
          check = 5;
          break;
        }
        nxt = (nxt + 1) % n;
      }
      if (check == 0) cout << "YES" << endl;
    } else if (flag == 5) {
      int i = 2;
      while (i < n) {
        if (arr[prev] != i) {
          cout << "NO" << endl;
          check = 5;
          break;
        }
        prev = (prev - 1);
        i++;
        if (prev < 0) prev = n - 1;
      }
      if (check == 0) cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
