# coding: utf-8 # Your code here! T=int(input()) for _ in range(T): N=int(input()) A=list(map(int,input().split())) dic={0:0,1:0,2:0} prev=-1 judge=True for a in A: dic[a]+=1 if (a==2 and prev==2) or (a==0 and prev==0): judge=False prev=a if dic[2]==dic[0] and dic[0]>0 and dic[1]>0 and judge: print("Yes") else: print("No")