#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

using namespace std;

#define $(x) (int)  ((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector

#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else
    #define dbg(x)
#endif

void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(9);
    solve();
    return 0;
}

const int MOD = 998244353, MAXN = 1e2 + 10, INF = 1e9 + 10;

void query() {
    int n, m;
    cin >> n >> m;
    int d = m, u = m;
    int pt = 0;
    for (int i = 1; i <= n; ++i) {
        int l, h, t;
        cin >> t >> l >> h;
        int dist = t - pt;
        pt = t;
        if (u < d) {
            cout << "NO" << endl;
            return;
        }
        u += dist;
        d -= dist;
        u = min(u, h);
        d = max(d, l);
        if (u < d) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

void solve() {
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        query();
    }
}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		for(int i=0;i<q;i++) {
			int n=sc.nextInt();
			int[]arr=new int[n];
			for(int j=0;j<n;j++) {
				int x=sc.nextInt();
				arr[j]=x;
			}
			if (dance(arr))
				System.out.println("YES");
			else
				System.out.println("NO");

//		int[]arr= {5,4,1,2,3};
//		System.out.println(dance(arr));
		}
//		int[]  a= {5,2,1,4,3};
//		System.out.println(dance(a));
	}
	public static boolean dance(int[]arr) {
		int first=arr[0];
		int i=0;
		for(;i<arr.length-1;i++) {
			System.out.println(arr[i] + " " + arr[i+1]);
			if ((arr[i]+1==arr[i+1]) || (arr[i]-1==arr[i+1])) {
				System.out.println("Geo 0 ");

			}
			else if (arr[i+1]==arr.length) {
				System.out.println("Geo 1");
				i++;
				break;
			}	else if (arr[i]==arr.length && arr[i+1]==1){
				System.out.println("Geo 2 ");
			}
			else
				return false;

		}
		for(;i<arr.length-1;i++) {
			if (arr[i]-1 != arr[i+1]) {
			//	System.out.println(arr[i] + " "+arr[i+1]);
			//	System.out.println("Geo 2 " + (arr[i]-arr[i+1]));
				return false;
			}
			if (i==arr.length-2) {
			//	System.out.println("Geo 3 ");
				if (first != arr[arr.length-1]-1 && first!= arr[arr.length-1]+1)
					return false;
			}
		}

			return true;

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

	public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

	public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		for(int i=0;i<q;i++) {
			int n=sc.nextInt();
			int[]arr=new int[n];
			for(int j=0;j<n;j++) {
				int x=sc.nextInt();
				arr[j]=x;
			}
			if (dance(arr))
				System.out.println("YES");
			else
				System.out.println("NO");

	//	int[]arr= {5,4,1,2,3};
	//	System.out.println(dance(arr));
		}
	//	int[]  a= {5,2,1,4,3};
//		System.out.println(dance(a));
	}
	public static boolean dance(int[]arr) {
		int first=arr[0];
		int i=0;
		for(;i<arr.length-1;i++) {
	//		System.out.println(arr[i] + " " + arr[i+1]);
			if ((arr[i]+1==arr[i+1]) || (arr[i]-1==arr[i+1])) {
		//		System.out.println("Geo 0 ");

			}
			else if (arr[i+1]==arr.length) {
		//		System.out.println("Geo 1");
				i++;
				break;
			}	else if (arr[i]==arr.length && arr[i+1]==1){
		//		System.out.println("Geo 2 ");
			}
			else
				return false;

		}
		for(;i<arr.length-1;i++) {
			if (arr[i]-1 != arr[i+1]) {
			//	System.out.println(arr[i] + " "+arr[i+1]);
			//	System.out.println("Geo 2 " + (arr[i]-arr[i+1]));
				return false;
			}
			if (i==arr.length-2) {
			//	System.out.println("Geo 3 ");
				if (first != arr[arr.length-1]-1 && first!= arr[arr.length-1]+1)
					return false;
			}
		}

			return true;

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

	public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

	public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		for(int i=0;i<q;i++) {
			int n=sc.nextInt();
			int[]arr=new int[n];
			for(int j=0;j<n;j++) {
				int x=sc.nextInt();
				arr[j]=x;
			}
			if (dance(arr))
				System.out.println("YES");
			else
				System.out.println("NO");
		}
//		int[]  a= {5,2,1,4,3};
//		System.out.println(dance(a));
	}
	public static boolean dance(int[]arr) {
		int first=arr[0];
		int i=0;
		for(;i<arr.length-1;i++) {
		//	System.out.println(arr[i] + " " + arr[i+1]);
			if ((arr[i]!=arr[i+1]+1) && (arr[i]!=arr[i+1]-1)) {

				if (arr[i+1]==arr.length) {
			//		System.out.println("Geo 1");
					i++;
					break;
				}
			}
		}
		for(;i<arr.length-1;i++) {
			if (arr[i]-1 != arr[i+1]) {
			//	System.out.println(arr[i] + " "+arr[i+1]);
			//	System.out.println("Geo 2 " + (arr[i]-arr[i+1]));
				return false;
			}
			if (i==arr.length-2) {
			//	System.out.println("Geo 3 ");
				if (first != arr[arr.length-1]-1 && first!= arr[arr.length-1]+1)
					return false;
			}
		}

			return true;

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

	public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

	public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		for(int i=0;i<q;i++) {
			//System.out.println("Geo 0");
			int n=sc.nextInt();
			if(n==1) {
				System.out.println("YES");
			//	System.out.println("Geo 1");
			}
			else {
				int curr=sc.nextInt();
				boolean f=true;
				for(int j=0;j<n-1;j++) {
					int x=sc.nextInt();
				//	System.out.println(" curr " + curr + "x " + x);
					if ((x == curr+1) || (x == curr-1)) {
						curr=x;

					}
					else if (x == n) {
						if (curr==1) {
							curr=x;
						}
						else {
							int y=sc.nextInt();
							if(y==1) {
								curr=y;
								j++;
							}
							else {
								f=false;
								System.out.println("NO");
								break;
							}
						}
					}
					else {
					//	System.out.println("Geo 2");
						System.out.println("NO");
						f = false;
						break;
					}
				}
				if (f)
					System.out.println("YES");
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		for(int i=0;i<q;i++) {
			int n=sc.nextInt();
			int[]arr=new int[n];
			for(int j=0;j<n;j++) {
				int x=sc.nextInt();
				arr[j]=x;
			}
			if (dance(arr))
				System.out.println("YES");
			else
				System.out.println("NO");
//		int[]arr= {5,2,1,4,3};
//		System.out.println(dance(arr));
		}
//		int[]  a= {5,2,1,4,3};
//		System.out.println(dance(a));
	}
	public static boolean dance(int[]arr) {
		int first=arr[0];
		int i=0;
		for(;i<arr.length-1;i++) {
		//	System.out.println(arr[i] + " " + arr[i+1]);
			if ((arr[i]+1==arr[i+1]) || (arr[i]-1==arr[i+1])) {
		//		System.out.println("Geo 0 ");

			}
			else if  (arr[i+1]==arr.length) {
		//		System.out.println("Geo 1");
				i++;
				break;
			}	else if (arr[i+1]==1){
		//		System.out.println("Geo 2 ");
			}
			else
				return false;

		}
		for(;i<arr.length-1;i++) {
			if (arr[i]-1 != arr[i+1]) {
			//	System.out.println(arr[i] + " "+arr[i+1]);
			//	System.out.println("Geo 2 " + (arr[i]-arr[i+1]));
				return false;
			}
			if (i==arr.length-2) {
			//	System.out.println("Geo 3 ");
				if (first != arr[arr.length-1]-1 && first!= arr[arr.length-1]+1)
					return false;
			}
		}

			return true;

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

	public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

	public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		for(int i=0;i<q;i++) {
			//System.out.println("Geo 0");
			int n=sc.nextInt();
			if(n==1) {
				System.out.println("YES");
			//	System.out.println("Geo 1");
			}
			else {
				int curr=sc.nextInt();
				boolean f=true;
				for(int j=0;j<n-1;j++) {
					int x=sc.nextInt();
				//	System.out.println(" curr " + curr + "x " + x);
					if ((x == curr+1) || (x == curr-1)) {
						curr=x;

					}
					else if (x == n) {
						if (curr!=1) {
							System.out.println("NO");
							f=false;
						}
					}
//					else {
//						System.out.println("Geo 2");
//						System.out.println("NO");
//						f = false;
//					}
				}
				if (f)
					System.out.println("YES");
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		for(int i=0;i<q;i++) {
			//System.out.println("Geo 0");
			int n=sc.nextInt();
			if(n==1) {
				System.out.println("YES");
			//	System.out.println("Geo 1");
			}
			else {
				int curr=sc.nextInt();
				boolean f=true;
				for(int j=0;j<n-1;j++) {
					int x=sc.nextInt();
				//	System.out.println(" curr " + curr + "x " + x);
					if ((x == curr+1) || (x == curr-1)) {
						curr=x;

					}
					else if (x == n) {
						if (curr==1) {
							curr=x;
						}
						else {
							int y=sc.nextInt();
							if(y==1) {
								curr=y;
								j++;
							}
							else {
								f=false;
								System.out.println("NO");
							}
						}
					}
//					else {
//						System.out.println("Geo 2");
//						System.out.println("NO");
//						f = false;
//					}
				}
				if (f)
					System.out.println("YES");
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.*;
public class Solution{
         public static void main(String[] arg){
		    Scanner sc=new Scanner(System.in);
			int q=sc.nextInt();
			for(int i=0;i<q;i++){
				String start="",end="",val="";
				int n=sc.nextInt();
				int[] arr=new int[n];
				int flag=0;
				for(int j=0;j<n;j++){
					arr[j]=sc.nextInt();
					if(j>0){
						if(Math.abs(arr[j]-arr[j-1])>=2)
							flag=j;
					}
					val+=arr[j];
				}
				String result=val.substring(flag)+val.substring(0,flag);
				//System.out.println(result);
				for(int j=1;j<=n;j++){
					start+=j;
					end=j+end;
				}
				if(start.equals(result)==true)
					System.out.println("YES");
				else if(end.equals(result)==true)
					System.out.println("YES");
				else System.out.println("NO");
				//System.out.println(start);
				//System.out.println(end);
			}
        }
    }


import java.util.*;
public class Solution{
         public static void main(String[] arg){
		    Scanner sc=new Scanner(System.in);
			int q=sc.nextInt();
			for(int i=0;i<q;i++){
				String start="",end="",val="";
				int n=sc.nextInt();
				int[] arr=new int[n];
				int flag=0;
				for(int j=0;j<n;j++){
					arr[j]=sc.nextInt();
					val+=arr[j];
					if(j>0){
						if(Math.abs(arr[j]-arr[j-1])>=2){
                         String ff=""+arr[j];
						flag=val.length()-ff.length();
						}
					}
				}
				String result=val.substring(flag)+val.substring(0,flag);
				//System.out.println(result);
				for(int j=1;j<=n;j++){
					start+=j;
					end=j+end;
				}
				if(start.equals(result)==true)
					System.out.println("YES");
				else if(end.equals(result)==true)
					System.out.println("YES");
				else System.out.println("NO");
				//System.out.println(start);
				//System.out.println(end);
			}
        }
    }


#include <iostream>
#include <algorithm>
#include <vector>

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))

template <class T> T& chmax(T& a, T b){return (a < b) ? a = b : a;}
template <class T> T& chmin(T& a, T b){return (a > b) ? a = b : a;}

using lli = long long int;

constexpr int MAX_SIZE = 200;
std::vector<int> A(MAX_SIZE);

bool judge(int n){
    int argOne = 0;
    while(true) if(A[argOne++] == 1){argOne--; break;}
    bool flag = true;
    REP(i, n-1){
        int d = (A[(argOne + i + 1) % n] - A[(argOne + i) % n]) % n;
        if(d != 1){flag = false; break;}
    }
    if(flag) return true;
    flag = true;
    REP(i, n-1){
        int d = (A[(argOne - i - 1 + n) % n] - A[(argOne - i + n) % n]) % n;
        if(d != 1){flag = false; break;}
    }
    return flag;
}

int main(void){
    int Q; scanf("%d", &Q);
    while(Q--){
        int n; scanf("%d", &n);
        REP(i, n) scanf("%d", &A[i]);
        puts(judge(n) ? "YES" : "NO");
    }
    return 0;
}


'use strict'

const roundelay = (n, p) => {
    let i = 1;
    while (i < n && (p[i] === p[i-1] + 1 || p[i-1] === n && p[i] === 1)) i++;
    if (i === n) return 'YES';
    i = 1;
    while (i < n && (p[i] === p[i-1] - 1 || p[i-1] === 1 && p[i] === n)) i++;
    if (i === n) return 'YES';
    return 'NO';
}

const q = parseInt(readline());
for (let i = 0; i < q; i++) {
    write(roundelay(parseInt(readline()), readline().split(' ').map(Number)) + '\n');
}


'use strict'

const roundelay = (n, p) => {
    let i = 1;
    while (i < n && (p[i] === p[i-1] + 1 || p[i-1] === n && p[i] === 1)) i++;
    if (i === n) return 'OK';
    i = 1;
    while (i < n && (p[i] === p[i-1] - 1 || p[i-1] === 1 && p[i] === n)) i++;
    if (i === n) return 'OK';
    return 'NO';
}

const q = parseInt(readline());
for (let i = 0; i < q; i++) {
    roundelay(parseInt(readline()), readline().split(' ').map(Number));
}


'use strict'

const roundelay = (n, p) => {
    let i = 1;
    while (i < n && (p[i] === p[i-1] + 1 || p[i-1] === n && p[i] === 1)) i++;
    if (i === n) return 'OK';
    i = 1;
    while (i < n && (p[i] === p[i-1] - 1 || p[i-1] === 1 && p[i] === n)) i++;
    if (i === n) return 'OK';
    return 'NO';
}

const q = parseInt(readline());
for (let i = 0; i < q; i++) {
    write(roundelay(parseInt(readline()), readline().split(' ').map(Number)) + '\n');
}


rVal = () => +readline();
rArr = () => readline().split(' ').map(item => +item);

var q = rVal();

for(var i = 0; i < q; i++) {
  var n = rVal();
  var arr = rArr();

  if(n === 1) {
    print('YES');
    continue;
  }

  for(var j = 0; j < n; j++) {
    if(arr[j] === 1) {
      index = j;
      break;
    }
  }

  var j = 0;

  for(j = 0, k = index; j < n - 1; j++) {
    var k2 = k + 1;
    if(k2 === n) {
      k2 = 0;
    }
    if(arr[k2] - arr[k] === 1) {
      k = k2;
    } else {
      break;
    }
  }

  if(j === n - 1) {
    print('YES');
    continue;
  }

  for(var j = 0, k = index; j < n - 1; j++) {
    var k2 = k - 1;
    if(k2 < 0) {
      k2 = n - 1;
    }
    if(arr[k2] - arr[k] === 1) {
      k = k2;
    } else {
      break;
    }
  }

  if(j === n - 1) {
    print('YES');
    continue;
  }

  print('NO');
}


'use strict'

var t=Number(readline());

while(t--)
{
    var n=parseInt(readline());
    var data=readline().split(' ').map(Number);

    var start_idx=-1;
    for(var i=0;i<n;i++){
        if(data[i]==1) start_idx=i;
    }

    var flag= true;
    var clockW=start_idx;

    for(var i=1;i<n;i++){
        var tmp=data[clockW];
        clockW++;
        if(clockW>=n) clockW=0;
        if((data[clockW]-tmp)!=1){
            flag=false;
            break;
        }
    }

    if(!flag){
        flag=true;
        clockW=start_idx;

        for(var i=1;i<n;i++){
            var tmp=data[clockW];
            clockW--;
            if(clockW<0) clockW=n-1;

            if( (data[clockW]-tmp)!=1 ){
                flag=false;
                break;
            }
        }
    }

    print((flag)?"YES":"NO");
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int q{0};
    cin >> q ;
    while(q--)
    {
        int n{0},clk{2},ant{2};
        cin >> n;
        vector<int> vec;
        for(int i{0};i<n;i++)
        {
            int p{0};
            cin >> p;
            vec.push_back(p);
        }
        int a=vec[0];
        if(n!=1)
        {
            if(vec[1]==vec[0]+1)
            {
                int i{0};
                for(int j{a};j<n;j++)
                {
                    if(vec[i+1]!=vec[i]+1)
                    {
                        cout << "NO" << '\n';
                        clk =1;
                        break;
                    }
                    i++;
                }
            //cout << i;
                if(i<vec.size()-1)
                    i++;

                for(int j{1};j>(a-1);j++)
                {
                    if(clk == 1 || i == vec.size()-1)
                        break;
                    else if(vec[i+1]!=vec[i]+1)
                    {
                        cout << "NO" << '\n';
                        clk =1;
                        break;
                    }
                }
                if(clk==2)
                    cout << "YES" << '\n';
            }
            else if(vec[1]==vec[0]-1 || vec[1]==n)
            {
                int i{0};
                for(int j{a};j>1;j--)
                {
                    if(vec[i+1]!=vec[i]-1)
                    {
                    cout << "NO" << '\n';
                    ant=1;
                    break;
                }
                i++;
            }
            //cout << i ;
            if(i<vec.size()-1)
                i++;

            for(int j{n};j>(a+1);j--)
            {
                if(ant == 1 || i == vec.size()-1)
                    break;
                else if(vec[i+1]!=vec[i]-1)
                {
                    cout << "NO" << '\n';
                    ant =1;
                    break;
                }
            }
            if(ant==2)
                cout << "YES" << '\n';
            }
            else
                cout << "NO" << '\n';
        }
        else
            cout << "YES" << '\n';
    }
    return 0;
}


    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int q{0};
        cin >> q;
        while(q--)
        {
            int n{0},m{0},flag{1},z{0};
            cin >> n;
            m=n;
            vector<int> vec;
            while(m--)
            {
                int p{0};
                cin >>p;
                vec.push_back(p);
                if(p==1)
                    z=vec.size()-1;
            }
            if(z==0&&vec[z+1]!=n)
            {
                for(int i{0};i<n-1;i++)
                {
                    if(vec[i+1]!=vec[i]+1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
            }
            else if(z==0&&vec[z+1]==n)
            {
                for(int i{z+1};i<n-1;i++)
                {
                    if(vec[i+1]!=vec[i]-1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
            }
            else if(z==n-1&&vec[z-1]!=n)
            {
                for(int i{z};i>0;i--)
                {
                    if(vec[i-1]!=vec[i]+1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
            }
            else if(z==n-1&&vec[z-1]==n)
            {
                for(int i{z-1};i>0;i--)
                {
                    if(vec[i-1]!=vec[i]-1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
            }
            else if(vec[z+1]==n&&vec[z-1]==vec[z]+1)
            {
                for(int i{z+1};i<n-1;i++)
                {
                    if(vec[i+1]!=vec[i]-1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
                for(int i{z};i>0;i--)
                {
                    if(vec[i-1]!=vec[i]+1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
            }
            else if(vec[z+1]==vec[z]+1&&vec[z-1]==n)
            {
                for(int i{z};i<n-1;i++)
                {
                    if(vec[i+1]!=vec[i]+1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
                for(int i{z-1};i>0;i--)
                {
                    if(vec[i-1]!=vec[i]-1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
            }
            else
            {
                cout << "NO\n";
                        flag=2;
                        break;
            }
            if(flag == 1)
                cout << "YES" << '\n';
        }
        //cout << "YES" << '\n';
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int q{0};
    cin >> q ;
    while(q--)
    {
        int n{0},clk{2},ant{2};
        cin >> n;
        vector<int> vec;
        for(int i{0};i<n;i++)
        {
            int p{0};
            cin >> p;
            vec.push_back(p);
        }
        int a=vec[0];
        if(vec[1]==vec[0]+1)
        {
            int i{0};
            for(int j{a};j<n;j++)
            {
                if(vec[i+1]!=vec[i]+1)
                {
                    cout << "NO" << '\n';
                    clk =1;
                    break;
                }
                i++;
            }
            //cout << i;
            if(i<vec.size()-1)
                i++;

            for(int j{1};j>(a-1);j++)
            {
                if(clk == 1 || i == vec.size()-1)
                    break;
                else if(vec[i+1]!=vec[i]+1)
                {
                    cout << "NO" << '\n';
                    clk =1;
                    break;
                }
            }
            if(clk==2)
                cout << "YES" << '\n';
        }
        else if(vec[1]==vec[0]-1 || vec[1]==n)
        {
            int i{0};
            for(int j{a};j>1;j--)
            {
                if(vec[i+1]!=vec[i]-1)
                {
                    cout << "NO" << '\n';
                    ant=1;
                    break;
                }
                i++;
            }
            //cout << i ;
            if(i<vec.size()-1)
                i++;

            for(int j{n};j>(a+1);j--)
            {
                if(ant == 1 || i == vec.size()-1)
                    break;
                else if(vec[i+1]!=vec[i]-1)
                {
                    cout << "NO" << '\n';
                    ant =1;
                    break;
                }
            }
            if(ant==2)
                cout << "YES" << '\n';
        }
        else
            cout << "NO" << '\n';

    }
    return 0;
}


    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int q{0};
        cin >> q;
        while(q--)
        {
            int n{0},m{0},flag{1},z{0};
            cin >> n;
            m=n;
            vector<int> vec;
            while(m--)
            {
                int p{0};
                cin >>p;
                vec.push_back(p);
                if(p==1)
                    z=vec.size()-1;
            }
            if(z==0&&vec[z+1]!=n)
            {
                for(int i{0};i<n-1;i++)
                {
                    if(vec[i+1]!=vec[i]+1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
            }
            else if(z==0&&vec[z+1]==n)
            {
                for(int i{z+1};i<n-1;i++)
                {
                    if(vec[i+1]!=vec[i]-1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
            }
            else if(vec[z+1]==n&&vec[z-1]==vec[z]+1)
            {
                for(int i{z+1};i<n-1;i++)
                {
                    if(vec[i+1]!=vec[i]-1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
                for(int i{z};i>0;i--)
                {
                    if(vec[i-1]!=vec[i]+1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
            }
            else if(vec[z+1]==vec[z]+1&&vec[z-1]==n)
            {
                for(int i{z};i<n-1;i++)
                {
                    if(vec[i+1]!=vec[i]+1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
                for(int i{z-1};i>0;i--)
                {
                    if(vec[i-1]!=vec[i]-1)
                    {
                        cout << "NO\n";
                        flag=2;
                        break;
                    }
                }
            }
            else
            {
                cout << "NO\n";
                        flag=2;
                        break;
            }
            if(flag == 1)
                cout << "YES" << '\n';
        }
        //cout << "YES" << '\n';
        return 0;
    }


    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int q{0};
        cin >> q;
        while(q--)
        {
            int n{0},m{0},z{0},flagc{2},flaga{2};
            cin >> n;
            m=n;
            vector<int> vec;
            while(m--)
            {
                int p{0};
                cin >>p;
                vec.push_back(p);
                if(p==1)
                    z=vec.size()-1;
            }

            for(int i{1} ; i<n ; i++)
            {
                if(vec[(z-i+n)%n]!=i+1)
                {
                    flagc=1;
                    break;
                }

            }
            for(int i{1} ; i<n ; i++)
            {
                if(vec[(z+i+n)%n]!=i+1)
                {
                    flaga=1;
                    break;
                }

            }
            if(flagc==2||flaga==2)
                cout << "YES\n";
            else
                cout << "NO\n";
        }
        //cout << "YES" << '\n';
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int q{0};
    cin >> q;
    while(q--)
    {
        int n{0},m{0},flag{1};
        cin >> n;
        m=n;
        vector<int> vec;
        while(m--)
        {
            int p{0};
            cin >>p;
            vec.push_back(p);

        }
        for(int i{1};i<vec.size();i++)
        {
            if(vec[1]==vec[0]+1&&vec[0]!=n)
            {
                //cout << "*******\n";
                if(vec[i]==n&&vec[i+1]!=1 && i+1<n)
                {
                    cout << "NO" << '\n';
                    flag = 2;
                    break;
                }
                else
                {
                    //cout << "*";
                    if(vec[i] != vec[i-1]+1 && vec[i-1]!=n)
                    {
                        cout << "NO" << '\n';
                        flag = 2;
                        break;
                    }
                }
            }
            else if(vec[n-1]==vec[0]+1 && vec[0]!=n)
            {
                if(vec[i]==1&&vec[i+1]!=n)
                {
                    cout << "NO" << '\n';
                    flag = 2;
                    break;
                }
                else
                {
                    if(vec[i] != vec[i-1]-1 && vec[i-1]!=1)
                    {
                        cout << "NO" << '\n';
                        flag = 2;
                        break;
                    }
                }
            }
            else if(vec[0]==n)
            {
                if(vec[i]!=vec[i-1]-1)
                {
                    cout << "NO" << '\n';
                    flag = 2;
                    break;
                }

            }
            else
            {
                cout << "NO" << '\n';
                flag = 2;
                break;
            }
        }
        if(flag == 1)
            cout << "YES" << '\n';
    }
    //cout << "YES" << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t-->0)
	{
		int n;
		cin>>n;
		vector<int> v,v1;
		int flag=0;
		int i,j;
		for(i=0;i<n;i++)
		{
			int x;
			cin>>x;
			if(flag==0)
			v.push_back(x);
			else
			v1.push_back(x);
			if(x==1)
			flag=1;
		}
		if(n==1 || n==2 || n==3)
		{
			cout<<"YES"<<endl;
			continue;
		}
		flag=0;
		if(v.size()==1)
		{
			int p=v1[0]-v1[1];
			if(p==1 || p==-1) {
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
				flag=1;
				break;
			    }
			}
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else if(v1.size()==0)
		{
			int p=v[0]-v[1];
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(v[v.size()-2]!=2 && v[v.size()-2]!=n)
			flag=1;
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else
		{
			int p;
			if(v[1]!=1)
			p=v[0]-v[1];
			else
			{
				if(v.size()==2 && v1.size()==1)
				p=v[1]-v1[0];
				else
				p=v1[0]-v1[1];
			}
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t-->0)
	{
		int n;
		cin>>n;
		vector<int> v,v1;
		int flag=0;
		int i,j;
		for(i=0;i<n;i++)
		{
			int x;
			cin>>x;
			if(flag==0)
			v.push_back(x);
			else
			v1.push_back(x);
			if(x==1)
			flag=1;
		}
		if(n==1)
		{
			cout<<"YES"<<endl;
			continue;
		}
		flag=0;
		if(v.size()==1)
		{
			int p=v1[0]-v1[1];
			if(p==1 || p==-1) {
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
				flag=1;
				break;
			    }
			}
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else if(v1.size()==0)
		{
			int p=v[0]-v[1];
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(v.size()-2!=2 || v.size()-2!=n)
			flag=1;
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else
		{
			int p;
			if(v[1]!=1)
			p=v[0]-v[1];
			else
			{
				if(v.size()==2 && v1.size()==1)
				p=v[1]-v1[0];
				else
				p=v1[0]-v1[1];
			}
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
bool checkClockwise(int a[], int index, int n) {
	int i=index;
	while((i+1)%n!=index)
	{
		if(a[i%n]+1!=a[(i+1)%n])
		return false;
		i=(i+1)%n;
	}
	return true;
}
bool checkAntiClockwise(int a[], int index, int n) {
	int i=index;
	while((i-1>=0?i-1:n-1)!=index)
	{
		if(a[i]+1!=(i-1>=0?a[i-1]:a[n-1]))
		return false;
		i=i-1;
		if(i<0)
		i=n-1;
	}
	return true;
}
int main()
{
	int t;
	cin>>t;
	while(t-->0)
	{
		int n;
		cin>>n;
		int a[n];
		int i,index;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			if(a[i]==1)
			index=i;
		}
		if(checkClockwise(a,index,n) || checkAntiClockwise(a,index,n))
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t-->0)
	{
		int n;
		cin>>n;
		int a[n];
		int i,index=-1;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			if(a[i]==1)
			index=i;
		}
		if(n==1)
		{
			cout<<"YES"<<endl;
			continue;
		}
		int flag=0;
		if(index<=n-3)
		{
			if(a[index+1]-a[index+2]==1)
			flag=1;
			else if(a[index+1]-a[index+2]==-1)
			flag=0;
			else
			{
			cout<<"NO"<<endl;
			continue;
		    }
		}
		else
		{
			if(a[0]-a[1]==1)
			flag=1;
			else if(a[0]-a[1]==-1)
			flag=0;
			else
			{
			cout<<"NO"<<endl;
			continue;
		    }
		}
		if(flag==0)
		{
			int flag1=0;
			for(i=0;i<index-1;i++)
			{
				if(a[i]-a[i+1]!=-1)
				{
					flag1=1;
					break;
				}
			}
			for(i=index+1;i<n-1;i++)
			{
				if(a[i]-a[i+1]!=-1)
				{
					flag1=1;
					break;
				}
			}
			if(flag1==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		}
		else
		{
			int flag1=0;
			for(i=0;i<index-1;i++)
			{
				if(a[i]-a[i+1]!=1)
				{
					flag1=1;
					break;
				}
			}
			for(i=index+1;i<n-1;i++)
			{
				if(a[i]-a[i+1]!=1)
				{
					flag1=1;
					break;
				}
			}
			if(flag1==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t-->0)
	{
		int n;
		cin>>n;
		vector<int> v,v1;
		int flag=0;
		int i,j;
		for(i=0;i<n;i++)
		{
			int x;
			cin>>x;
			if(flag==0)
			v.push_back(x);
			else
			v1.push_back(x);
			if(x==1)
			flag=1;
		}
		if(n==1 || n==2 || n==3)
		{
			cout<<"YES"<<endl;
			continue;
		}
		flag=0;
		if(v.size()==1)
		{
			int p=v1[0]-v1[1];
			if(p==1 || p==-1) {
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
				flag=1;
				break;
			    }
			}
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else if(v1.size()==0)
		{
			int p=v[0]-v[1];
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(v[v.size()-2]!=2 && v[v.size()-2]!=n)
			flag=1;
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else
		{
			int p;
			if(v[1]!=1)
			p=v[0]-v[1];
			else
			{
				if(v.size()==2 && v1.size()==1)
				p=v[1]-v1[0];
				else
				p=v1[0]-v1[1];
			}
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(v[1]==1)
			{
				if(v1[0]!=2 || v1[0]!=n)
				flag=1;
			}
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t-->0)
	{
		int n;
		cin>>n;
		vector<int> v,v1;
		int flag=0;
		int i,j;
		for(i=0;i<n;i++)
		{
			int x;
			cin>>x;
			if(flag==0)
			v.push_back(x);
			else
			v1.push_back(x);
			if(x==1)
			flag=1;
		}
		if(n==1 || n==2 || n==3)
		{
			cout<<"YES"<<endl;
			continue;
		}
		flag=0;
		if(v.size()==1)
		{
			int p=v1[0]-v1[1];
			if(p==1 || p==-1) {
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
				flag=1;
				break;
			    }
			}
			if(v1[0]!=2 && v1[0]!=n)
			flag=1;
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else if(v1.size()==0)
		{
			int p=v[0]-v[1];
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else
		{
			int p;
			if(v[1]!=1)
			p=v[0]-v[1];
			else
			{
				if(v.size()==2 && v1.size()==1)
				p=v[1]-v1[0];
				else
				p=v1[0]-v1[1];
			}
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(v1[0]!=2 && v1[0]!=n)
			flag=1;
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t-->0)
	{
		int n;
		cin>>n;
		vector<int> v,v1;
		int flag=0;
		int i,j;
		for(i=0;i<n;i++)
		{
			int x;
			cin>>x;
			if(flag==0)
			v.push_back(x);
			else
			v1.push_back(x);
			if(x==1)
			flag=1;
		}
		if(n==1 || n==2 || n==3)
		{
			cout<<"YES"<<endl;
			continue;
		}
		flag=0;
		if(v.size()==1)
		{
			int p=v1[0]-v1[1];
			if(p==1 || p==-1) {
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
				flag=1;
				break;
			    }
			}
			if(v1[0]!=2 || v1[0]!=n)
			flag=1;
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else if(v1.size()==0)
		{
			int p=v[0]-v[1];
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(v[v.size()-2]!=2 && v[v.size()-2]!=n)
			flag=1;
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else
		{
			int p;
			if(v[1]!=1)
			p=v[0]-v[1];
			else
			{
				if(v.size()==2 && v1.size()==1)
				p=v[1]-v1[0];
				else
				p=v1[0]-v1[1];
			}
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(v1[0]!=2 || v1[0]!=n)
			flag=1;
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t-->0)
	{
		int n;
		cin>>n;
		vector<int> v,v1;
		int flag=0;
		int i,j;
		for(i=0;i<n;i++)
		{
			int x;
			cin>>x;
			if(flag==0)
			v.push_back(x);
			else
			v1.push_back(x);
			if(x==1)
			flag=1;
		}
		if(n==1 || n==2 || n==3)
		{
			cout<<"YES"<<endl;
			continue;
		}
		flag=0;
		if(v.size()==1)
		{
			int p=v1[0]-v1[1];
			if(p==1 || p==-1) {
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
				flag=1;
				break;
			    }
			}
			if(v1[0]!=2 && v1[0]!=n)
			flag=1;
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else if(v1.size()==0)
		{
			int p=v[0]-v[1];
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(v[v.size()-2]!=2 && v[v.size()-2]!=n)
			flag=1;
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
		else
		{
			int p;
			if(v[1]!=1)
			p=v[0]-v[1];
			else
			{
				if(v.size()==2 && v1.size()==1)
				p=v[1]-v1[0];
				else
				p=v1[0]-v1[1];
			}
			if(p==1 || p==-1) {
			for(i=0;i<v.size()-2;i++)
			{
				if(v[i]-v[i+1]!=p) {
					flag=1;
					break;
				}
			}
			for(i=0;i<v1.size()-1;i++)
			{
				if(v1[i]-v1[i+1]!=p) {
					flag=1;
					break;
				}
			}
			if(v1[0]!=2 && v1[0]!=n)
			flag=1;
			if(flag==0)
			cout<<"YES"<<endl;
			else
			cout<<"NO"<<endl;
		    }
		    else
		    cout<<"NO"<<endl;
		}
	}
}


    #include <bits/stdc++.h>
    using namespace std;
    #define NIL -1
    #define MAX 100
    #define ll long long
    #define dd double
    #define cazz ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define mod (ll)(998244353)
    #define tc(t) int t;cin >>t;while(t--)
    #define pb(i) push_back(i)
    #define rr return 0
    int main (){
        cazz
        tc(t){
            ll n;
            cin>>n;
            ll a[n];
            ll p=0,cnt=0,cnt1=0,flag=0,mvp=0;
            for(ll i=0;i<n;i++)cin>>a[i];
            ll k=*min_element (a,a+n);
            for(ll i=0;i<n;i++){
                if(a[i]==k)p=i;
            }
            for(ll i=p;i<p+n-1;i++){
                if(a[i%n]<a[(i%n)+1]){
                    cnt++;
                    if(cnt==n-1){
                        flag=1;
                        mvp=1;
                        cout<<"YES"<<endl;
                        break;
                    }
                }
            }
            if(flag==0){
                for(ll i=p;i>p-n;i--){
                if(a[abs(i)%n]<a[abs(i-n+1)%n]){
                    cnt1++;
                    if(cnt1==n-1){
                        mvp=1;
                        cout<<"YES"<<endl;
                        break;
                    }
                }
            }
            }
            if(n==1)cout<<"YES"<<endl;
            else if(mvp==0)cout<<"NO"<<endl;
            //cout<<k;
        }
    }


#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 100
#define ll long long
#define dd double
#define cazz ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (ll)(998244353)
#define tc(t) int t;cin >>t;while(t--)
#define pb(i) push_back(i)
#define rr return 0
int main (){
    cazz
    tc(t){
        ll n;
        cin>>n;
        ll a[n];
        ll b[n];
        ll c[n];
        ll flag=0;
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        ll cnt=0,cnt1=0;
        ll k=*max_element (a,a+n);
        for(ll i=1;i<n;i++){
            if((a[i]>a[i-1]) or a[i]==k )cnt++;
        }
        for(ll i=1;i<n;i++){
            if((a[i]<a[i-1]) or a[i]==k )cnt1++;
        }
        if(cnt==n-1 or cnt1==n-1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


    #include <bits/stdc++.h>
    using namespace std;
    #define NIL -1
    #define MAX 100
    #define ll long long
    #define dd double
    #define cazz ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define mod (ll)(998244353)
    #define tc(t) int t;cin >>t;while(t--)
    #define pb(i) push_back(i)
    #define rr return 0
    int main (){
        cazz
        tc(t){
            ll n;
            cin>>n;
            ll a[n];
            ll b[n];
            ll c[n];
            ll flag=0;
            for(ll i=0;i<n;i++){
                cin>>a[i];
            }
            ll cnt=0,cnt1=0;
            ll k=*max_element (a,a+n);
            for(ll i=1;i<n;i++){
                if((a[i]>a[i-1]) or a[i]==k or (a[i]<a[i-1] && a[i]<a[0])){
                    cnt++;
                    if(cnt==n-1){
                        flag=1;
                        cout<<"YES"<<endl;
                        break;
                    }
                }
            }
            if(flag==0){
            for(ll i=1;i<n;i++){
                if((a[i]<a[i-1]) or a[i]==k or (a[i]>a[i-1] && a[i]<a[0])){
                cnt1++;
                if(cnt1==n-1){
                    flag=1;
                    cout<<"YES"<<endl;
                    break;
                }
            }
            }
            }
            if(n==1)cout<<"YES"<<endl;
            else if(flag==0)cout<<"NO"<<endl;
            //else cout<<"NO"<<endl;
        }
    }


#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 100
#define ll long long
#define dd double
#define cazz ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (ll)(998244353)
#define tc(t) int t;cin >>t;while(t--)
#define pb(i) push_back(i)
#define rr return 0
int main (){
    cazz
    tc(t){
        ll n;
        cin>>n;
        ll A[n];
        for(int i=0;i<n;i++)cin>>A[i];
        ll cnt=0;
        ll a=0;
        for(int i=0;i<n;i++){
            if(A[i]==1){
                a=i;
                break;
            }
        }
        for(int i=a;i<a+n-1;i++){
            if(A[(i)%n]>A[(i+1)%n]){
                cnt=1;
                break;
            }
        }
        if(cnt==0)cout<<"YES\n";
        else{
            cnt=0;
            for(int i=0;i<n-1;i++){
                if(A[(n+a-i-1)%n]<A[(n+a-i)%n]){
                    cnt=1;
                    break;
                }
            }
            if(cnt==0)cout<<"YES\n";
            else cout<<"NO\n";
        }
    }
    rr;
}


#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 100
#define ll long long
#define dd double
#define cazz ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (ll)(998244353)
#define tc(t) int t;cin >>t;while(t--)
#define pb(i) push_back(i)
#define rr return 0
int main (){
    cazz
    tc(t){
        ll n;
        cin>>n;
        ll a[n];
        ll b[n];
        ll c[n];
        ll flag=0;
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        ll cnt=0,cnt1=0;
        ll k=*max_element (a,a+n);
        for(ll i=1;i<n;i++){
            if((a[i]>a[i-1]) or a[i]==k or (a[i]<a[i-1] && a[i]<a[0]))cnt++;
        }
        for(ll i=1;i<n;i++){
            if((a[i]<a[i-1]) or a[i]==k or (a[i]>a[i-1] && a[i]<a[0]))cnt1++;
        }
        if(cnt==n-1 or cnt1==n-1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 100
#define ll long long
#define dd double
#define cazz ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (ll)(998244353)
#define tc(t) int t;cin >>t;while(t--)
#define pb(i) push_back(i)
#define rr return 0
int main (){
    cazz
    tc(t){
        ll n;
        cin>>n;
        ll a[n];
        ll b[n];
        ll c[n];
        ll flag=0;
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        ll cnt=0,cnt1=0;
        ll k=*max_element (a,a+n);
        for(ll i=1;i<n;i++){
            if((a[i]==a[i-1]+1) or a[i]==k )cnt++;
        }
        for(ll i=1;i<n;i++){
            if((a[i]==a[i-1]-1) or a[i]==k )cnt1++;
        }
        if(cnt==n-1 or cnt1==n-1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std ;

void swap(int *a ,int *b){
	int temp=*a ;
	*a=*b ;
	*b=temp ;
}

string mi(string s ,string t){
    if(s.size()>t.size()){
        return t ;
    }else if(s.size()<t.size()){
        return s ;
    }else {
        if(s.compare(t)>=0){
            return t ;
        }else
        return s ;
    }
}

int isprime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
void pairsort(int a[], int b[], int n){
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll fact(ll a){
    ll p=1 ;

    for(int i=1;i<=a;i++)
        p*=i ;

    return p ;
}
string findsum(string str1, string str2)
{
    // Before proceeding further, make sure length
    // of str2 is larger.
    if (str1.length() > str2.length())
        swap(str1, str2);

    // Take an empty string for storing result
    string str = "";

    // Calculate length of both string
    int n1 = str1.length(), n2 = str2.length();
    int diff = n2 - n1;

    // Initially take carry zero
    int carry = 0;

    // Traverse from end of both strings
    for (int i=n1-1; i>=0; i--)
    {
        // Do school mathematics, compute sum of
        // current digits and carry
        int sum = ((str1[i]-'0') +
                   (str2[i+diff]-'0') +
                   carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining digits of str2[]
    for (int i=n2-n1-1; i>=0; i--)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)
        str.push_back(carry+'0');

    // reverse resultant string
    reverse(str.begin(), str.end());

    return str;
}
long long bw(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

vector <int> decToBinary(int n)
{   vector <int> v ;

    for (int i = 31; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            v.push_back((int)pow(2,i)) ;
    }

    return v ;
}

int bs(int a[],int  n,int x){
    int l=0 ;
    int r=n-1 ;
    int mid=(l+r)/2 ;
    while(l<=r){
         mid=l+(r-l)/2 ;

        if(a[mid]==x)
         l =mid+1 ;

        else if(a[mid]>x){
            r=mid-1 ;
        }else
        l=mid+1 ;
    }

    return mid ;
}

int main()
{    IOS ;

    int q ;
    cin>>q ;

    while(q--){
      int n ;
      cin>>n ;

      int a[n] ;

      for(int i=0;i<n;i++){
          cin>>a[i] ;
      }

      if(n==1){
          cout<<"YES"<<endl ;
          continue ;
      }

      int c=a[1]-a[0] ;

      int flag=0 ,flag2=0 ;
      if(fabs(a[1]-a[0])>1){
         c= a[2]-a[1] ;
         if(a[0]!=1 && a[1]!=1 || flag2)
          flag=1 ;

          flag2=1 ;
      }

      for(int i=2;i<n;i++){
          if(fabs(a[i]-a[i-1])>1){
              if(a[i]!=1 && a[i-1]!=1 || flag2)
                  flag=1 ;
             flag2=1 ;
              continue ;
          }
          else
           if(a[i]-a[i-1]!=c){
               flag=1 ;
               break ;
           }
      }

      if(flag)
        cout<<"NO"<<endl ;
      else
       cout<<"YES"<<endl ;
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std ;

void swap(int *a ,int *b){
	int temp=*a ;
	*a=*b ;
	*b=temp ;
}

string mi(string s ,string t){
    if(s.size()>t.size()){
        return t ;
    }else if(s.size()<t.size()){
        return s ;
    }else {
        if(s.compare(t)>=0){
            return t ;
        }else
        return s ;
    }
}

int isprime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
void pairsort(int a[], int b[], int n){
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll fact(ll a){
    ll p=1 ;

    for(int i=1;i<=a;i++)
        p*=i ;

    return p ;
}
string findsum(string str1, string str2)
{
    // Before proceeding further, make sure length
    // of str2 is larger.
    if (str1.length() > str2.length())
        swap(str1, str2);

    // Take an empty string for storing result
    string str = "";

    // Calculate length of both string
    int n1 = str1.length(), n2 = str2.length();
    int diff = n2 - n1;

    // Initially take carry zero
    int carry = 0;

    // Traverse from end of both strings
    for (int i=n1-1; i>=0; i--)
    {
        // Do school mathematics, compute sum of
        // current digits and carry
        int sum = ((str1[i]-'0') +
                   (str2[i+diff]-'0') +
                   carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining digits of str2[]
    for (int i=n2-n1-1; i>=0; i--)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)
        str.push_back(carry+'0');

    // reverse resultant string
    reverse(str.begin(), str.end());

    return str;
}
long long bw(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

vector <int> decToBinary(int n)
{   vector <int> v ;

    for (int i = 31; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            v.push_back((int)pow(2,i)) ;
    }

    return v ;
}

int bs(int a[],int  n,int x){
    int l=0 ;
    int r=n-1 ;
    int mid=(l+r)/2 ;
    while(l<=r){
         mid=l+(r-l)/2 ;

        if(a[mid]==x)
         l =mid+1 ;

        else if(a[mid]>x){
            r=mid-1 ;
        }else
        l=mid+1 ;
    }

    return mid ;
}

int main()
{    IOS ;

    int q ;
    cin>>q ;

    while(q--){
      int n ;
      cin>>n ;

      int a[n] ;

      for(int i=0;i<n;i++){
          cin>>a[i] ;
      }

      if(n==1){
          cout<<"YES"<<endl ;
          continue ;
      }

      int c=a[1]-a[0] ;

      int flag=0 ;
      if(fabs(a[1]-a[0])>1){
         c= a[2]-a[1] ;
         if(a[0]!=1 && a[1]!=1)
          flag=1 ;
      }

      for(int i=1;i<n;i++){
          if(fabs(a[i]-a[i-1])>1){
              if(a[i]!=1 && a[i-1]!=1)
                  flag=1 ;
              continue ;
          }
          else
           if(a[i]-a[i-1]!=c){
               flag=1 ;
               break ;
           }
      }

      if(flag)
        cout<<"NO"<<endl ;
      else
       cout<<"YES"<<endl ;
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std ;

void swap(int *a ,int *b){
	int temp=*a ;
	*a=*b ;
	*b=temp ;
}

string mi(string s ,string t){
    if(s.size()>t.size()){
        return t ;
    }else if(s.size()<t.size()){
        return s ;
    }else {
        if(s.compare(t)>=0){
            return t ;
        }else
        return s ;
    }
}

int isprime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
void pairsort(int a[], int b[], int n){
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll fact(ll a){
    ll p=1 ;

    for(int i=1;i<=a;i++)
        p*=i ;

    return p ;
}
string findsum(string str1, string str2)
{
    // Before proceeding further, make sure length
    // of str2 is larger.
    if (str1.length() > str2.length())
        swap(str1, str2);

    // Take an empty string for storing result
    string str = "";

    // Calculate length of both string
    int n1 = str1.length(), n2 = str2.length();
    int diff = n2 - n1;

    // Initially take carry zero
    int carry = 0;

    // Traverse from end of both strings
    for (int i=n1-1; i>=0; i--)
    {
        // Do school mathematics, compute sum of
        // current digits and carry
        int sum = ((str1[i]-'0') +
                   (str2[i+diff]-'0') +
                   carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining digits of str2[]
    for (int i=n2-n1-1; i>=0; i--)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)
        str.push_back(carry+'0');

    // reverse resultant string
    reverse(str.begin(), str.end());

    return str;
}
long long bw(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

vector <int> decToBinary(int n)
{   vector <int> v ;

    for (int i = 31; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            v.push_back((int)pow(2,i)) ;
    }

    return v ;
}

int bs(int a[],int  n,int x){
    int l=0 ;
    int r=n-1 ;
    int mid=(l+r)/2 ;
    while(l<=r){
         mid=l+(r-l)/2 ;

        if(a[mid]==x)
         l =mid+1 ;

        else if(a[mid]>x){
            r=mid-1 ;
        }else
        l=mid+1 ;
    }

    return mid ;
}

int main()
{    IOS ;

    int q ;
    cin>>q ;

    while(q--){
      int n ;
      cin>>n ;

      int a[n] ;

      for(int i=0;i<n;i++){
          cin>>a[i] ;
      }

      if(n==1){
          cout<<"YES"<<endl ;
          continue ;
      }

      int c=a[1]-a[0] ;

      int flag=0 ,flag2=0 ;
      if(fabs(a[1]-a[0])>1){
         c= a[2]-a[1] ;
         if(a[0]!=1 && a[1]!=1 || flag2)
          flag=1 ;

          flag2=1 ;
      }

      for(int i=1;i<n;i++){
          if(fabs(a[i]-a[i-1])>1){
              if(a[i]!=1 && a[i-1]!=1 || flag2)
                  flag=1 ;
             flag2=1 ;
              continue ;
          }
          else
           if(a[i]-a[i-1]!=c){
               flag=1 ;
               break ;
           }
      }

      if(flag)
        cout<<"NO"<<endl ;
      else
       cout<<"YES"<<endl ;
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std ;

void swap(int *a ,int *b){
	int temp=*a ;
	*a=*b ;
	*b=temp ;
}

string mi(string s ,string t){
    if(s.size()>t.size()){
        return t ;
    }else if(s.size()<t.size()){
        return s ;
    }else {
        if(s.compare(t)>=0){
            return t ;
        }else
        return s ;
    }
}

int isprime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
void pairsort(int a[], int b[], int n){
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll fact(ll a){
    ll p=1 ;

    for(int i=1;i<=a;i++)
        p*=i ;

    return p ;
}
string findsum(string str1, string str2)
{
    // Before proceeding further, make sure length
    // of str2 is larger.
    if (str1.length() > str2.length())
        swap(str1, str2);

    // Take an empty string for storing result
    string str = "";

    // Calculate length of both string
    int n1 = str1.length(), n2 = str2.length();
    int diff = n2 - n1;

    // Initially take carry zero
    int carry = 0;

    // Traverse from end of both strings
    for (int i=n1-1; i>=0; i--)
    {
        // Do school mathematics, compute sum of
        // current digits and carry
        int sum = ((str1[i]-'0') +
                   (str2[i+diff]-'0') +
                   carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining digits of str2[]
    for (int i=n2-n1-1; i>=0; i--)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)
        str.push_back(carry+'0');

    // reverse resultant string
    reverse(str.begin(), str.end());

    return str;
}
long long bw(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

vector <int> decToBinary(int n)
{   vector <int> v ;

    for (int i = 31; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            v.push_back((int)pow(2,i)) ;
    }

    return v ;
}

int bs(int a[],int  n,int x){
    int l=0 ;
    int r=n-1 ;
    int mid=(l+r)/2 ;
    while(l<=r){
         mid=l+(r-l)/2 ;

        if(a[mid]==x)
         l =mid+1 ;

        else if(a[mid]>x){
            r=mid-1 ;
        }else
        l=mid+1 ;
    }

    return mid ;
}

int main()
{    IOS ;

    int q ;
    cin>>q ;

    while(q--){
      int n ;
      cin>>n ;

      int a[n] ;

      for(int i=0;i<n;i++){
          cin>>a[i] ;
      }

      int c=a[1]-a[0] ;

      if(fabs(a[1]-a[0])>1){
         c= a[2]-a[1] ;
      }

      int flag=0 ;

      for(int i=1;i<n;i++){
          if(fabs(a[i]-a[i-1])>1)
           continue ;
           else
           if(a[i]-a[i-1]!=c){
               flag=1 ;
               break ;
           }
      }

      if(flag)
        cout<<"NO"<<endl ;
      else
       cout<<"YES"<<endl ;
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std ;

void swap(int *a ,int *b){
	int temp=*a ;
	*a=*b ;
	*b=temp ;
}

string mi(string s ,string t){
    if(s.size()>t.size()){
        return t ;
    }else if(s.size()<t.size()){
        return s ;
    }else {
        if(s.compare(t)>=0){
            return t ;
        }else
        return s ;
    }
}

int isprime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
void pairsort(int a[], int b[], int n){
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll fact(ll a){
    ll p=1 ;

    for(int i=1;i<=a;i++)
        p*=i ;

    return p ;
}
string findsum(string str1, string str2)
{
    // Before proceeding further, make sure length
    // of str2 is larger.
    if (str1.length() > str2.length())
        swap(str1, str2);

    // Take an empty string for storing result
    string str = "";

    // Calculate length of both string
    int n1 = str1.length(), n2 = str2.length();
    int diff = n2 - n1;

    // Initially take carry zero
    int carry = 0;

    // Traverse from end of both strings
    for (int i=n1-1; i>=0; i--)
    {
        // Do school mathematics, compute sum of
        // current digits and carry
        int sum = ((str1[i]-'0') +
                   (str2[i+diff]-'0') +
                   carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining digits of str2[]
    for (int i=n2-n1-1; i>=0; i--)
    {
        int sum = ((str2[i]-'0')+carry);
        str.push_back(sum%10 + '0');
        carry = sum/10;
    }

    // Add remaining carry
    if (carry)
        str.push_back(carry+'0');

    // reverse resultant string
    reverse(str.begin(), str.end());

    return str;
}
long long bw(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

vector <int> decToBinary(int n)
{   vector <int> v ;

    for (int i = 31; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            v.push_back((int)pow(2,i)) ;
    }

    return v ;
}

int bs(int a[],int  n,int x){
    int l=0 ;
    int r=n-1 ;
    int mid=(l+r)/2 ;
    while(l<=r){
         mid=l+(r-l)/2 ;

        if(a[mid]==x)
         l =mid+1 ;

        else if(a[mid]>x){
            r=mid-1 ;
        }else
        l=mid+1 ;
    }

    return mid ;
}

int main()
{    IOS ;

    int q ;
    cin>>q ;

    while(q--){
      int n ;
      cin>>n ;

      int a[n] ;

      for(int i=0;i<n;i++){
          cin>>a[i] ;
      }

      if(n==1){
          cout<<"YES" ;
          continue ;
      }

      int c=a[1]-a[0] ;

      int flag=0 ;
      if(fabs(a[1]-a[0])>1){
         c= a[2]-a[1] ;
         if(a[0]!=1 && a[1]!=1)
          flag=1 ;
      }

      for(int i=1;i<n;i++){
          if(fabs(a[i]-a[i-1])>1){
              if(a[i]!=1 && a[i-1]!=1)
                  flag=1 ;
              continue ;
          }
          else
           if(a[i]-a[i-1]!=c){
               flag=1 ;
               break ;
           }
      }

      if(flag)
        cout<<"NO"<<endl ;
      else
       cout<<"YES"<<endl ;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int j=0;j<n;j++)
    {
        int m;
        cin>>m;
        int a[m],idx,f=0;
        for(int i=0; i<m; i++)
        {
            cin>>a[i];
            if(a[i]==1)idx=i;
        }
        if(idx==0)
        {
            if(a[m-1]==2)
            {
                for(int i=m-1;i>1;i--)
                {
                    if(a[i-1]-a[i]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
            else
            {
                for(int i=1;i<m;i++)
                {
                    if(a[i]-a[i-1]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
        }
        else if(idx==m-1)
        {
            if(a[m-2]==2)
            {
                for(int i=m-2;i>0;i--)
                {
                    if(a[i-1]-a[i]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
            else
            {
                for(int i=1;i<m-1;i++)
                {
                    if(a[i]-a[i-1]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
        }
        else
        {
            if(a[idx+1]==2)
            {
                for(int i=idx+1;;i++)
                {
                    int x=i%m;
                    int y=i-1;
                    if(y<0)y+=m;
                    if(a[x]==idx)break;
                    if(a[x]-a[y]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
            else
            {
                for(int i=idx-1;;i--)
                {
                    int x=i;
                    int y=i+1;
                    if(x<0)x+=m;
                    if(y<0)y+=m;
                    //cout<<x<<' '<<y<<endl;
                    if(x==idx)break;
                    if(a[x]-a[y]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
        }
        if(f)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
        int n;
        cin>>n;
        int a[n],idx,f=0;
        for(int i=0; i<n; i++)
        {
            cin>>a[i];
            if(a[i]==1)idx=i;
        }
        for(int i=0; i<n; i++)
        {
            int x=idx+i;
            x%=n;
          //  cout<<x<<' '<<a[x]<<' '<<i+1<<endl;
            if(a[x]!=i+1)
            {
                f=1;
                break;
            }
        }
        if(f)
        {
            f=0;
            for(int i=0; i<n; i++)
            {
                int x=idx-i;
                if(x<0)x+=n;
         //   cout<<x<<' '<<a[x]<<' '<<i<<endl;
                if(a[x]!=i+1)
                {
                    f=1;
                    break;
                }
            }
        }
        if(f)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int j=0;j<n;j++)
    {
        int m;
        cin>>m;
        int a[m],idx,f=0;
        for(int i=0; i<m; i++)
        {
            cin>>a[i];
            if(a[i]==1)idx=i;
        }
        if(idx==0)
        {
            if(a[m-1]==2)
            {
                for(int i=m-1;i>1;i--)
                {
                    if(a[i-1]-a[i]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
            else
            {
                for(int i=1;i<m;i++)
                {
                    if(a[i]-a[i-1]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
        }
        else if(idx==m-1)
        {
            if(a[m-2]==2)
            {
                for(int i=m-2;i>0;i--)
                {
                    if(a[i-1]-a[i]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
            else
            {
                for(int i=1;i<m-1;i++)
                {
                    if(a[i]-a[i-1]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
        }
        else
        {
            if(a[idx+1]==2)
            {
                for(int i=idx+1;;i++)
                {
                    int x=i%m;
                    int y=i-1;
                    if(y<=0)y+=m;
                    if(a[x]==idx)break;
                    if(a[x]-a[y]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
            else
            {
                for(int i=idx-1;;idx--)
                {
                    int x=i;
                    int y=i+1;
                    if(x<=0)x+=m;
                    if(y<=0)y+=m;
                    if(x==idx)break;
                    if(a[x]-a[y]!=1)
                    {
                        f=1;
                        break;
                    }
                }
            }
        }
        if(f)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}


/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------O_v_T-------         |
  |_______________10_________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mem(a , v)  memset(a , v , sizeof(a))
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s" , &a)
#define scc(a) scanf("%c" , &a)
#define blank printf("\n")
#define pla printf("plapla\n")
#define pb push_back
#define fo(j,n,t)     for(int i=j;i<n;i+=t)
#define fod(j,n,t)     for(int i=j;i>=n;i-=t)
#define f first
#define s second
const ull MAX = 1e5+55;
const int inf = 1e9+77;
const int MOD = 1e9+7;
const double eps = 1e-7;
map<char,int>mp;
vector<int>v;
set<ll>cc;
pair<int ,int>pi;
int x[MAX];
int y[MAX];
char c[MAX];
/*int Binary(int num)
{
      int bin;

    while (num > 0)

    {

        bin = num % 2;

        cout << bin;

        num /= 2;

    }
}*/
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q;
cin>>q;
while(q--)
{ // begin q

   memset(x,0,sizeof x);
   v.clear();
   int n;
   cin>>n;
   for(int i=0;i<n;i++){
        cin>>x[i];
        v.pb(x[i]);
   }

   /////////////////////////
   bool t=1;
   int j=1;
   for(int i=1;i<n;i++)
   {

    if(x[i]>x[i-1]){
      t=true;
    }
    else if( x[i]>=j &&x[i]<=x[0] ){
      t=true;
      j=x[i];
    }

   else
   {
       t=false;
       break;
   }

}

if(t)
    cout<<"YES"<<endl;
///////////////////
else
{
    reverse(v.begin(),v.end());
   bool r=1;
   int p=1;
   for(int i=1;i<n;i++)
   {

    if(v[i]>v[i-1] ){
      r=true;
    }
    else if(v[i]>=p &&v[i]<=v[0] ){
      r=true;
      p=v[i];
    }

   else
   {
       r=false;
       break;
   }

}

if(r)
    cout<<"YES"<<endl;
else
    cout<<"NO"<<endl;

}// end else

}// end

//cout<<fixed<<setprecision(14)<<A;
return 0;
}


/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------O_v_T-------         |
  |_______________10_________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mem(a , v)  memset(a , v , sizeof(a))
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s" , &a)
#define scc(a) scanf("%c" , &a)
#define blank printf("\n")
#define pla printf("plapla\n")
#define pb push_back
#define fo(j,n,t)     for(int i=j;i<n;i+=t)
#define fod(j,n,t)     for(int i=j;i>=n;i-=t)
#define f first
#define s second
const ull MAX = 1e5+55;
const int inf = 1e9+77;
const int MOD = 1e9+7;
const double eps = 1e-7;
map<char,int>mp;
vector<int>v;
set<ll>cc;
pair<int ,int>pi;
int x[MAX];
int y[MAX];
char c[MAX];
/*int Binary(int num)
{
      int bin;

    while (num > 0)

    {

        bin = num % 2;

        cout << bin;

        num /= 2;

    }
}*/
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q;
cin>>q;
while(q--)
{ // begin q

   memset(x,0,sizeof x);
   v.clear();
   int n;
   cin>>n;
   for(int i=0;i<n;i++){
        cin>>x[i];
        v.pb(x[i]);
   }

   /////////////////////////
   bool t=1;
   int j=1;
   int num=0;
   for(int i=1;i<n;i++)
   {

    if(x[i]>x[i-1] && num==0){
      t=true;
    }
    else if( x[i]>=j &&x[i]<=x[0] ){
            num++;
      t=true;
      j=x[i];
    }

   else
   {
       t=false;
       break;
   }

}

if(t)
    cout<<"YES"<<endl;
///////////////////
else
{
    reverse(v.begin(),v.end());
   bool r=1;
   int p=1;
   int sum=0;
   for(int i=1;i<n;i++)
   {

    if(v[i]>v[i-1] &&sum==0){
      r=true;
    }
    else if(v[i]>=p &&v[i]<=v[0] ){

sum++;
      r=true;
      p=v[i];
    }

   else
   {
       r=false;
       break;
   }

}

if(r)
    cout<<"YES"<<endl;
else
    cout<<"NO"<<endl;

}// end else

}// end

//cout<<fixed<<setprecision(14)<<A;
return 0;
}


/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------O_v_T-------         |
  |_______________10_________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mem(a , v)  memset(a , v , sizeof(a))
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s" , &a)
#define scc(a) scanf("%c" , &a)
#define blank printf("\n")
#define pla printf("plapla\n")
#define pb push_back
#define fo(j,n,t)     for(int i=j;i<n;i+=t)
#define fod(j,n,t)     for(int i=j;i>=n;i-=t)
#define f first
#define s second
const ull MAX = 1e5+55;
const int inf = 1e9+77;
const int MOD = 1e9+7;
const double eps = 1e-7;
map<char,int>mp;
vector<int>v;
set<ll>cc;
pair<int ,int>pi;

int y[MAX];
char c[MAX];
/*int Binary(int num)
{
      int bin;

    while (num > 0)

    {

        bin = num % 2;

        cout << bin;

        num /= 2;

    }
}*/
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q;
cin>>q;
while(q--)
{

    int n;
    cin>>n;
    int x[n+4];
    int sum=0;
    int j=0;
    for(int i=0;i<n;i++)
        cin>>x[i];

    bool t=1;
    for(int i=0;i<n-1;i++)
        if(x[i]<x[i+1] && x[i+1]-x[i]==1)
            continue;
        else{
            t=0;
            break;
        }
        if(t)
            cout<<"YES"<<endl;
        else
        {

            bool r=1;
           for(int i=0;i<n-1;i++)
                if(x[i]>x[i+1] && x[i]-x[i+1]==1)
                  r=1;
                 else{
                    j=i+1;
                    r=0;

                    break;}
            for(int i=j;i<n-1;i++)
                if(x[i]>x[i+1]&& x[i]-x[i+1]==1)
                 r=1;
                else{
                    r=0;
                    break;
                }
        if(r)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
        }

}

//cout<<fixed<<setprecision(14)<<A;
return 0;
}


/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------O_v_T-------         |
  |_______________10_________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mem(a , v)  memset(a , v , sizeof(a))
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s" , &a)
#define scc(a) scanf("%c" , &a)
#define blank printf("\n")
#define pla printf("plapla\n")
#define pb push_back
#define fo(j,n,t)     for(int i=j;i<n;i+=t)
#define fod(j,n,t)     for(int i=j;i>=n;i-=t)
#define f first
#define s second
const ull MAX = 1e5+55;
const int inf = 1e9+77;
const int MOD = 1e9+7;
const double eps = 1e-7;
map<char,int>mp;
vector<int>v;
set<ll>cc;
pair<int ,int>pi;
int x[MAX];
int y[MAX];
char c[MAX];
/*int Binary(int num)
{
      int bin;

    while (num > 0)

    {

        bin = num % 2;

        cout << bin;

        num /= 2;

    }
}*/
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q;
cin>>q;
while(q--)
{
    memset(x,0,sizeof x);
    int n;
    cin>>n;
    int sum=0;
    int j=0;
    for(int i=0;i<n;i++)
        cin>>x[i];

    bool t=1;
    for(int i=1;i<n;i++)
        if(x[i]>=x[i-1])
            continue;
        else{
            t=0;
            break;
        }
        if(t)
            cout<<"YES"<<endl;
        else
        {
            bool r=1;
           for(int i=1;i<n;i++)
                if(x[i]<x[i-1])
                  r=1;
                 else{
                    j=i;
                    r=0;

                    break;}
            for(int i=j+1;i<n;i++)
                if(x[i]<x[i-1])
                 r=1;
                else{
                    r=0;
                    break;
                }
        if(r)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
        }

}

//cout<<fixed<<setprecision(14)<<A;
return 0;
}


/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------O_v_T-------         |
  |_______________10_________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mem(a , v)  memset(a , v , sizeof(a))
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s" , &a)
#define scc(a) scanf("%c" , &a)
#define blank printf("\n")
#define pla printf("plapla\n")
#define pb push_back
#define fo(j,n,t)     for(int i=j;i<n;i+=t)
#define fod(j,n,t)     for(int i=j;i>=n;i-=t)
#define f first
#define s second
const ull MAX = 1e5+55;
const int inf = 1e9+77;
const int MOD = 1e9+7;
const double eps = 1e-7;
map<char,int>mp;
vector<int>v;
set<ll>cc;
pair<int ,int>pi;
int x[MAX];
int y[MAX];
char c[MAX];
/*int Binary(int num)
{
      int bin;

    while (num > 0)

    {

        bin = num % 2;

        cout << bin;

        num /= 2;

    }
}*/
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q;
cin>>q;
while(q--)
{
    memset(x,0,sizeof x);
    int n;
    cin>>n;
    int sum=0;
    int j=0;
    for(int i=0;i<n;i++)
        cin>>x[i];

    bool t=1;
    for(int i=1;i<n;i++)
        if(x[i]>=x[i-1])
            continue;
        else{
            t=0;
            break;
        }
        if(t)
            cout<<"YES"<<endl;
        else
        {

            bool r=1;
           for(int i=0;i<n-1;i++)
                if(x[i]>x[i+1])
                  r=1;
                 else{
                    j=i+1;
                    r=0;

                    break;}
            for(int i=j;i<n-1;i++)
                if(x[i]>x[i+1])
                 r=1;
                else{
                    r=0;
                    break;
                }
        if(r)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
        }

}

//cout<<fixed<<setprecision(14)<<A;
return 0;
}


/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------O_v_T-------         |
  |_______________10_________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mem(a , v)  memset(a , v , sizeof(a))
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s" , &a)
#define scc(a) scanf("%c" , &a)
#define blank printf("\n")
#define pla printf("plapla\n")
#define pb push_back
#define fo(j,n,t)     for(int i=j;i<n;i+=t)
#define fod(j,n,t)     for(int i=j;i>=n;i-=t)
#define f first
#define s second
const ull MAX = 1e5+55;
const int inf = 1e9+77;
const int MOD = 1e9+7;
const double eps = 1e-7;
map<char,int>mp;
vector<int>v;
set<ll>cc;
pair<int ,int>pi;

int y[MAX];
char c[MAX];
/*int Binary(int num)
{
      int bin;

    while (num > 0)

    {

        bin = num % 2;

        cout << bin;

        num /= 2;

    }
}*/
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q;
cin>>q;
while(q--)
{

    int n;
    cin>>n;
    int x[n+4];
    int sum=0;
    int j=0;
    for(int i=1;i<=n;i++)
        cin>>x[i];

    bool t=1;
    for(int i=1;i<=n-1;i++)
        if(x[i]<x[i+1])
         continue;
        else
        {
            t=0;
            j=i+1;
            break;
        }
        if(t)
            cout<<"YES"<<endl;
        else if(t==0 && x[1]>x[j])
        {

            if(j==n)
             t=1;
            else{
            for(int i=j;i<=n-1;i++)
                if(x[i]<x[i+1] )
                  t=1;
                else
                {
                    t=0;
                    break;
                }

        }
        if(t)
            cout<<"YES"<<endl;

}

if(!t)
{
    bool t=1;
    for(int i=1;i<=n-1;i++)
        if(x[i]>x[i+1])
         continue;
        else
        {
            t=0;
            j=i+1;
            break;
        }
        if(t)
            cout<<"YES"<<endl;
        else if(t==0 && x[1]<x[j])
        {

            if(j==n)
             t=1;
            else{
            for(int i=j;i<=n-1;i++)
                if(x[i]>x[i+1] )
                  t=1;
                else
                {
                    t=0;
                    break;
                }

        }
        if(t)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;

}

}
}

//cout<<fixed<<setprecision(14)<<A;
return 0;
}


#include<bits/stdc++.h>

#define task "inp"
#define rep(i,l,r) for (int i = (l) ; i <= (r) ; ++i)
#define Rep(i,r,l) for (int i = (r) ; i >= (l) ; --i)
#define all(x) (x).begin(),(x).end()
#define allar(x,_,__) (x) + (_), (x) + (_) + (__)
#define pb push_back
#define pob pop_back
#define pof pop_front
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define c_zh(x) __builtin_clz((x))
#define c_zl(x) __builtin_ctz((x))
#define c_o(x) __builtin_popcount((x))
#define o_e(x) __builtin_parity((x))

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int,pii> viii;
typedef vector<long long> vll;
typedef long long ll;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, pos;
        cin >> n;
        vector<int> a(n + 1);
        rep(i, 0, n - 1) {
            cin >> a[i];
            if (a[i] == 1) pos = i;
        }
        int okr = 1, okl = 1;
        for (int i = 1; i < n; ++i)
        {
            okl &= (a[(pos - i + n) % n] == i + 1);
            okr &= (a[(pos + i + n) % n] == i + 1);
        }
        if (okr || okl) cout << "YES\n";
        else cout << "NO\n";
    }
	return 0;
}


#include<bits/stdc++.h>

#define task "inp"
#define rep(i,l,r) for (int i = (l) ; i <= (r) ; ++i)
#define Rep(i,r,l) for (int i = (r) ; i >= (l) ; --i)
#define all(x) (x).begin(),(x).end()
#define allar(x,_,__) (x) + (_), (x) + (_) + (__)
#define pb push_back
#define pob pop_back
#define pof pop_front
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define c_zh(x) __builtin_clz((x))
#define c_zl(x) __builtin_ctz((x))
#define c_o(x) __builtin_popcount((x))
#define o_e(x) __builtin_parity((x))

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int,pii> viii;
typedef vector<long long> vll;
typedef long long ll;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, pos1;
        cin >> n;
        vector<int> a(n + 1);
        rep(i, 1, n) {
            cin >> a[i];
            if (a[i] == 1) pos1 = i;
        }
        bool flag = true;
        if (n == 1)
        {
            cout << "YES\n";
            continue;
        }
        if (a[pos1] == a[((pos1 + 1) % n == 0) ? (n) : ((pos1 + 1) % n)] - 1)
        {
            int j = ((pos1 + 1) % n == 0) ? (n) : ((pos1 + 1) % n);
            while (j != pos1)
            {
                //cout << (((j + 1) % n == 0) ? (n) : ((j + 1) % n)) << " " << pos1 << "\n";
                if ((((j + 1) % n == 0) ? (n) : ((j + 1) % n)) == pos1) break;
                //cout <<j << " " << j + 1 << "\n";
                if (a[j] == a[((j + 1) % n == 0) ? (n) : ((j + 1) % n)] - 1){
                    j = ((j + 1) % n == 0) ? (n) : ((j + 1) % n);
                    //cout << j << " ";
                }
                else {
                        flag = false;
                        break;
                }
            }
        }
        else if (a[pos1] == a[(pos1 - 1 == 0) ? (n) : (pos1 - 1)] - 1)
        {
            int j = (pos1 - 1 == 0) ? (n) : (pos1 - 1);
            while (j != pos1)
            {
                if (pos1 == ((j == 0) ? (n) : (j - 1))) break;
                if (a[j] == a[(j - 1 == 0) ? (n) : (j - 1)] - 1)
                    j = ((j - 1) == 0) ? (n) : (j - 1);
                else{
                    flag = false;
                    break;
                }
            }
        }else flag = false;
        (flag) ? (cout << "YES\n") : (cout << "NO\n");
    }
	return 0;
}


#include<bits/stdc++.h>

#define task "inp"
#define rep(i,l,r) for (int i = (l) ; i <= (r) ; ++i)
#define Rep(i,r,l) for (int i = (r) ; i >= (l) ; --i)
#define all(x) (x).begin(),(x).end()
#define allar(x,_,__) (x) + (_), (x) + (_) + (__)
#define pb push_back
#define pob pop_back
#define pof pop_front
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define c_zh(x) __builtin_clz((x))
#define c_zl(x) __builtin_ctz((x))
#define c_o(x) __builtin_popcount((x))
#define o_e(x) __builtin_parity((x))

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int,pii> viii;
typedef vector<long long> vll;
typedef long long ll;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, pos1;
        cin >> n;
        vector<int> a(n + 1);
        rep(i, 1, n) {
            cin >> a[i];
            if (a[i] == 1) pos1 = i;
        }
        bool flag = true;
        if (n == 1)
        {
            cout << "YES\n";
            continue;
        }
        if (a[pos1] == a[((pos1 + 1) == n) ? (pos1 + 1) : ((pos1 + 1) % n)] - 1)
        {
            int j = ((pos1 + 1) == n) ? (pos1 + 1) : ((pos1 + 1) % n);
            while (j != pos1)
            {
                if ((j + 1) % n == pos1) break;
                //cout <<j << " " << j + 1 << "\n";
                if (a[j] == a[((j + 1) == n) ? (j + 1) : ((j + 1) % n)] - 1)
                    j = (j + 1) % n;
                else {
                        flag = false;
                        break;
                }
            }
        }
        else if (a[pos1] == a[(pos1 - 1 == 0) ? (n) : (pos1 - 1)] - 1)
        {
            int j = (pos1 - 1 == 0) ? (n) : (pos1 - 1);
            while (j != pos1)
            {
                if (pos1 == ((j == 0) ? (n) : (j - 1))) break;
                if (a[j] == a[(j - 1 == 0) ? (n) : (j - 1)] - 1)
                    j = ((j - 1) == 0) ? (n) : (j - 1);
                else{
                    flag = false;
                    break;
                }
            }
        }else flag = false;
        (flag) ? (cout << "YES\n") : (cout << "NO\n");
    }
	return 0;
}