Chef has two binary strings A and B, both having length N. He can perform the following operation on A any number of times (possibly zero):
Select any index i (1 ≤ i ≤ N - 1) and simultaneously set A_{i} := A_{i} \oplus A_{i + 1} and A_{i + 1} := A_{i} \oplus A_{i + 1}. Formally, if initially A_{i} = x and A_{i + 1} = y then set A_{i} := x \oplus y and A_{i + 1} := x \oplus y

Here, \oplus denotes the [bitwise XOR] operation.

Chef wants to determine if it is possible to make A equal to B by applying the above operation any number of times. Can you help Chef?

------ Input Format ------ 

- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N — the length of the binary string A.
- The second line of each test case contains the binary string A of length N.
- The third line of each test case contains the binary string B of length N.

------ Output Format ------ 

For each test case, output YES if Chef can make string A equal to string B by applying the above operation any number of times. Otherwise, output NO.

You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes will be considered identical).

------ Constraints ------ 

$1 ≤T ≤10^{5}$
$2 ≤N ≤10^{5}$
- The sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$

----- Sample Input 1 ------ 
3
2
00
10
3
010
000
4
0011
0100

----- Sample Output 1 ------ 
NO
YES
YES

----- explanation 1 ------ 
Test case $1$: It can be proven that we can not make $A$ equal to $B$ by using the given operation.

Test case $2$: We can apply the following operations: $0\underline{10} \rightarrow 0\underline{11} \rightarrow 000$.

Test case $3$: We can apply the following operations: $0\underline{01}1 \rightarrow 01\underline{11} \rightarrow 0100$.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Bit manipulation

Constructive algorithms

Mathematics

Ad-hoc


Solutions:
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	a1 = list(a)
	c = a1.count('1')
	if n == 2 and a == '00' and (b == '11'):
		print('NO')
	else:
		d = 0
		for i in range(1, n):
			if b[i] == b[i - 1]:
				d = 1
				break
		if d == 1:
			if a == b:
				print('YES')
			elif c == 0:
				print('NO')
			else:
				print('YES')
		elif a == b:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	f = 0
	if a == b:
		print('YES')
		continue
	for i in a:
		if i == '1':
			f = 1
			break
	if f == 0:
		print('NO')
		continue
	f = 1
	for i in range(n - 1):
		if b[i] != b[i + 1]:
			continue
		else:
			f = 0
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
		continue
	if b.count('1') >= 1 and a.count('1') == 0:
		print('NO')
		continue
	(p, q) = ('', '')
	for i in range(n):
		if i % 2:
			p += '0'
			q += '1'
		else:
			p += '1'
			q += '0'
	if b == p or b == q:
		print('NO')
		continue
	print('YES')


for _ in range(int(input())):
	n = int(input())
	A = input()
	B = input()
	if A == B:
		print('YES')
		continue
	if '1' in B and '1' not in A:
		print('NO')
		continue
	sink = False
	for (i, j) in zip(B[:-1], B[1:]):
		if i == j:
			sink = True
	if sink:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	N = int(input())
	in_str = input()
	out_str = input()
	consecutive = False
	one_present = False
	for i in range(N - 1):
		if out_str[i] == out_str[i + 1]:
			consecutive = True
	for x in range(N):
		if in_str[x] == '1':
			one_present = True
			break
	if in_str == out_str:
		print('YES')
	elif consecutive == True and one_present == True:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	c = False
	i = 1
	if a == b:
		print('YES')
		continue
	if n == 2 and a == '00' and (b == '11'):
		print('NO')
		continue
	while i < n:
		if b[i - 1] == b[i]:
			c = True
			break
		i += 1
	if c:
		if a.count('1') == 0:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


def check(s1, n):
	check = True
	for i in range(0, n - 1):
		if s1[i] == s1[i + 1]:
			check = False
			break
	return check
t = int(input())
while t > 0:
	n = int(input())
	s1 = input()
	s2 = input()
	if s1 == s2:
		print('YES')
	elif '1' in s1:
		flag = check(s2, n)
		if flag:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	if s1 == s2:
		print('YES')
	elif '1' not in s1 and '1' in s2:
		print('NO')
	else:
		count = 1
		for i in range(n - 1):
			if s2[i] != s2[i + 1]:
				count += 1
		if count == n:
			print('NO')
		else:
			print('YES')


for p in range(int(input())):
	n = int(input())
	(a, b, f) = (str(input()), str(input()), 0)
	for i in a:
		if i == '1':
			f += 1
			break
	for i in range(n - 1):
		if b[i] == b[i + 1]:
			f += 1
			break
	if a == b or f == 2:
		print('YES')
	else:
		print('NO')


