#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> nums;
    while (n--) {
      int num;
      cin >> num;
      nums.push_back(num);
    }
    int pos = -1;
    for (int i = 0; i < nums.size(); i++)
      if (nums[i] == 1) pos = i;
    bool cl, cr;
    cl = cr = true;
    for (int i = 1; i < nums.size(); i++) {
      cr &= nums[(pos + i) % nums.size()] == i + 1;
      cl &= nums[(pos - i + nums.size()) % nums.size()] == i + 1;
    }
    string ans[] = {"NO", "YES"};
    cout << ans[cr || cl] << endl;
  }
  return 0;
}
