def main(): n = int(input()) S = input() i = 0 x = 0 while i < n: j = i while j < n and S[i] == S[j]: j += 1 c = j-i i = j if x % 2: c -= 1 x -= 1 x = x//2+c if S[-1] == "1": while not x % 4: x //= 4 t = 1 else: while not x % 4: x //= 4 t = 2 return "Yes" if x == t else "No" for _ in range(int(input())): print(main())