from collections import defaultdict
t = int(input())
while t:
	p = int(input())
	s = list(input())
	h = list(input())
	sr = 0
	hr = 0
	for i in range(p):
		if s[i] == '1':
			sr += 1
		if h[i] == '1':
			hr += 1
	if s == h:
		print('YES')
	elif sr == 0 and hr != 0:
		print('NO')
	else:
		check = 0
		for i in range(p - 1):
			if h[i] != h[i + 1]:
				check += 1
		if check == p - 1:
			print('NO')
		else:
			print('YES')
	t -= 1


def solve(a, b, n):
	x = 1
	for i in range(1, n):
		if b[i] == b[i - 1]:
			x = 0
	if x != 0:
		return a == b
	else:
		cnt = len([x for x in a if x == '1'])
		if cnt > 0:
			return True
		else:
			return a == b

def main():
	t = int(input())
	for tc in range(t):
		n = int(input())
		a = input()
		b = input()
		if solve(a, b, n):
			print('YES')
		else:
			print('NO')
main()


def check(st):
	for i in range(len(st) - 1):
		if st[i] == '0':
			if st[i + 1] != '1':
				return False
		elif st[i + 1] != '0':
			return False
	return True
T = int(input())
for _ in range(T):
	N = int(input())
	A = input()
	B = input()
	one = '1'
	zero = '0'
	if one in B and one not in A:
		print('NO')
	elif A == B:
		print('YES')
	elif check(B):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	(s1, s2) = (input(), input())
	if s1 == s2:
		print('YES')
	elif '1' not in s1:
		print('NO')
	else:
		check = True
		for i in range(1, n):
			if s2[i] == s2[i - 1]:
				check = False
		if check:
			print('NO')
		else:
			print('YES')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	found = a.count('1')
	if n == 2 and a == '00' and (b == '11'):
		print('NO')
	else:
		hi = False
		for i in range(1, n):
			if b[i] == b[i - 1]:
				hi = True
				break
		if hi == True:
			if a == b:
				print('YES')
			elif found == 0:
				print('NO')
			else:
				print('YES')
		elif a == b:
			print('YES')
		else:
			print('NO')


t = int(input())
while t:
	n = int(input())
	s1 = input()
	s2 = input()
	f = 0
	if s1 == s2:
		f = 1
		print('YES')
	elif s2.count('1') > 0 and s1.count('1') == 0:
		f = 1
		print('NO')
	elif len(s2) > 1:
		prev = s2[0]
		ct = 1
		for i in range(1, len(s2)):
			if prev != s2[i]:
				ct += 1
			prev = s2[i]
		if ct == len(s1):
			f = 1
			print('NO')
	if f == 0:
		print('YES')
	t -= 1


