You are given two binary strings $S$ and $P$, each with length $N$. A binary string contains only characters '0' and '1'. For each valid $i$, let's denote the $i$-th character of $S$ by $S_i$.
You have to convert the string $S$ into $P$ using zero or more operations. In one operation, you should choose two indices $i$ and $j$ ($1 \leq i < j \leq N$) such that $S_i$ is '1' and $S_j$ is '0', and swap $S_i$ with $S_j$.
Determine if it is possible to convert $S$ into $P$ by performing some operations.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains a single string $S$.
- The third line contains a single string $P$.

-----Output-----
For each test case, print a single line containing the string "Yes" if it is possible to convert $S$ into $P$ or "No" otherwise (without quotes).

-----Constraints-----
- $1 \leq T \leq 10^5$
- $1 \leq N \leq 10^5$
- $S$ and $P$ contain only characters '0' and '1'
- the sum of $N$ over all test cases does not exceed $10^5$

-----Subtasks-----
Subtask #1 (20 points):
- $N \leq 14$
- the sum of $N$ over all test cases does not exceed $100$
Subtask #2 (30 points): the sum of $N$ over all test cases does not exceed $1,000$
Subtask #3 (50 points): original constraints

-----Example Input-----
3
2
00
00
3
101
010
4
0110
0011

-----Example Output-----
Yes
No
Yes

-----Explanation-----
Example case 1: The strings are already equal.
Example case 2: It can be showed that it is impossible to convert $S$ into $P$.
Example case 3: You can swap $S_2$ with $S_4$. The strings will then be equal.

Difficulty: interview

Starter code:

Solutions:

def solve(s, p):
 diffs = 0
 for x, y in zip(s, p):
  if x == y:
   continue
  if x == '0':
   if diffs < 1:
    return "No"
   diffs -= 1
  else:
   diffs += 1
 return "Yes" if diffs == 0 else "No"

for _ in range(int(input())):
 l = int(input())
 s = input().strip()
 p = input().strip()
 print(solve(s, p))


for test in range(int(input())):
 no=int(input())
 a=input()
 b=input()
 if a.count('0')==b.count('0') and a.count('1')==b.count('1'):
  c=0
  for i in range(len(b)):
   if b[:i].count('1')>a[:i].count('1'):
    c=1
    break
  if c==0:
   print('Yes')
  else:
   print('No')
 else:
  print('No')

t = int(input())
for _ in range(t):
 n = int(input())
 s1 = input()
 s2 = input()
 rem = 0
 if (s1.count('1') == s2.count('1') and s1.count('0') == s2.count('0')):
  u1 = 0
  n1 = 0
  s1 = list(s1)
  s2 = list(s2)
  for i in range(n):
   if s1[i] != s2[i]:
    if s1[i] == '1':
     u1 += 1
    elif s2[i] == '1':
     n1 += 1
    if u1 < n1:
     rem = 1
     break
  if rem == 0:    
   print("Yes")
  else:
   print("No")
 else:   print("No")







import sys
from math import * 
from collections import *
from itertools import *

def int_arr():return list(map(int,input().split()))
def str_arr():return list(map(str,input().split()))
def two_int():return list(map(int,input().split()))
def two_str():return list(map(str,input().split()))
mod = 10**9+7
sys.setrecursionlimit(10**9)


def solve(s,p):
 s = list(s)
 p = list(p)
 flag = 0
 if s.count('0') == p.count('0') and s.count('1') == p.count('1'):
  for i in range(len(s)):
   if s[i] == '1' and p[i] == '0':
    for j in range(i,n):
     if s[j] == '0':
      temp = s[i]
      s[i] = s[j]
      s[j] = temp
      break
   if s == p:
    flag = 1
    break

 if flag == 1:
  return 'Yes'
 else:
  return 'No'






for _ in range(int(input())):
 n = int(input())
 s = str(input())
 p = str(input())
 print(solve(s,p))


import sys
from math import * 
from collections import *
from itertools import *

