#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int j = 0; j < t; j++) {
    int n;
    int a;
    int ile = 0;
    cin >> n;
    int tab[n];
    for (int i = 0; i < n; i++) {
      cin >> tab[i];
      if (tab[i] == 1) a = i;
    }
    for (int i = 1; i < n; i++) {
      if (tab[i] != tab[i - 1] + 1 && i != a) ile++;
    }
    if (ile == 0)
      cout << "YES";
    else {
      ile = 0;
      for (int i = 0; i < n - 1; i++)
        if (tab[i] - 1 != tab[i + 1] && i != a) ile++;
      if (ile == 0)
        cout << "YES";
      else
        cout << "NO";
    }
    cout << "\n";
  }
  return 0;
}
