#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q-- > 0) {
    int n;
    cin >> n;
    int arr[n];
    int start = -1;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] == 1) {
        start = i;
      }
    }
    int i = 0;
    while (i < n) {
      int pos = (i + start) % n;
      int next = (i + 1 + start) % n;
      if (arr[pos] > arr[next] && arr[next] != 1) {
        break;
      }
      i++;
    }
    if (i == n) {
      cout << "YES\n";
      continue;
    }
    i = 0;
    while (i < n) {
      int pos = (i + start) % n;
      int next = (i + 1 + start) % n;
      if (arr[pos] < arr[next] && arr[pos] != 1) {
        break;
      }
      i++;
    }
    if (i == n) {
      cout << "YES\n";
      continue;
    }
    cout << "NO\n";
  }
  return 0;
}
