#include <bits/stdc++.h>
using namespace std;
int main() {
  int numTests;
  cin >> numTests;
  while (numTests--) {
    int n;
    cin >> n;
    vector<int> students;
    int firstStudent = 0;
    for (int i = 0; i < n; i++) {
      int newStudent;
      cin >> newStudent;
      if (newStudent == 1) {
        firstStudent = i;
      }
      students.push_back(newStudent);
    }
    bool canClockwise = true;
    for (int i = 0; i < n; i++) {
      int location = (firstStudent + i) % n;
      if (students[location] != i + 1) {
        canClockwise = false;
      }
    }
    bool canCounterClockwise = true;
    for (int i = 0; i < n; i++) {
      int location = (firstStudent - i);
      if (location < 0) {
        location += n;
      }
      if (students[location] != i + 1) {
        canCounterClockwise = false;
      }
    }
    if (canClockwise || canCounterClockwise) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
