There are $n$ students standing in a circle in some order. The index of the $i$-th student is $p_i$. It is guaranteed that all indices of students are distinct integers from $1$ to $n$ (i. e. they form a permutation).

Students want to start a round dance. A clockwise round dance can be started if the student $2$ comes right after the student $1$ in clockwise order (there are no students between them), the student $3$ comes right after the student $2$ in clockwise order, and so on, and the student $n$ comes right after the student $n - 1$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $i$ should be right after the student $i - 1$ in counterclockwise order (this condition should be met for every $i$ from $2$ to $n$). 

For example, if the indices of students listed in clockwise order are $[2, 3, 4, 5, 1]$, then they can start a clockwise round dance. If the students have indices $[3, 2, 1, 4]$ in clockwise order, then they can start a counterclockwise round dance.

Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. 

You have to answer $q$ independent queries.


-----Input-----

The first line of the input contains one integer $q$ ($1 \le q \le 200$) — the number of queries. Then $q$ queries follow.

The first line of the query contains one integer $n$ ($1 \le n \le 200$) — the number of students.

The second line of the query contains a permutation of indices $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$), where $p_i$ is the index of the $i$-th student (in clockwise order). It is guaranteed that all $p_i$ are distinct integers from $1$ to $n$ (i. e. they form a permutation).


-----Output-----

For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".


-----Example-----
Input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4

Output
YES
YES
NO
YES
YES

Difficulty: introductory

Starter code:

Solutions:
'''input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4

'''
import sys
from collections import defaultdict as dd
from itertools import  permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from  heapq import heappush as hpush
from heapq import heappop as hpop
mod=10**9+7

def ri(flag=0):
	if flag==0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())



for _ in range(ri(1)):
	n = ri(1)
	a= ri()
	idx = a.index(1)

	check1 = 1
	check2 =1
	for i in range(n):
		if a[(idx+i)%n] == i+1:
			pass
		else:
			check1=0
	a=a[::-1]
	idx = a.index(1)
	for i in range(n):
		if a[(idx+i)%n] == i+1:
			pass
		else:
			check2=0

	if check1==1 or check2==1:
		print("YES")
	else:
		print("NO")

from collections import deque
for _ in range(int(input())):
    n = int(input())
    A = list(map(int, input().split()))
    ans = 'NO'
    B = deque(A)
    C = [i for i in range(1, n + 1)]
    D = C[::-1]
    for i in range(n):
        B.popleft()
        B.append(A[i])
        if list(B) == C or list(B) == D:
            ans = 'YES'
    print(ans)

q=int(input())
for i in range(q):
    n=int(input())
    arr=[int(x) for x in input().split()]
    l=arr[0]
    forwards=True
    back=True
    for j in range(n-1):
        if arr[j]-1!=(arr[0]-1+j)%n:
            forwards=False
        if arr[j]-1!=(arr[0]-1-j)%n:
            back=False
    if forwards==True or back==True:
        print("YES")
    else:
        print("NO")

q = int(input())
for i in range(q):
	n = int(input())
	p = list(map(int, input().split()))
	for i in range(n - 1):
		if p[i] + 1 != p[i+1] and not(p[i] == n and p[i+1] == 1):
			break
	else:
		print('YES')
		continue
	for i in range(n - 1):
		if p[i] - 1 != p[i+1] and not(p[i] == 1 and p[i+1] == n):
			break
	else:
		print('YES')
		continue
	print('NO')


n=int(input())
for x in range(n):
    t=int(input())
    r=list(map(int,input().split()))
    r=r+r
    l1=[x for x in range(1,t+1)]
    l2=l1[::-1]
    bo=0
    for i in range(t):
        if(r[i:i+t]==l1):
            bo=1
        if(r[i:i+t]==l2):
            bo=1
    if(bo==1):
        print("YES")
    else:
        print("NO")


from sys import stdin
q=int(stdin.readline().strip())
for i in range(q):
    n=int(stdin.readline().strip())
    s=list(map(int,stdin.readline().strip().split()))
    x=s.index(1)
    y=1
    t=True
    for i in range(n):
        if s[x]!=y:
            t=False
            break
        x=(x+1)%n
        y+=1
    t1=True
    x=s.index(1)
    y=1
    for i in range(n):

        if s[x]!=y:
            t1=False
            break
        x=(x-1)%n
        y+=1
    if t or t1:
        print("YES")
    else:
        print("NO")
        


