#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long m;
    cin >> m;
    vector<int> data(m);
    vector<int> s;
    vector<int> s1;
    int indexInc = 0;
    int indexDesc = 0;
    for (int j = 0; j < m; ++j) {
      cin >> data[j];
      s.push_back(j + 1);
      s1.push_back(m - j);
      if (data[j] == 1)
        indexInc = j;
      else if (data[j] == m)
        indexDesc = j;
    }
    int j = indexInc;
    int k = 0;
    bool checkInc = true;
    int hasil = (j + (m - 1)) % m;
    while (hasil != j) {
      if (s[k] != data[j]) {
        checkInc = false;
        break;
      }
      k++;
      j++;
      j %= m;
    }
    if (s[k] != data[j]) {
      checkInc = false;
    }
    j = indexDesc;
    k = 0;
    bool checkDesc = true;
    hasil = (j + (m - 1)) % m;
    while (hasil != j) {
      if (s1[k] != data[j]) {
        checkDesc = false;
        break;
      }
      k++;
      j++;
      j %= m;
    }
    if (s1[k] != data[j]) {
      checkDesc = false;
    }
    if (checkDesc || checkInc)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