def int_arr():return list(map(int,input().split()))
def str_arr():return list(map(str,input().split()))
def two_int():return map(int,input().split())
def two_str():return map(str,input().split())
mod = 10**9+7
sys.setrecursionlimit(10**9)


def solve(s,p):
 s = list(s)
 p = list(p)
 flag = 0
 if s.count('0') == p.count('0') and s.count('1') == p.count('1'):
  for i in range(len(s)):
   if s[i] == '1' and p[i] == '0':
    for j in range(1,n):
     if s[j] == '0':
      temp = s[i]
      s[i] = s[j]
      s[j] = temp
      break
   if s == p:
    flag = 1
    break

 if flag == 1:
  return 'Yes'
 else:
  return 'No'






for _ in range(int(input())):
 n = int(input())
 s = str(input())
 p = str(input())
 print(solve(s,p))

# cook your dish here
for _ in range(int(input())):
 n = int(input())
 s = input().strip()
 p =input().strip()
 arr1 = [0]*(n+1)
 arr2 = [0]*(n+1)
 flag = False
 s1 = 0
 p1 = 0
 for i in range(1,n+1):
  arr1[i] = arr1[i-1]
  arr2[i] = arr2[i-1]
  if s[i-1] == '1':
   arr1[i] += 1
   s1 += 1
  if p[i-1] == '1':
   arr2[i] += 1
   p1 += 1
  
  if arr1[i] < arr2[i]:
   flag = True;break
 # print(arr1)
 # print(arr2)
 if p1 != s1:
  flag =True
 if flag:
  print("No")
 else:
  print("Yes")

for _ in range(int(input())):
 N = int(input())
 S= str(input())
 P= str(input())
 zero=0
 one=0
 ans=True
 for i in range(N):
  if S[i]!=P[i]:
   if S[i]=='1':
    one+=1 
   else:
    zero+=1 
   if one<zero:
    ans=False
    break
 if ans==True and (one==zero):
  print('Yes')
 else:
  print('No')
   
   
 
 
 


# cook your dish here
t = int(input())

for _ in range(t):
 n = int(input())
 s = input()
 p = input()
 
 o=0
 z=0
 o2=0
 z2=0
 for i in s:
  if(i=='1'):
   o+=1
  else:
   z+=1
 
 flag=0
 
 for i in p:
  if(i=='1'):
   o2+=1
  else:
   z2+=1
 
 spareone=0
 if(o==o2 and z == z2):
  for i in range(n):
   if(s[i]!=p[i]):
    if(p[i]=='0'):
     spareone+=1
    if(p[i]=='1'):
     if(spareone==0):
      flag=1
      break
     else:
      spareone=spareone-1
  
  if(flag==0):
   print("Yes")
  else:
   print("No")
 else:
  print("No")


tc = int(input())
 
for _ in range(tc):
 
 n = int(input())
 s = input()
 p = input()
 
 zeros = ones = 0
 
 for i in range(n):
  if s[i] != p[i]:
   if s[i] == '0':
    zeros += 1
   else:
    ones += 1
 
 if zeros != ones:
  print("No")
  continue
 
 c1 = 0
 ans = True
 
 for i in range(n):
  if s[i] != p[i]:
   if s[i] == '0':
    if c1 > 0:
     c1 -= 1
    else:
     ans = False
     break
   else:
    c1 += 1
    
 print("Yes" if ans else "No")

# cook your dish here
for i in range(int(input())):
 n=int(input())
 s=input()
 p=input()
 c=1
 o=0
 z=0
 for j in range(n):
  if s[j]!=p[j]:
   if s[j]=="1":
    o+=1
   else:
    z+=1
   if o<z:
    c=0
    break
 if c==1 and o==z:
  print("Yes")
 else:
  print("No")

# cook your dish here
t = int(input())
for i in range(t):
 n=input()
 l=input()
 p=input()
 c=1
 o=0
 z=0
 for j in range(len(l)):
  if l[j]!=p[j]:
   if l[j]=="1":
    o+=1
   else:
    z+=1
   if o<z:
    c=0
    break
 if c==1 and o==z:
  print("Yes")
 else:
  print("No")