for i in range(int(input())):
	n = int(input())
	A = input()
	B = input()
	if A == '0' * n and B != '0' * n:
		print('NO')
		continue
	if n == 1:
		if A == B:
			print('YES')
		else:
			print('NO')
		continue
	if n % 2 == 0:
		if A == B:
			print('YES')
		elif B == '10' * (n // 2) or B == '01' * (n // 2):
			print('NO')
		else:
			print('YES')
	elif A == B:
		print('YES')
	elif B == '10' * (n // 2) + '1' or B == '01' * (n // 2) + '0':
		print('NO')
	else:
		print('YES')


def mi():
	return map(int, input().split())

def li():
	return list(mi())

def si():
	return str(input())

def ni():
	return int(input())

def yn(ans):
	if ans:
		print('YES')
	else:
		print('NO')
for T in range(int(input())):
	n = ni()
	a = si()
	b = si()
	if '1' not in a and '1' in b:
		print('NO')
		continue
	if a == b:
		print('YES')
		continue
	ans = False
	if '00' in b or '11' in b:
		print('YES')
	else:
		print('NO')


for tc in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	x = a.count('1')
	y = b.count('1')
	alt = 1
	for i in range(n - 1):
		if b[i] == b[i + 1]:
			alt = 0
			break
	if not alt:
		if a == b:
			print('YES')
		elif x == 0:
			print('NO')
		else:
			print('YES')
	elif a == b:
		print('YES')
	else:
		print('NO')


strng = lambda : input().split()[0]
inp = lambda : int(input())
mul = lambda : map(int, input().split())
jn = lambda x, l: x.join(map(str, l))
slst = lambda : list(input().split()[0])
silst = lambda : list(map(int, input().split()))
lst = lambda : list(map(int, input().split()))
dd = lambda : defaultdict(lambda : 0)
import sys
input = sys.stdin.readline
from heapq import heapify, nsmallest, nlargest, heappush, heappop
from collections import defaultdict, deque
from math import ceil, log, floor, sqrt, gcd, log10
for _ in range(inp()):
	n = inp()
	a = slst()
	b = slst()
	if a == b:
		print('YES')
		continue
	if set(a) == {'0'}:
		print('NO')
		continue
	for i in range(n - 1):
		if b[i] == b[i + 1]:
			break
	else:
		print('NO')
		continue
	print('YES')


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	if s1 == '00' and s2 == '11':
		print('NO')
	else:
		one = -1
		for i in range(n):
			if s1[i] == '1':
				one = i
				break
		flag = False
		for i in range(1, n):
			if s2[i] == s2[i - 1]:
				flag = True
				break
		if flag:
			if s1 == s2:
				print('YES')
			elif one == -1:
				print('NO')
			else:
				print('YES')
		elif s1 == s2:
			print('YES')
		else:
			print('NO')


testcasesare = int(input())
for a in range(testcasesare):
	numarenumis = int(input())
	warrior1 = input()
	warrior2 = input()
	if warrior1 == warrior2:
		print('YES')
	elif '1' not in warrior1:
		if '1' in warrior2:
			print('NO')
	elif '11' in warrior2 or '00' in warrior2:
		print('YES')
	else:
		print('NO')


def sol(a, b):
	if a == b:
		return True
	if a.count('1') == 0:
		return False
	if b.count('11') == 0 and b.count('00') == 0:
		return False
	return True
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if sol(a, b):
		print('YES')
	else:
		print('NO')


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
import math

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
from math import inf, log2

class LazySegmentTree:

	def __init__(self, array, func=max):
		self.n = len(array)
		self.size = 2 ** (int(log2(self.n - 1)) + 1) if self.n != 1 else 1
		self.func = func
		self.default = 0 if self.func != min else inf
		self.data = [self.default] * (2 * self.size)
		self.lazy = [0] * (2 * self.size)
		self.process(array)

	def process(self, array):
		self.data[self.size:self.size + self.n] = array
		for i in range(self.size - 1, -1, -1):
			self.data[i] = self.func(self.data[2 * i], self.data[2 * i + 1])

	def push(self, index):
		self.lazy[2 * index] += self.lazy[index]
		self.lazy[2 * index + 1] += self.lazy[index]
		self.data[2 * index] += self.lazy[index]
		self.data[2 * index + 1] += self.lazy[index]
		self.lazy[index] = 0

	def build(self, index):
		index >>= 1
		while index:
			self.data[index] = self.func(self.data[2 * index], self.data[2 * index + 1]) + self.lazy[index]
			index >>= 1

	def query(self, alpha, omega):
		res = self.default
		alpha += self.size
		omega += self.size + 1
		for i in range(len(bin(alpha)[2:]) - 1, 0, -1):
			self.push(alpha >> i)
		for i in range(len(bin(omega - 1)[2:]) - 1, 0, -1):
			self.push(omega - 1 >> i)
		while alpha < omega:
			if alpha & 1:
				res = self.func(res, self.data[alpha])
				alpha += 1
			if omega & 1:
				omega -= 1
				res = self.func(res, self.data[omega])
			alpha >>= 1
			omega >>= 1
		return res

	def update(self, alpha, omega, value):
		alpha += self.size
		omega += self.size + 1
		(l, r) = (alpha, omega)
		while alpha < omega:
			if alpha & 1:
				self.data[alpha] += value
				self.lazy[alpha] += value
				alpha += 1
			if omega & 1:
				omega -= 1
				self.data[omega] += value
				self.lazy[omega] += value
			alpha >>= 1
			omega >>= 1
		self.build(l)
		self.build(r - 1)
import sys
input = lambda : sys.stdin.readline().strip()
lis = lambda : list(map(int, input().split()))
sin = lambda : int(input())
many = lambda : map(int, input().split())
alp = 'abcdefghijklmnopqrstuvwxyz'
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
INF = 10 ** 18
import math

def highestPowerof2(n):
	p = int(math.log(n, 2))
	return int(pow(2, p))
v = ['a', 'e', 'i', 'o', 'u']

def solve():
	n = sin()
	s = input()
	p = -1
	c = 0
	for i in range(n):
		if s[i] not in v:
			c += 1
		else:
			c = 0
		if c == 4:
			print('NO')
			return
	print('YES')
from collections import Counter
from collections import OrderedDict

def solve2():
	n = sin()
	a = input()
	b = input()
	if a == b or (a.count('1') > 0 and (b.count('00') > 0 or b.count('11') > 0)):
		print('YES')
	else:
		print('NO')
testisisisisisis = int(input())
for testis in range(testisisisisisis):
	solve2()


stringcasestes = int(input())
for _ in range(stringcasestes):
	numbersins = int(input())
	strone1 = str(input())
	strtwo2 = str(input())
	oneisone = 1
	if strone1 == strtwo2:
		print('YES')
	elif '1' not in strone1:
		if '1' in strtwo2:
			print('NO')
	elif '11' in strtwo2 or '00' in strtwo2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s = input()
	s0 = input()
	if s == s0:
		print('YES')
	elif s.count('1') == 0:
		print('NO')
	else:
		(temp, mode) = (s0[0], 1)
		for i in range(n - 1):
			if mode:
				if s0[0] == '1':
					temp += '0'
				else:
					temp += '1'
				mode = 0
			else:
				temp += s0[0]
				mode = 1
		if s0 == temp:
			print('NO')
		else:
			print('YES')


from collections import defaultdict, Counter, OrderedDict, deque
from heapq import heapify, heappop, heappush

def func():
	n = int(input())
	a = input()
	b = input()
	if '1' not in a:
		if '1' not in b:
			print('YES')
		else:
			print('NO')
	else:
		bl = True
		for i in range(1, n):
			if b[i] == b[i - 1]:
				bl = False
		if bl:
			if a == b:
				print('YES')
			else:
				print('NO')
		else:
			print('YES')
tc = int(input())
while tc > 0:
	func()
	tc -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	f = 0
	if a == b:
		print('YES')
		continue
	if b.count('1') and (not a.count('1')):
		print('NO')
	else:
		for j in range(len(b) - 1):
			if b[j] == b[j + 1]:
				f = 1
				break
		if f == 1:
			print('YES')
		else:
			print('NO')


import sys
input = sys.stdin.readline
testcase = int(input())
while testcase:
	testcase -= 1
	n = int(input())
	s1 = input()
	s2 = input()
	ind = -1
	for i in range(n):
		if s1[i] == '1':
			ind = i
			break
	ct1 = 0
	ct2 = 0
	for i in range(n):
		if s1[i] == '1':
			ct1 += 1
		if s2[i] == '1':
			ct2 += 1
	if s1 == s2:
		print('YES')
	elif ind == -1:
		print('NO')
	else:
		a1 = ''
		a2 = ''
		for i in range(n):
			if i % 2 == 0:
				a1 += '1'
				a2 += '0'
			else:
				a1 += '0'
				a2 += '1'
		s22 = ''
		for i in range(n):
			s22 += s2[i]
		if s22 == a1:
			print('NO')
		elif s22 == a2:
			print('NO')
		else:
			print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
		continue
	a0 = a1 = 0
	b0 = b1 = 0
	for i in range(n):
		if a[i] == '0':
			a0 += 1
		else:
			a1 += 1
		if b[i] == '0':
			b0 += 1
		else:
			b1 += 1
	if a1 == 0 and b1 > 0:
		print('NO')
		continue
	flag = 0
	for i in range(n - 1):
		if b[i] == b[i + 1]:
			flag = 1
			break
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	N9 = int(input())
	A9 = input()
	B9 = input()
	if A9 == B9:
		print('YES')
	elif '1' not in A9:
		if '1' in B9:
			print('NO')
	elif '11' in B9 or '00' in B9:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	lt = input()
	rt = input()
	onesa = sum((int(x) for x in lt))
	onesb = sum((int(x) for x in rt))
	if onesa == 0 and onesb > 0:
		print('NO')
		continue
	if len(lt) == 2 and onesa == 1 and (onesb == 1) and (lt[0] != rt[0]):
		print('NO')
		continue
	(flaga, flagb) = (True, lt[0] == rt[0])
	for i in range(1, len(lt)):
		if rt[i] == rt[i - 1]:
			flaga = False
			break
		if rt[i] != lt[i]:
			flagb = False
	if flaga and (not flagb):
		print('NO')
		continue
	print('YES')


for _ in range(int(input())):
	N1 = int(input())
	A1 = input()
	B1 = input()
	if A1 == B1:
		print('YES')
	elif '1' not in A1:
		if '1' in B1:
			print('NO')
	elif '11' in B1 or '00' in B1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	N = int(input())
	A = input()
	B = input()
	if A == B:
		print('YES')
	elif '1' not in A:
		if '1' in B:
			print('NO')
	elif '11' in B or '00' in B:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	if b.count('0') != n and a.count('0') == n:
		print('NO')
	elif b.count('0') == n:
		print('YES')
	elif b.count('1') == n and a.count('0') != n:
		print('YES')
	else:
		(check, flag) = (False, False)
		for i in range(n):
			if a[i] != b[i]:
				check = True
				break
		if check:
			for i in range(n - 1):
				if b[i] == b[i + 1]:
					flag = True
					break
			if flag:
				if a.count('0') != n:
					print('YES')
				else:
					print('NO')
			else:
				print('NO')
		else:
			print('YES')


for i in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	if s1 == s2:
		print('YES')
	elif '1' not in s1:
		if '1' in s2:
			print('NO')
	elif '11' in s2 or '00' in s2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	s = str()
	s1 = str()
	for i in range(n):
		if i % 2 == 0:
			s += '1'
			s1 += '0'
		else:
			s += '0'
			s1 += '1'
	if a == b:
		print('YES')
	else:
		z = 0
		for i in range(n):
			if a[i] == '0':
				z += 1
		if z == n:
			print('NO')
		elif b == s:
			print('NO')
		elif b == s1:
			print('NO')
		else:
			print('YES')


def solvemypuzzle():
	n = int(input())
	stringa = input()
	stringb = input()
	check = False
	if stringa == stringb:
		return 'YES'
	for i in range(n):
		if stringa[i] == '1':
			check = True
	if not check:
		return 'NO'
	check = False
	for i in range(1, n):
		if stringb[i] == stringb[i - 1]:
			check = True
	if check:
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solvemypuzzle())


for _ in range(int(input())):
	n = int(input())
	(s1, s2) = (input(), input())
	if s1 == s2:
		print('YES')
		continue
	if s1.count('1') == 0:
		print('YES') if s2.count('1') == 0 else print('NO')
		continue
	(mode, found) = (s2[0], True)
	for i in s2:
		if i != mode:
			print('YES')
			found = False
			break
		mode = '0' if mode == '1' else '1'
	if found:
		print('NO')


import math
import collections
for _ in range(int(input())):
	N = int(input())
	A = input()
	B = input()
	if A == B:
		print('YES')
	elif A.count('1'):
		ans = 0
		for i in range(N - 1):
			if B[i] == '0' and B[i + 1] == '0' or (B[i] == '1' and B[i + 1] == '1'):
				ans = 1
		if ans:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = input()
	if 'dfvjdgjtr9tv' == 4344343:
		print('Tanmay')
	b = input()
	if a == b:
		print('YES')
		continue
	if a == '0' * n:
		print('NO')
		continue
	c = b[0]
	s = ''
	if c == '1':
		s = '10' * (n // 2)
		if n % 2 != 0:
			s += '1'
	else:
		s = '01' * (n // 2)
		if n % 2 != 0:
			s += '0'
	if s == b:
		print('NO')
		continue
	print('YES')


def BinToDec(value):
	return int(value, 2)
t = int(input())
for tt in range(t):
	n = int(input())
	a = input()
	b = input()
	a_dec = BinToDec(a)
	flag = 0
	if a == b:
		print('YES')
	elif a_dec == 0:
		print('NO')
	else:
		for i in range(n - 1):
			if b[i] == b[i + 1]:
				flag = 1
				break
		if flag == 1:
			print('YES')
		else:
			print('NO')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = input()
	b = input()
	if n == 1:
		if a == b:
			print('YES')
		else:
			print('NO')
	elif a == b:
		print('YES')
	else:
		x = '0' * n
		if a == x:
			print('NO')
		else:
			flag = 0
			for i in range(n - 1):
				if b[i] == b[i + 1]:
					flag = 1
					print('YES')
					break
			if flag == 0:
				print('NO')


for _ in range(int(input())):
	lengthOfBinaryString = int(input())
	binaryStringA = input().strip()
	binaryStringB = input().strip()
	if binaryStringA == binaryStringB:
		print('YES')
		continue
	tempString = ''
	for char in binaryStringA:
		tempString += '0'
	if tempString == binaryStringA:
		print('NO')
		continue
	elif tempString == binaryStringB:
		print('YES')
		continue
	consecutive = False
	previousChar = ''
	for char in binaryStringB:
		if char == previousChar:
			consecutive = True
			break
		previousChar = char
	if not consecutive:
		print('NO')
		continue
	print('YES')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
	elif a.count('1') == 0:
		print('NO')
	else:
		z = 0
		for i in range(len(b) - 1):
			if b[i] == b[i + 1]:
				z += 1
				break
		if z == 1:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(str(input()))
	b = list(str(input()))
	alter = [[], []]
	for i in range(n):
		alter[0].append('0') if i % 2 == 0 else alter[0].append('1')
		alter[1].append('1') if i % 2 == 0 else alter[1].append('0')
	if b == alter[0] or b == alter[1]:
		print('YES') if a == b else print('NO')
	elif a.count('1') >= 1:
		print('YES')
	elif a == b:
		print('YES')
	else:
		print('NO')


def li(s):
	l = []
	for x in s:
		l.append(x)
	return l
for _ in range(int(input())):
	n = int(input())
	a = str(input())
	b = str(input())
	(a, b) = (li(a), li(b))
	alter = [[], []]
	for i in range(n):
		alter[0].append('0') if i % 2 == 0 else alter[0].append('1')
		alter[1].append('1') if i % 2 == 0 else alter[1].append('0')
	if b == alter[0] or b == alter[1]:
		print('YES') if a == b else print('NO')
	elif a.count('1') >= 1:
		print('YES')
	elif a == b:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	n = int(input())
	a = input()
	b = input()
	one = 0
	alt = 1
	eq = 1
	for i in range(0, n):
		if a[i] != b[i]:
			eq = 0
		if a[i] == '1':
			one = 1
		if i + 1 < n and b[i] == b[i + 1]:
			alt = 0
	if eq:
		print('YES')
	elif one == 1 and alt == 0:
		print('YES')
	else:
		print('NO')
	t = t - 1


def xo(n, a, b):
	ca = cb = 0
	for i in range(n):
		if a[i] == '1':
			ca += 1
		if b[i] == '1':
			cb += 1
	if a == b:
		print('YES')
		return
	if ca > 0:
		f = 0
		for i in range(1, n):
			if b[i] == b[i - 1]:
				f = 1
		if f == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
	return
t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	xo(n, a, b)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
	elif a == '0' * n:
		print('NO')
	else:
		lf = b[0]
		c = 1
		for i in range(1, n):
			cf = b[i]
			if cf == lf:
				c += 1
			else:
				c = 1
			if c > 1:
				print('YES')
				break
			lf = cf
		else:
			print('NO')


t = int(input())
for k in range(t):
	n = int(input())
	a = input()
	b = input()
	cnt1 = 0
	cnt2 = 0
	for i in range(n):
		if a[i] == '1':
			cnt1 += 1
		if b[i] == '1':
			cnt2 += 1
	if cnt1 == 0 and cnt2 != 0:
		print('NO')
		continue
	if cnt1 == 0 and cnt2 == 0:
		print('YES')
		continue
	if cnt1 != 0 and cnt2 == 0:
		print('YES')
		continue
	same = True
	for i in range(n):
		if a[i] != b[i]:
			same = False
			break
	if same == True:
		print('YES')
		continue
	cur = b[0]
	flag = True
	need = ''
	if cur == '0':
		need = '1'
	else:
		need = '0'
	for i in range(1, n):
		if b[i] != need:
			flag = False
			break
		if need == '1':
			need = '0'
		else:
			need = '1'
	if flag == True:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	A = input()
	B = input()
	if A == B:
		print('YES')
		continue
	a = int(A[-1])
	b = 0
	for i in range(n - 1):
		a += int(A[i])
		if B[i] == B[i + 1]:
			b += 1
	if a > 0 and b > 0:
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
	else:
		hasOne = False
		for char in a:
			if char == '1':
				hasOne = True
				break
		alterating = True
		for i in range(1, len(b)):
			if b[i] == b[i - 1]:
				alterating = False
		if hasOne and (not alterating):
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	a = str(input())
	b = str(input())
	s = list(a)
	ss = list(b)
	if a == b:
		print('YES')
		continue
	if '1' not in s and '1' in ss:
		print('NO')
		continue
	(x, y) = ('', '')
	fl = 0
	for i in range(n):
		x += str(fl)
		y += str(fl ^ 1)
		fl ^= 1
	if x != b and y != b:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
	else:
		one_zero = ''
		zero_one = ''
		for j in range(n):
			if j & 1:
				one_zero += '1'
				zero_one += '0'
			else:
				one_zero += '0'
				zero_one += '1'
		num = a.count('1')
		if b == one_zero or b == zero_one or num == 0:
			print('NO')
		else:
			print('YES')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
		continue
	oz = ''
	zo = ''
	for i in range(n):
		if i & 1:
			oz += '1'
			zo += '0'
		else:
			oz += '0'
			zo += '1'
	count = a.count('1')
	if count >= 1:
		if b == oz or b == zo:
			if a == b:
				print('YES')
			else:
				print('NO')
		else:
			print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	x = a.count('1')
	y = b.count('1')
	if x == 0 and y > 0:
		print('NO')
	else:
		s1 = ''
		s2 = ''
		for i in range(n):
			if i % 2 == 0:
				s1 = s1 + '1'
				s2 = s2 + '0'
			else:
				s1 = s1 + '0'
				s2 = s2 + '1'
		if a == b:
			print('YES')
		elif b == s1 or b == s2:
			print('NO')
		else:
			print('YES')


def main():
	for _ in range(int(input())):
		N = int(input())
		test_string = list(input())
		final_string = list(input())
		zero_one = []
		one_zero = []
		for i in range(N):
			if i % 2 == 0:
				zero_one += '0'
				one_zero += '1'
			else:
				zero_one += '1'
				one_zero += '0'
		if test_string.count('1') > 0:
			if final_string == zero_one or final_string == one_zero:
				if test_string == final_string:
					print('YES')
				else:
					print('NO')
			else:
				print('YES')
		elif test_string == final_string:
			print('YES')
		else:
			print('NO')
	return 0
main()


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
	elif a.count('1') > 0:
		c1 = '01' * ((n + 1) // 2)
		c2 = '10' * ((n + 1) // 2)
		if b == c1[:n] or b == c2[:n]:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
	elif a == '0' * n:
		print('NO')
	elif '00' not in b and '11' not in b:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
M = int(1000000000.0) + 7

def solve():
	n = int(input())
	a = input().strip('\n')
	b = input().strip('\n')
	if a == b:
		return 'YES'
	if '1' not in a:
		return 'NO'
	for i in range(n - 1):
		if b[i] == b[i + 1]:
			return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solve())


for _ in range(int(input())):
	N = int(input())
	A = input()
	B = input()
	one_zero = ''
	zero_one = ''
	for i in range(N):
		if i % 2 == 0:
			zero_one += '0'
			one_zero += '1'
		else:
			zero_one += '1'
			one_zero += '0'
	count = A.count('1')
	if count > 0:
		if (B == one_zero or B == zero_one) and A == B:
			print('YES')
		elif (B == one_zero or B == zero_one) and A != B:
			print('NO')
		else:
			print('YES')
	elif A == B:
		print('YES')
	else:
		print('NO')


def solver(n, A, B):
	if A == B:
		return 'YES'
	ones_in_A = A.count('1')
	ones_in_B = B.count('1')
	if ones_in_B == 0:
		return 'YES'
	elif ones_in_A == 0:
		return 'NO'
	else:
		consecutive = False
		for i in range(1, n):
			if B[i - 1] == B[i]:
				consecutive = True
				break
		return 'YES' if consecutive else 'NO'
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	A = input()
	B = input()
	print(solver(n, A, B))


for _ in range(int(input())):
	l = int(input())
	s1 = input()
	s2 = input()
	c = 0
	if s1 == s2:
		print('YES')
	elif '1' not in s1:
		if '1' in s2:
			print('NO')
	elif '00' in s2 or '11' in s2:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
	elif a != b and a.count('0') == len(a):
		print('NO')
	elif '11' in b or '00' in b:
		print('YES')
	else:
		print('NO')


def consecutive_in(a, n):
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			return True
	return False

def one_in(a, n):
	for i in range(n):
		if a[i] == '1':
			return True
	return False
t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	if consecutive_in(b, n) and (one_in(a, n) or not one_in(b, n)) or b == a:
		print('YES')
	else:
		print('NO')


from heapq import heapify, heappush, heappop
from collections import deque
import sys
from math import gcd, sqrt, log10, log2, floor, ceil, sqrt
from tkinter.tix import Tree
input = sys.stdin.readline

def il():
	return [int(a) for a in input().strip().split()]

def ip():
	return input().strip()

def ii():
	return int(input())

def ot(in_p, *args, e=' '):
	if type(in_p) == list:
		print(*in_p, end=e)
	if type(in_p) == str or type(in_p) == int:
		print(in_p, end=e)
		for l in args:
			print(l, end=e)
	print()

def a_pwr_n(a, n, mod):
	if n == 1:
		return a % mod
	if n % 2 == 0:
		val = a_pwr_n(a, n // 2, mod)
		return val % mod * val % mod
	else:
		return a % mod * a_pwr_n(a, n - 1, mod) % mod

def rg(*ag):
	if len(ag) == 3:
		return range(ag[0], ag[1], ag[2])
	elif len(ag) == 2:
		return range(ag[0], ag[1])
	elif len(ag) == 1:
		return range(ag[0])
	else:
		raise 'invalid input'

def ispal(i, j, st):
	while i <= j:
		if st[i] == st[j]:
			i = i + 1
			j = j - 1
		else:
			return False
	return True
mod = 1000000000 + 7
dx = [-1, -2, 1, 2, 2, -2, -1, 1]
dy = [2, 1, 2, 1, -1, -1, -2, -2]
for _ in range(ii()):
	n = ii()
	s1 = ip()
	s2 = ip()
	f = False
	for i in range(n - 1):
		if s2[i] == s2[i + 1]:
			f = True
			break
	if s1 == s2 or (s1.find('1') >= 0 and f):
		print('YES')
	else:
		print('NO')


st = '10' * 50010
for i in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	l = list(s1)
	if s1 == s2:
		print('YES')
		continue
	one = s1.count('1')
	on = s2.count('1')
	if n == 2:
		if s1 == '00':
			print('NO')
		elif s1 == '11' and (s2 == '10' or s2 == '01'):
			print('NO')
		elif s1 == '10' and s2 == '01' or (s1 == '01' and s2 == '10'):
			print('NO')
		else:
			print('YES')
	elif s1.count('1') == 0:
		print('NO')
	else:
		c = s2[0]
		for j in s2[1:]:
			if j == c:
				print('YES')
				break
			c = j
		else:
			print('NO')


for _ in range(int(input())):
	N = int(input())
	s = input()
	t = input()
	(cnt1, cnt2) = (s.count('1'), t.count('1'))
	if cnt1 == 0 and cnt2:
		print('NO')
		continue
	ok = False
	for i in range(1, N):
		ok |= t[i] == t[i - 1]
	print('YES' if ok or s == t else 'NO')


T = int(input())
while T > 0:
	n = int(input())
	str1 = input()
	str2 = input()
	flag = True
	for i in range(1, n):
		if str2[i] == str2[i - 1]:
			flag = False
	if flag:
		if str1 == str2:
			print('YES')
		else:
			print('NO')
	elif int(str1) == 0 and int(str2) != 0:
		print('NO')
	else:
		print('YES')
	T -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	one_count = 0
	for i in range(n):
		one_count += a[i] == '1'
	consecutive_same = 0
	for i in range(n - 1):
		consecutive_same += b[i] == b[i + 1]
	if one_count > 0 and consecutive_same > 0 or a == b:
		print('YES')
	else:
		print('NO')


from math import inf
from collections import *
import math, os, sys, heapq, bisect, random, threading
from functools import lru_cache
from itertools import *

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def inpu():
	return int(inp())

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())
(M, M1) = (1000000007, 998244353)

def main():
	how_much_noob_I_am = 1
	how_much_noob_I_am = inpu()
	for _ in range(how_much_noob_I_am):
		n = inpu()
		s = inp()
		t = inp()
		if s == t:
			print('YES')
			continue
		p = '10' * n
		p = p[:n]
		q = '01' * n
		q = q[:n]
		if t == p or t == q:
			print('NO')
			continue
		if '1' not in s and '1' in t:
			print('NO')
		else:
			print('YES')
main()


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
	elif '1' in a and ('00' in b or '11' in b):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	A = input()
	B = input()
	if A == B:
		print('YES')
		continue
	elif int('0b' + A, 2) == 0:
		print('NO')
		continue
	flag = int(B[0])
	ff = 1
	for i in range(n):
		if flag != int(B[i]):
			ff = 0
			break
		flag ^= 1
	if ff:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if a == b:
		print('YES')
	elif n == 1:
		print('NO')
	else:
		a1 = 0
		b1 = 0
		for i in range(n):
			if a[i] == '1':
				a1 += 1
			if b[i] == '1':
				b1 += 1
		if a1 == 0 and b1 > 0:
			print('NO')
		else:
			for i in range(1, n):
				if b[i - 1] == b[i]:
					print('YES')
					break
			else:
				print('NO')