#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int max = a[0];
    int maxIn = 0;
    for (int i = 0; i < n; i++) {
      if (max < a[i]) {
        max = a[i];
        maxIn = i;
      }
    }
    bool fail = false;
    for (int i = 0; i < n - 1; i++) {
      if (a[(i + maxIn) % n] < a[(i + maxIn + 1) % n]) {
        fail = true;
        break;
      }
    }
    if (fail) {
      fail = false;
      for (int i = n; i > 1; i--) {
        if (a[(i + maxIn) % n] < a[(i + maxIn - 1) % n]) {
          fail = true;
          break;
        }
      }
    }
    if (fail) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
    }
  }
  return 0;
}