def check(a,b,i,n):
 for j in range(i+1,n):
  if a[j]=='0' and b[j]=='1':
   return j
 return -1
for _ in range(int(input())):
 n=int(input())
 a,b=input(),input()
 for i in range(n):
  if a[i]!=b[i]:
   if a[i]==0:
    print("No")
    break
   else:
    x=check(a,b,i,n)
    if x==-1:
     print("No")
     break
    else:
     a=a[:i]+a[x]+a[i+1:x]+a[i]+a[x+1:]
 else:
  print("Yes")

t = int(input())
for _ in range(t):
 n = int(input())
 s = input()
 p = input()
 counter = 0
 flag = 0
 count1,count2 = 0,0
 for x in s:
  if x=='1':
   count1 += 1
 for x in p:
  if x=='1':
   count2 += 1
 if count1!=count2:
  print('No')
 else:
  for i in range(n):
   if s[i]=='1' and p[i]=='0':
    counter += 1
   elif s[i]=='0' and p[i]=='1':
    counter-=1
   if counter < 0:
    flag = 1
    break
  if flag==1:
   print('No')
  else:
   print('Yes')

t = int(input())
while t != 0:
 n = int(input())
 s = input()
 p = input()
 f = 1
 o = 0
 z = 0
 for j in range(n):
  if s[j] != p[j]:
   if s[j] == "1":
    o += 1
   else:
    z += 1
   if o < z:
    f = 0
    break
 if f == 1 and o == z:
  print("Yes")
 else:
  print("No")
 t = t-1


t = int(input())
for i in range(t):
 n = int(input())
 s = input()
 p = input()
 
 if s == p:
  print("Yes")
 else:
  z1, z2 = s.count("0"), p.count("0")
  
  if z1 != z2:
   print("No")
   continue
  
  counter = 0

  for i in range(n):
   if s[i] != p[i]:
    False
    
    if s[i] == "0":
     if counter > 0:
      counter -= 1
     else:
      counter = 1
      break
    else:
     counter += 1
  
  if counter > 0:
   print("No")
  else:
   print("Yes")

# cook your dish here
t = int(input())
for _ in range(t):
 n = int(input())
 s = input()
 p = input()
 if s.count('1')!=p.count('1'):
  print("No")
  continue
 c = 0
 ans = True
 for i in range(n):
  if s[i]!=p[i]:
   if s[i]=='0':
    if c>0:
     c = c-1
    else:
     ans = False
     break
   else:
    c = c + 1
 if ans:
  print("Yes")
 else:
  print("No")


# cook your dish here
# cook your dish here
for j in range(int(input())):
 a=int(input())
 q=input()
 r=input()
 if q==r:
  print("Yes")
 else:
  c=0
  if(q.count('0')==r.count('0')):
   i=0
   while(i<a-1):
    if q==r:
     break
    if q[i]!=r[i]:
     if q[i]=='0':
      c=0
      break
     else:
      for t in range(i+1,a):
       if q[t]=='0':
        break
      k=t
      q=q.replace('1','0',i)
      if k!=a-1:
       q=q.replace('0','1',k)
      else:
       q=q[:a-1]
       q=q+q[i]
      i+=1
      c+=1
    else:
     i+=1
  if c==0:
   print("No")
  else:
   print("Yes")


# cook your dish here
# cook your dish here
for j in range(int(input())):
 a=int(input())
 q=input()
 r=input()
 if q==r:
  print("Yes")
 else:
  c=0
  if(q.count('0')==r.count('0')):
   i=0
   while(i<a-1):
    if q==r:
     break
    if q[i]!=r[i]:
     if q[i]=='0':
      c=0
      break
     else:
      for t in range(i+1,a):
       if q[t]=='0':
        break
      k=t
      q=q.replace('1','0',i)
      q=q.replace('0','1',k)
      i+=1
      c+=1
    else:
     i+=1
  if c==0:
   print("No")
  else:
   print("Yes")


