for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) if sum(A) != N: print("No") continue if 0 not in A: print("No") continue j = A.index(0) f = 0 ans = True for i in range(1, N + 1): if f == 0: if A[(i + j) % N] == 0: ans = False break if A[(i + j) % N] == 2: f = 2 elif f == 2: if A[(i + j) % N] == 2: ans = False break if A[(i + j) % N] == 0: f = 0 if ans: print("Yes") else: print("No")