for q in range(int(input())):
    n = int(input())
    a = [int(x) for x in input().split()]

    idx = a.index(1)

    b = a[idx : ] + a[ : idx]
    c = a[ : idx + 1][::-1] + a[idx +1 : ][::-1]

    a.sort()

    if b == a or c == a:
        print("YES")
    else:
        print("NO")


for _ in range(int(input())):
    n = int(input())
    l = [*map(int, input().split())]
    res = False
    for i in range(n):
        x = l[i:] + l[:i]
        if all(x[i] < x[i + 1] for i in range(n - 1)) or all(x[i] > x[i + 1] for i in range(n - 1)):
            res = True
    print('YES' if res else 'NO')

q = int (input())
while q:
    n = int(input())
    a = list(map(int, input().split()))
    a += a
    p = [i for i in range(1, n + 1)]
    flag = False
    for i in range(n):
        if a[i: i + n] == p or a[i: i + n] == p[::-1]:
            print("YES")
            flag = True
            break
    if not flag:
        print("NO")
    q -= 1


for _ in range(int(input())):
	n = int(input())
	ans = [i + 1 for i in range(n)]
	l = list(map(int, input().split()))
	one = l.index(1)
	l = l[one:] + l[:one]
	rev = l[::-1]
	one = rev.index(1)
	rev = rev[one:] + rev[:one]
	if rev == ans or l == ans:
		print('YES')
	else:
		print('NO')

q = int(input())
for _ in range(q):
    n = int(input())
    p = list(map(int, input().split()))
    i = p.index(1)
    p2 = p[i:] + p[:i]
    if p2 == list(range(1, n + 1)) or p2[1:] == list(reversed(list(range(2, n + 1)))):
        print('YES')
    else:
        print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int,input().split()))
	idx = 0
	f = 0
	f2 = 0
	for i in range(n):
		if(c[i]==1):
			idx = i
			break

	for i in range(n):
		if(c[(idx+i)%n]!=i+1):
			f = 1
		if(c[idx-i]!=i+1):
			f2 = 1
	if f == 1 and f2 ==1:
		print('NO')
	else:
		print('YES')

n = int(input())
for _ in range(n):
	_ = int(input())
	*l, = map(int, input().split())
	ans = False
	for i in range(len(l)-1):
		if l[i] == len(l):
			if not l[i+1] == 1:
				break
		else:
			if not l[i] + 1 == l[i+1]:
				break
	else:
		ans = True
	for i in range(len(l)-1):
		if l[i] == 1:
			if not l[i+1] == len(l):
				break
		else:
			if not l[i] - 1 == l[i+1]:
				break
	else:
		ans = True
	if ans:
		print("YES")
	else:
		print("NO")

#579_A

q = int(input())

for i in range(0, q):
    n = int(input())
    ln = [int(j) for j in input().split(" ")]
    st = 0
    f = True
    for j in range(1, len(ln)):
        if abs(ln[j] - ln[j - 1]) != 1 and abs(ln[j] - ln[j - 1]) != n - 1:
            f = False
            break
    if abs(ln[0] - ln[-1]) != 1 and abs(ln[0] - ln[-1]) != n - 1:
        f = False
    if f:
        print("YES")
    else:
        print("NO")
        


import math
# helpful:
# r,g,b=map(int,input().split())
#list1 = input().split()
#for i in range(len(list1)):
#    list1[i] = int(list1[i])
#print(list1)
# arr = [[0 for x in range(columns)] for y in range(rows)]

q = int(input())
for i in range(q):
    n = int(input())
    arr = input().split()
    for i in range(n):
        arr[i] = int(arr[i])
    if(n<=3):
        print("YES")
    else:
        havent = True
        val = (arr[1]-arr[0]) % n
        if(val != 1 and val != n-1):
            print("NO")
        else:
            for i in range(n-1):
               if((arr[i+1]-arr[i]) % n != val and havent):
                   print("NO")
                   havent = False
            if(havent):
               print("YES")
           
        