# cook your dish here
# cook your dish here
for j in range(int(input())):
 a=int(input())
 q=list(input())
 r=list(input())
 if q==r:
  print("Yes")
 else:
  c=0
  if(q.count('0')==r.count('0')):
   i=0
   while(i<a-1):
    if q==r:
     break
    if q[i]!=r[i]:
     if q[i]=='0':
      c=0
      break
     else:
      for t in range(i+1,a):
       if q[t]=='0':
        break
      k=t
      q[i],q[k]=q[k],q[i]
      i+=1
      c+=1
    else:
     i+=1
  if c==0:
   print("No")
  else:
   print("Yes")


# cook your dish here
# cook your dish here
for j in range(int(input())):
 a=int(input())
 q=input()
 r=input()
 if q==r:
  print("Yes")
 else:
  c=0
  if(q.count('0')==r.count('0')):
   i=0
   while(i<a-1):
    if q==r:
     break
    if q[i]!=r[i]:
     if q[i]=='0':
      c=0
      break
     else:
      for t in range(i+1,a):
       if q[t]=='0':
        break
      k=t
      q=q[:i]+q[k]+q[i+1:k]+q[i]+q[k+1:]
      i+=1
      c+=1
    else:
     i+=1
  if c==0:
   print("No")
  else:
   print("Yes")


# cook your dish here
# cook your dish here
for j in range(int(input())):
 a=int(input())
 q=input()
 r=input()
 if q==r:
  print("Yes")
 else:
  c=0
  if(q.count('0')==r.count('0')):
   i=0
   while(i<a-1):
    if q==r:
     break
    if q[i]!=r[i]:
     if q[i]=='0':
      c=0
      break
     else:
      for t in range(0,a):
       if q[t]=='0':
        break
      k=t
      q=q[:i]+q[i+k+1]+q[i+1:i+k+1]+q[i]+q[i+k+2:]
      i+=1
      c+=1
    else:
     i+=1
  if c==0:
   print("No")
  else:
   print("Yes")


# cook your dish here
# cook your dish here
for j in range(int(input())):
 a=int(input())
 q=input()
 r=input()
 if q==r:
  print("Yes")
 else:
  c=0
  if(q.count('0')==r.count('0')):
   i=0
   while(i<a-1):
    if q==r:
     break
    if q[i]!=r[i]:
     if q[i]=='0':
      c=0
      break
     else:
      w=q[i+1:]
      k=w.index('0')
      q=q[:i]+q[i+k+1]+q[i+1:i+k+1]+q[i]+q[i+k+2:]
      i+=1
      c+=1
    else:
     i+=1
  if c==0:
   print("No")
  else:
   print("Yes")


def fun(a,b):
 if a.count('1')==b.count('1'):
  x=0
  for i in range(len(a)):
   if a[i]=='1' and b[i]=='0':
    x=x+1
   if a[i]=='0' and b[i]=='1':
    x=x-1
   if x<0:
    return 0
  if x==0:
   return 1
  else:
   return 0
 return 0

for xxx in range(int(input(''))):
 n=int(input(''))
 a=input('')
 b=input('')
 if fun(a,b)==1:
  print("Yes")
 else:
  print("No")

def fun(a,b):
 x=0
 y=0
 for i in a:
  if i=='1':
   x+=1
 for i in b:
  if i=='1':
   y+=1
 #print(x,y)
 flag=0
 ones_so_far=0
 for i in range(len(a)):
  if a[i]=='1':
   ones_so_far+=1
  if a[i]=='0' and b[i]=='1':
 #       print(i)
 #       print(ones_so_far)
   if ones_so_far!=x:
    flag=1
 #print(flag)
 #return
 if x==y and flag==0:
  print("Yes")
 else:
  print("No")


for xxx in range(int(input(''))):
 n=int(input(''))
 a=input('')
 b=input('')
 fun(a,b)