import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) #alist = [] #s = input() t = int(input()) for _ in range(t): n = int(input()) alist = list(map(int,input().split())) if sum(alist) != n: print('No') continue c = 0 for i in range(n): if alist[i] == 2: if alist[i-1] == 2 or alist[(i+1)%n] == 2: print('No') c = 1 break if alist[i] == 1: if alist[i-1] == 2 and alist[(i+1)%n] == 2: print('No') c = 1 break if alist[i] == 0: if alist[i-1] == 0 or alist[(i+1)%n] == 0: print('No') c = 1 break if alist.count(2) == 0 or alist.count(0) == 0: print('No') c = 1 if not c: print('Yes')