q = int(input())
for qq in range(q):
    n = int(input())
    *p, = list(map(int, input().split()))
    for i in range(n-1):
        if (p[i+1]-p[i]!=1 and not(p[i+1]==1 and p[i]==n)):
            break
    else:
        print("YES")
        continue

    for i in range(n-1):
        if (p[i+1]-p[i]!=-1 and not(p[i+1]==n and p[i]==1)):
            break
    else:
        print("YES")
        continue
    
    print("NO")


import sys

def solve(A):
    n = len(A)
    t = A[0]-1
    cw = True
    for a in A:
        if t != a-1:
            cw = False
        t = (t+1)%n
    t = A[0]-1
    ccw = True
    for a in A:
        if t != a-1:
            ccw = False
        t = (n+t-1)%n
    return (ccw or cw)

in_file = sys.stdin #open("A.txt", "r") 

q = int(in_file.readline().strip())
for _ in range(q):
    n = int(in_file.readline().strip())
    A = list(map(int, in_file.readline().strip().split()))
    if solve(A):
        sys.stdout.write("YES\n")
    else:
        sys.stdout.write("NO\n")
sys.stdout.flush()

for _ in range(int(input())):
    n = int(input())
    p = list(int(a) for a in input().split())
    c = 0
    if p[n-1] < p[0]:
        c += 1
    for i in range(1, n):
        if p[i-1] < p[i]:
            c += 1
    if c == n-1 or c == 1:
        print("YES")
    else:
        print("NO")


q = int(input())

for i in range(q):
    n = int(input())
    p = list(map(int,input().split()))
    q = p+p+p
    p = sorted(p)
    r = p[::-1]
    f = 0
    for k in range(2*n):
        if q[k:k+n] == r or q[k:k+n] == p:
            f = 1
            break
    if f == 0:
        print("NO")
    else:
        print("YES")


'''q=int(input())
for I in range(q):
    n=int(input())
    a=[int(i) for i in input().split()]
    ind = a.find(1)
    ini = [(i+1) for i in range(n)]
    arr1 = a[ind:]
    arr2 = a[:ind]
    if(sorted(arr1)==a['''

def main():
    t=int(input())
    for q in range(t):
        n = int(input())
        a = [int(x) for x in input().split()]

        idx = a.index(1)

        b = a[idx : ] + a[ : idx]
        c = a[ : idx + 1][::-1] + a[idx +1 : ][::-1]

        a.sort()

        if b == a or c == a:
            print("YES")
        else:
            print("NO")


main()


''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces1203A_live
gi = lambda : list(map(int,input().split()))
for k in range(gi()[0]):
	n, = gi()
	l = gi()
	cl = l[l.index(1):] + l[:l.index(1)]
	ccl = l[l.index(n):] + l[:l.index(n)]
	p = [i for i in range(1, n + 1)]
	if cl == p or ccl == p[::-1]:
		print("YES")
	else:
		print("NO")

t = int(input())

while t:
    t -= 1
    n = int(input())
    arr = [int(item) for item in input().split(' ')]
    ans = True
    for i in range(n):
        if (arr[i - 1] + 1) % n == arr[i] % n:
            continue
        ans = False
        break

    ans2 = True
    for i in range(n):
        if (arr[i] + 1) % n == arr[i - 1] % n:
            continue
        ans2 = False
        break
    print("YES" if ans or ans2 else "NO")


w = int(input())
def fun(x, n):
	if x % n != 0:
		return x % n
	else:
		return n
for we in range(w):
	n = int(input())
	l = list(map(int,input().split()))
	if n == 1:
		print("YES")
	else:
		start = l[0]
		odp = 1
		if l[1] == fun(l[0] + 1, n):
			for i in range(1, n):
				if l[i] != fun(l[i-1] + 1, n):
					odp = 0
					break
		elif l[1] == fun(l[0] - 1, n):
			for i in range(1, n):
				if l[i] != fun(l[i-1] - 1, n):
					odp = 0
					break
		else:
			odp = 0
		if odp == 0:
			print("NO")
		else:
			print("YES")

for _ in range(int(input())):
    n = int(input())
    p = list(map(int, input().split()))
    i = p.index(1)
    if p[i:] + p[:i] == sorted(p) or p[i + 1:] + p[:i + 1] == sorted(p, reverse=True):
        print("YES")
    else:
        print("NO")