for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) o = sum(a) k = o - (n - o) for i in range(n-1): if a[i] != a[i+1]: continue if a[i]: if k > 0: k -= 1 else: if k < 0: k += 1 print("No" if k else "Yes")