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) for i in range(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 or cnt[0] != cnt[2]: print('No') else: print('Yes') for _ in range(T): solve()