def ip():return int(input()) def mp():return map(int, input().split()) def lmp():return list(map(int, input().split())) T = ip() from collections import defaultdict def solve(): N = ip() A = lmp() cnt = defaultdict(int) cnt[A[0]] = 1 for i in range(1, N): cnt[A[i]] += 1 if A[i] != 1 and A[i] == A[i-1]: print('No') return if cnt[0] == 0 or cnt[2] == 0: print('No') else: print('Yes') for _ in range(T): solve()