#include <bits/stdc++.h>
int main() {
  int q;
  std::cin >> q;
  for (int i = 0; i < q; i++) {
    int n;
    std::cin >> n;
    std::vector<int> vec(n);
    for (int i = 0; i < n; i++) std::cin >> vec[i];
    int min = 1e9, it;
    for (int i = 0; i < n; i++) {
      if (vec[i] < min) {
        min = vec[i];
        it = i;
      }
    }
    bool check1 = true, check2 = true;
    for (int i = 0; i < n; i++) {
      if (vec[(it + i) % n] == n) continue;
      if (vec[(it + i) % n] + 1 != vec[(it + i + 1) % n]) {
        check1 = false;
        break;
      }
    }
    int max = -1e9;
    for (int i = 0; i < n; i++) {
      if (vec[i] > max) {
        max = vec[i];
        it = i;
      }
    }
    for (int i = 0; i < n; i++) {
      if (vec[(it + i) % n] == 1) continue;
      if (vec[(it + i) % n] != vec[(it + i + 1) % n] + 1) {
        check2 = false;
        break;
      }
    }
    if (check1 || check2)
      std::cout << "YES\n";
    else
      std::cout << "NO\n";
  }
  return 0;
}
