for _ in range(T := int(input())): N = int(input()) A = list(map(int, input().split())) memo = 1 for a in A*2: if a == 1: continue if a == memo: print("No") break memo = a else: print("No" if memo == 1 else "Yes")