You are given a system of pipes. It consists of two rows, each row consists of $n$ pipes. The top left pipe has the coordinates $(1, 1)$ and the bottom right — $(2, n)$.

There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types:

 [Image] Types of pipes 

You can turn each of the given pipes $90$ degrees clockwise or counterclockwise arbitrary (possibly, zero) number of times (so the types $1$ and $2$ can become each other and types $3, 4, 5, 6$ can become each other).

You want to turn some pipes in a way that the water flow can start at $(1, 0)$ (to the left of the top left pipe), move to the pipe at $(1, 1)$, flow somehow by connected pipes to the pipe at $(2, n)$ and flow right to $(2, n + 1)$.

Pipes are connected if they are adjacent in the system and their ends are connected. Here are examples of connected pipes:

 [Image] Examples of connected pipes 

Let's describe the problem using some example:

 [Image] The first example input 

And its solution is below:  [Image] The first example answer 

As you can see, the water flow is the poorly drawn blue line. To obtain the answer, we need to turn the pipe at $(1, 2)$ $90$ degrees clockwise, the pipe at $(2, 3)$ $90$ degrees, the pipe at $(1, 6)$ $90$ degrees, the pipe at $(1, 7)$ $180$ degrees and the pipe at $(2, 7)$ $180$ degrees. Then the flow of water can reach $(2, n + 1)$ from $(1, 0)$.

You have to answer $q$ independent queries.


-----Input-----

The first line of the input contains one integer $q$ ($1 \le q \le 10^4$) — the number of queries. Then $q$ queries follow.

Each query consists of exactly three lines. The first line of the query contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of pipes in each row. The next two lines contain a description of the first and the second rows correspondingly. Each row description consists of $n$ digits from $1$ to $6$ without any whitespaces between them, each digit corresponds to the type of pipe in the corresponding cell. See the problem statement to understand which digits correspond to which types of pipes.

It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$.


-----Output-----

For the $i$-th query print the answer for it — "YES" (without quotes) if it is possible to turn some pipes in a way that the water flow can reach $(2, n + 1)$ from $(1, 0)$, and "NO" otherwise.


-----Example-----
Input
6
7
2323216
1615124
1
3
4
2
13
24
2
12
34
3
536
345
2
46
54

Output
YES
YES
YES
NO
YES
NO



-----Note-----

The first query from the example is described in the problem statement.

Difficulty: MEDIUM
Tags: Dynamic programming

Implementation
Skill types: Dynamic programming

Starter code:

Solutions:
def pipetype(i):
	if i == '1' or i == '2':
		return 1
	else:
		return 2

def find_way2(arr, n):
	count = 0
	row = 0
	col = 0
	prev_row = 0
	prev_col = -1
	prev_state = 1
	while col <= n:
		count += 1
		prev_i = row
		prev_j = col
		if col == n and row == 0:
			return 'NO'
		elif col == n and row == 1:
			return 'YES'
		if pipetype(arr[row][col]) == 1:
			if row == prev_row:
				col += 1
			else:
				return 'NO'
		elif pipetype(arr[row][col]) == 2:
			if row == 0 and prev_row == 0:
				row += 1
			elif row == 0 and prev_row == 1:
				col += 1
			elif row == 1 and prev_row == 0:
				col += 1
			elif row == 1 and prev_row == 1:
				row -= 1
		prev_row = prev_i
		prev_col = prev_j
	return 'YES'
for i in range(int(input())):
	n = int(input())
	arr = [input()]
	arr.append(input())
	print(find_way2(arr, n))


import sys
import os
from io import IOBase, BytesIO

def main():
	for tc in range(int(input())):
		n = int(input())
		s1 = list(input())
		s2 = list(input())
		(s, f) = (1, 0)
		for i in range(n):
			if s == 1:
				if s1[i] == '1' or s1[i] == '2':
					continue
				elif s2[i] == '1' or s2[i] == '2':
					f = 1
					break
				else:
					s = 0
			elif s2[i] == '1' or s2[i] == '2':
				continue
			elif s1[i] == '1' or s1[i] == '2':
				f = 1
				break
			else:
				s = 1
			if f == 1:
				break
		if s == 0 and f == 0:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2 == 1:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip()
main()


import sys
from heapq import heappop
from heapq import heappush
from heapq import heapify
from bisect import insort
from bisect import bisect_right
from bisect import bisect_left
from sys import stdin, stdout
from collections import defaultdict
inp = lambda : int(stdin.readline())
sip = lambda : input()
mulip = lambda : map(int, input().split())
lst = lambda : list(map(int, stdin.readline().split()))
slst = lambda : list(sip())
arr2d = lambda x: [[int(j) for j in input().split()] for i in range(x)]
odds = lambda l: len(list(filter(lambda x: x % 2 != 0, l)))
evens = lambda l: len(list(filter(lambda x: x % 2 == 0, l)))
mod = pow(10, 9) + 7
for _ in range(inp()):
	n = inp()
	s1 = list(input())
	s2 = list(input())
	l = []
	l.append(s1)
	l.append(s2)
	r = 0
	i = 0
	while i < n:
		if int(l[r][i]) > 2:
			if int(l[r ^ 1][i]) < 3:
				break
			else:
				r = r ^ 1
		i += 1
	if r == 1 and i == n:
		print('YES')
	else:
		print('NO')


st = ['1', '2']
tera = ['3', '4', '5', '6']
for _ in range(int(input())):
	n = int(input())
	li = [input()]
	li.append(input())
	j = 0
	i = 0
	flag = 1
	while i < n:
		if li[j][i] in st:
			i += 1
		elif j == 0:
			if li[1][i] not in tera:
				flag = 0
				break
			else:
				j = 1
				i += 1
		elif li[0][i] not in tera:
			flag = 0
			break
		else:
			j = 0
			i += 1
	if flag == 1 and j == 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	n = int(input())
	(lx, ly) = (0, -1)
	(x, y) = (0, 0)
	s = [['1'] + list(input().rstrip()) for _ in range(2)]
	visit = [[0] * (n + 1) for _ in range(2)]
	while 0 <= x < 2 and 0 <= y < n + 1:
		if visit[x][y]:
			break
		visit[x][y] = 1
		if int(s[x][y]) <= 2:
			(nx, ny) = (2 * x - lx, 2 * y - ly)
		elif abs(x - lx):
			(nx, ny) = (x, y + 1)
		else:
			(nx, ny) = (x ^ 1, y)
		(lx, ly) = (x, y)
		(x, y) = (nx, ny)
	ans = 'YES' if x == 1 and y == n + 1 else 'NO'
	print(ans)


q = int(input())
for _ in range(q):
	n = int(input())
	s1 = input()
	s2 = input()
	i = 0
	current = 0
	flag = 0
	while i < n - 1:
		if current == 0:
			if s1[i] == '3' or s1[i] == '4' or s1[i] == '5' or (s1[i] == '6'):
				current = 1
				if s2[i] == '1' or s2[i] == '2':
					print('NO')
					flag = 1
					break
		elif s2[i] == '3' or s2[i] == '4' or s2[i] == '5' or (s2[i] == '6'):
			current = 0
			if s1[i] == '1' or s1[i] == '2':
				print('NO')
				flag = 1
				break
		i += 1
	if flag == 1:
		continue
	if current == 0:
		if s1[i] == '3' or s1[i] == '4' or s1[i] == '5' or (s1[i] == '6'):
			if s2[i] == '3' or s2[i] == '4' or s2[i] == '5' or (s2[i] == '6'):
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	elif s2[i] == '1' or s2[i] == '2':
		print('YES')
	else:
		print('NO')


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	list_map = [sys.stdin.readline().strip() for _ in range(2)]
	list_memo = [[[0] * 5 for _ in range(N + 1)] for _ in range(2)]
	list_memo[0][-1][0] = 1
	for i in range(N):
		for j in range(2):
			now = list_map[j][i]
			if now == '2' or now == '1':
				list_memo[j][i][0] = max(list_memo[j][i - 1][0], list_memo[j][i - 1][1], list_memo[j][i - 1][4])
			else:
				list_memo[j][i][3] = max(list_memo[j][i - 1][0], list_memo[j][i - 1][4])
				list_memo[j][i][2] = max(list_memo[j][i - 1][0], list_memo[j][i - 1][1])
				list_memo[j][i][1] = max(list_memo[1][i - 1][0], list_memo[1][i - 1][4]) if j == 0 and list_map[1][i] > '2' else 0
				list_memo[j][i][4] = max(list_memo[0][i - 1][0], list_memo[0][i - 1][1]) if j == 1 and list_map[0][i] > '2' else 0
	print('YES' if max(list_memo[1][N - 1][0], list_memo[1][N - 1][4]) else 'NO')


q = int(input())
pipe = {'1': 1, '2': 1, '3': 2, '4': 2, '5': 2, '6': 2}
for i in range(0, q):
	n = int(input())
	a = input()
	b = input()
	flag = True
	if pipe[a[0]] == 2 and pipe[b[0]] == 1:
		print('NO')
		continue
	dir = pipe[a[0]]
	flag = True
	for j in range(1, len(a)):
		if dir == 1:
			if pipe[a[j]] == 1:
				continue
			elif pipe[a[j]] != pipe[b[j]]:
				flag = False
				break
			else:
				dir = 2
		elif dir == 2:
			if pipe[b[j]] == 1:
				continue
			elif pipe[a[j]] != pipe[b[j]]:
				flag = False
				break
			else:
				dir = 1
	if flag and dir == 2:
		print('YES')
	else:
		print('NO')


from collections import deque
from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a1 = input()
	b1 = input()
	a = []
	b = []
	for i in range(n):
		a.append(int(a1[i]))
		b.append(int(b1[i]))
	x = 0
	ans = 'YES'
	for i in range(n):
		if i == n - 1:
			if x:
				if not (b[i] == 1 or b[i] == 2):
					ans = 'NO'
			elif a[i] == 1 or a[i] == 2 or b[i] == 1 or (b[i] == 2):
				ans = 'NO'
		if not x:
			if a[i] == 1 or a[i] == 2:
				continue
			elif b[i] == 1 or b[i] == 2:
				ans = 'NO'
				break
			else:
				x ^= 1
		elif b[i] == 1 or b[i] == 2:
			continue
		elif a[i] == 1 or a[i] == 2:
			ans = 'NO'
			break
		else:
			x ^= 1
	print(ans)


for case in range(int(input())):
	n = int(input())
	l1 = list(input())
	l2 = list(input())
	l1.insert(0, 0)
	l2.insert(0, 0)
	l = [0, l1, l2]
	itr = (1, 1)
	dirt = 1
	fir = True
	fl = False
	while True:
		if itr[1] > n:
			if itr == (2, n + 1):
				fl = True
				break
			elif fir:
				dirt == -1
				itr = (1, 1)
				fir = False
			else:
				break
		if l[itr[0]][itr[1]] == '1' or l[itr[0]][itr[1]] == '2':
			if dirt == 1:
				itr = (itr[0], itr[1] + 1)
			else:
				break
		else:
			if itr[0] == 2 and dirt == 1:
				itr = (1, itr[1])
			elif itr[0] == 1 and dirt == 1:
				itr = (2, itr[1])
			elif dirt == -1:
				itr = (itr[0], itr[1] + 1)
			dirt = -dirt
	print('Yes' if fl else 'No')


a = int(input())
for _ in range(a):
	n = int(input())
	a = input()
	b = input()
	fg = 0
	fk = 1
	for i in range(n):
		if int(a[i]) / 2 > 1 and int(b[i]) / 2 <= 1 or (int(a[i]) / 2 <= 1 and int(b[i]) / 2 > 1):
			if not (int(a[i]) / 2 <= 1 and fk == 1 or (int(b[i]) / 2 <= 1 and fk == 2)):
				print('NO')
				fg = 1
				break
		elif int(a[i]) / 2 > 1 and int(b[i]) / 2 > 1:
			fk = 3 - fk
	if fg == 0 and fk == 2:
		print('YES')
	elif fg == 0 and fk == 1:
		print('NO')


q = int(input())
for _ in range(q):
	pipes = [[], []]
	length = int(input())
	currentX = 0
	currentY = 0
	pipes[0] = input()
	pipes[1] = input()
	hrzn = True
	while 1:
		if currentX == 1 and currentY == length - 1:
			if hrzn and pipes[currentX][currentY] in ('1', '2') or (not hrzn and pipes[currentX][currentY] not in ('1', '2')):
				print('YES')
				break
			else:
				print('NO')
				break
		elif currentY > length - 1:
			print('NO')
			break
		if pipes[currentX][currentY] in ('1', '2'):
			if hrzn:
				currentY += 1
			else:
				print('NO')
				break
		else:
			if hrzn:
				currentX += 1
				currentX %= 2
			else:
				currentY += 1
			hrzn = not hrzn


t = int(input())
for _ in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	s = [s1, s2]
	(tp1, tp2) = (['1', '2'], ['3', '4', '5', '6'])
	cur = 0
	for i in range(n):
		if s[cur][i] in tp1:
			continue
		elif s[1 - cur][i] in tp2:
			cur = 1 - cur
		else:
			print('NO')
			break
	else:
		if cur == 1:
			print('YES')
		else:
			print('NO')


import re, math, decimal, bisect

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

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]

def round(n):
	return int(n + 0.5)
DEBUG = 1
DEBUG = 0

def debug(*args, **kwargs):
	if DEBUG:
		print(*args, **kwargs)
q = iread()
for _ in range(q):
	n = iread()
	row = [read(), read()]
	now = 0
	ans = 'YES'
	for i in range(n):
		if row[now][i] > '2' and row[now ^ 1][i] <= '2':
			ans = 'NO'
			break
		elif row[now][i] > '2':
			now ^= 1
	if ans != 'NO' and now != 1:
		ans = 'NO'
	print(ans)


t = int(input())
for i in range(t):
	l = int(input())
	row1 = list(input())
	for i in range(l):
		row1[i] = int(row1[i])
	row2 = list(input())
	for i in range(l):
		row2[i] = int(row2[i])
	curr = 0
	pipes = [[0] * l for i in range(2)]
	flag = 0
	for i in range(2):
		for j in range(l):
			if i == 0:
				pipes[i][j] = row1[j]
			else:
				pipes[i][j] = row2[j]
	i = 0
	while i < l - 1:
		if pipes[curr][i] == 1 or pipes[curr][i] == 2:
			i += 1
		else:
			curr = 1 - curr
			if pipes[curr][i] == 1 or pipes[curr][i] == 2:
				print('NO')
				flag = 1
				break
			else:
				i += 1
	if flag == 1:
		continue
	delta = 0
	if curr == 1:
		if pipes[curr][l - 1] == 1 or pipes[curr][l - 1] == 2:
			delta = 1
	elif curr == 0:
		if pipes[curr][l - 1] == 3 or pipes[curr][l - 1] == 4 or pipes[curr][l - 1] == 5 or (pipes[curr][l - 1] == 6):
			curr = 1
			if pipes[curr][l - 1] == 3 or pipes[curr][l - 1] == 4 or pipes[curr][l - 1] == 5 or (pipes[curr][l - 1] == 6):
				delta = 1
	if delta == 1:
		print('YES')
	else:
		print('NO')


q = int(input())
for hoho in range(q):
	n = int(input())
	a = [input(), input()]
	x = 0
	y = 0
	income = 1
	flag = True
	while x < 2 and y < n:
		if income == 1:
			if a[x][y] == '1' or a[x][y] == '2':
				y = y + 1
			elif x == 0:
				x = 1
				income = 2
			else:
				x = 0
				income = 4
		elif income == 2:
			if a[x][y] == '1' or a[x][y] == '2':
				flag = False
				break
			elif x == 0:
				flag = False
				break
			else:
				y += 1
				income = 1
		elif income == 4:
			if a[x][y] == '1' or a[x][y] == '2':
				flag = False
				break
			elif x == 0:
				y += 1
				income = 1
			else:
				flag = False
				break
	if x == 1 and y == n and flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	lines = (tuple(map(int, tuple(input()))), tuple(map(int, tuple(input()))))
	line = 0
	i = 0
	fl = False
	switch = False
	while i != n:
		if lines[line][i] < 3:
			i += 1
			switch = False
		elif lines[1 - line][i] > 2 and (not switch):
			line = 1 - line
			switch = True
		elif switch:
			i += 1
			switch = False
		else:
			fl = True
			print('NO')
			break
	if fl:
		continue
	if line == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	s = [int(x) for x in input()]
	t = [int(x) for x in input()]
	old = [1, 0]
	for i in range(n):
		new = [0, 0]
		if s[i] == 1:
			new[0] = old[0]
		if s[i] == 2:
			new[0] = old[0]
		if t[i] == 1:
			new[1] = old[1]
		if t[i] == 2:
			new[1] = old[1]
		if t[i] in (3, 4, 5, 6) and s[i] in (3, 4, 5, 6):
			new[0] = old[1]
			new[1] = old[0]
		old = new
	print('YES' if old[1] else 'NO')


q = int(input())
f = lambda : [*map(int, list(input()))]
A = [1, 2]
B = [3, 4, 5, 6]
for i in range(q):
	size = int(input())
	pipes = [f(), f()]
	k = 0
	level = 0
	B_is_first_on_this_level = False
	must_be_B = False
	while k <= size:
		if k == size and level == 1:
			print('YES')
			break
		elif k == size:
			print('NO')
			break
		else:
			if B_is_first_on_this_level:
				if pipes[level][k] not in B:
					print('NO')
					break
				else:
					B_is_first_on_this_level = False
					k += 1
					continue
			if pipes[level][k] in A:
				k += 1
				continue
			if pipes[level][k] in B:
				level ^= 1
				B_is_first_on_this_level = True
				continue


def solve(n, T, B):
	X = [False for i in range(n)]
	Y = [False for i in range(n)]
	S = ['1', '2']
	C = ['3', '4', '5', '6']
	if T[0] in S:
		X[0] = True
		Y[0] = False
	elif T[0] in C and B[0] in C:
		X[0] = False
		Y[0] = True
	else:
		X[0] = False
		Y[0] = False
	for i in range(1, n):
		if X[i - 1] and T[i] in S or (Y[i - 1] and T[i] in C and (B[i] in C)):
			X[i] = True
		else:
			X[i] = False
		if Y[i - 1] and B[i] in S or (X[i - 1] and T[i] in C and (B[i] in C)):
			Y[i] = True
		else:
			Y[i] = False
	if Y[n - 1]:
		return 'YES'
	else:
		return 'NO'
q = int(input())
ans = []
for j in range(q):
	n = int(input())
	T = input()
	B = input()
	ans.append(solve(n, T, B))
print('\n'.join(ans))


from math import inf as inf
import sys
input = sys.stdin.readline
q = int(input())
for i in range(q):
	n = int(input())
	bends = [0] * n
	count = [0] * n
	two = 0
	l1 = [int(i) for i in input() if i != '\n']
	l2 = [int(i) for i in input() if i != '\n']
	for i in range(len(l1)):
		if l1[i] > 2:
			bends[i] += 1
	for i in range(len(l2)):
		if l2[i] > 2:
			bends[i] += 1
		if bends[i] == 2:
			two += 1
			count[i] += two
	last = 0
	if bends.count(2) % 2 == 1:
		for i in range(n):
			if count[i] > 0:
				last = count[i]
			if bends[i] == 1:
				if l1[i] > 2 and last % 2 == 0:
					print('NO')
					break
				elif l2[i] > 2 and last % 2 == 1:
					print('NO')
					break
		else:
			print('YES')
	else:
		print('NO')


import math
import copy
t = int(input())
for _ in range(t):
	n = int(input())
	x = input()
	y = input()
	r = 0
	for i in range(n):
		if r == 0:
			if x[i] == '1' or x[i] == '2':
				r = 0
			else:
				r = 1
				if y[i] == '1' or y[i] == '2':
					r = 0
					break
		elif y[i] == '1' or y[i] == '2':
			r = 1
		else:
			if x[i] == '1' or x[i] == '2':
				r = 0
				break
			r = 0
	if r == 1:
		print('YES')
	else:
		print('NO')


Q = int(input())
for q in range(Q):
	n = int(input())
	c1 = input()
	c2 = input()
	a = [[None] * n, [None] * n]
	for i in range(n):
		if c1[i] == '1' or c1[i] == '2':
			a[0][i] = 0
		else:
			a[0][i] = 1
		if c2[i] == '1' or c2[i] == '2':
			a[1][i] = 0
		else:
			a[1][i] = 1
	st = 0
	fg = 0
	for i in range(n):
		if a[st][i] == 0:
			continue
		elif a[(st + 1) % 2][i] != 1:
			print('NO')
			fg = 1
			break
		else:
			st = (st + 1) % 2
	if fg != 1:
		if st == 1:
			print('YES')
		else:
			print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	q = ['1', '2']
	w = ['3', '4', '5', '6']
	qw = 1
	c = 0
	i = 0
	while i < len(a):
		if a[i] in w:
			if b[i] in q:
				qw = 0
				break
			(a, b) = (b, a)
			c = c + 1
		i = i + 1
	if qw == 1 and c % 2 != 0:
		print('YES')
	else:
		print('NO')


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
for _ in range(ii()):
	n = ii()
	loc = 0
	rs = [input(), input()]
	c = 0
	di = 1
	while loc < n:
		if rs[c][loc] < 51:
			if not di:
				break
			loc += 1
		else:
			if not di:
				loc += 1
			else:
				c ^= 1
			di ^= 1
	print('YNEOS'[1 ^ (loc == n and c == di == 1)::2])


n = int(input())

def check(a):
	if a in ('3', '4', '5', '6'):
		return True
	else:
		return False
for qwer in range(n):
	k = int(input())
	s1 = input()
	s2 = input()
	temp = 1
	r = 0
	f = False
	i = 0
	while i < k:
		if temp == 1:
			if f:
				if check(s1[i]):
					f = False
					i += 1
				else:
					temp = 1
					break
			elif check(s1[i]):
				temp = 2
				f = True
			else:
				i += 1
				f = False
		elif f:
			if check(s2[i]):
				i += 1
				f = False
			else:
				temp = 1
				break
		elif check(s2[i]):
			temp = 1
			f = True
		else:
			i += 1
			f = False
	if temp == 2:
		print('YES')
	else:
		print('NO')


q = int(input())

class Pipes:

	def __init__(self):
		self.upper_pipe = []
		self.lower_pipe = []
pipes = []

def pipe_type(x):
	if int(x) <= 2:
		return 1
	else:
		return 2
for i in range(q):
	pipe = Pipes()
	input()
	pipe.upper_pipe = [pipe_type(x) for x in input()]
	pipe.lower_pipe = [pipe_type(x) for x in input()]
	pipes.append(pipe)
for pipe in pipes:
	in_upper = True
	result = 'YES'
	for i in range(len(pipe.lower_pipe)):
		if in_upper and pipe.upper_pipe[i] == 1 or (not in_upper and pipe.lower_pipe[i] == 1):
			pass
		elif pipe.upper_pipe[i] == 2 and pipe.lower_pipe[i] == 2:
			in_upper = not in_upper
		else:
			result = 'NO'
	if in_upper:
		result = 'NO'
	print(result)


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
for _ in range(int(cin())):
	n = int(cin())
	lst = [[None] * n for _ in range(2)]
	for i in range(2):
		lst[i] = cin()[:-1]
	(i, y, u) = (0, 0, 2)
	while i < n:
		if lst[y][i] < '3':
			if u == 2:
				i += 1
			else:
				cout('NO\n')
				break
		elif not y:
			if u == 1:
				u = 2
				i += 1
			elif u == 2:
				y += 1
				u = 0
			else:
				cout('NO\n')
				break
		elif y:
			if not u:
				u = 2
				i += 1
			elif u == 2:
				y -= 1
				u = 1
			else:
				cout('NO\n')
				break
		else:
			cout('NO\n')
			break
	else:
		if y:
			cout('YES\n')
		else:
			cout('NO\n')


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(2):
		a.append([int(i) for i in input()])
	if a[0][0] <= 2:
		cr = 0
		pr = 0
	else:
		cr = 1
		if a[1][0] <= 2:
			print('NO')
			continue
		pr = 1
	i = 1
	f = 1
	while i < n:
		if cr == 1:
			if pr == 1:
				if a[cr][i] <= 2:
					i += 1
				else:
					cr = 0
			else:
				if a[cr][i] <= 2:
					print('NO')
					f = 0
					break
				pr = 1
				i += 1
		elif pr == 0:
			if a[cr][i] <= 2:
				i += 1
			else:
				cr = 1
		else:
			if a[cr][i] <= 2:
				print('NO')
				f = 0
				break
			pr = 0
			i += 1
	if f:
		if pr == 1:
			print('YES')
		else:
			print('NO')


q = int(input())
for t in range(q):
	n = int(input())
	s = [[int(i) for i in list(input())] for j in range(2)]
	row = 0
	flag = 1
	for i in range(n):
		if s[row][i] >= 3:
			if s[1 - row][i] < 3:
				flag = 0
			else:
				row = 1 - row
	if flag and row == 1:
		print('YES')
	else:
		print('NO')


q = int(input())
while q:
	n = int(input())
	a = input()
	b = input()
	flag = True
	f1 = True
	for i in range(n):
		if f1:
			if a[i] in ['3', '4', '5', '6']:
				if b[i] in ['1', '2']:
					flag = False
					break
				else:
					f1 = False
		elif b[i] in ['3', '4', '5', '6']:
			if a[i] in ['1', '2']:
				flag = False
				break
			else:
				f1 = True
	if flag:
		if f1:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')
	q -= 1


q = int(input())
first = {1, 2}
second = {3, 4}
for _ in range(q):
	n = int(input())
	row1 = str(input())
	row2 = str(input())
	current = 2
	is_possible = True
	for i in range(n - 1):
		if current in first:
			if row1[i] in {'3', '4', '5', '6'}:
				current += 1
				if row2[i] not in {'3', '4', '5', '6'}:
					is_possible = False
					break
				if current == 2:
					current = 3
		elif current in second:
			if row2[i] in {'3', '4', '5', '6'}:
				current += 1
				if row1[i] not in {'3', '4', '5', '6'}:
					is_possible = False
					break
				if current == 4:
					current = 1
	if current in first:
		if row1[n - 1] not in {'3', '4', '5', '6'} or row2[n - 1] not in {'3', '4', '5', '6'}:
			is_possible = False
	elif current in second:
		if row2[n - 1] not in {'1', '2'}:
			is_possible = False
	if is_possible:
		print('YES')
	else:
		print('NO')


q = int(input(''))
for _ in range(q):
	n = int(input(''))
	m = []
	a = list(map(int, list(input(''))))
	m.append(a)
	a = list(map(int, list(input(''))))
	m.append(a)
	for i in range(2):
		for j in range(n):
			if m[i][j] == 1 or m[i][j] == 2:
				m[i][j] = 0
			else:
				m[i][j] = 1
	res = True
	f = 0
	for i in range(n):
		if m[f][i] == 0:
			continue
		elif m[f ^ 1][i] == 1:
			f = f ^ 1
			continue
		else:
			res = False
			break
	if res:
		if f == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	a = [[int(i) for i in S()], [int(i) for i in S()]]
	(x, y) = (0, 0)
	for i in range(n):
		if a[x][y] > 2:
			x = (x + 1) % 2
			if a[x][y] <= 2:
				break
			y += 1
		else:
			y += 1
	if x == 1 and y == n:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	ch1 = input()
	ch2 = input()
	a = 0
	Test = True
	nb = 0
	for j in range(n):
		if a == 0:
			if ch1[j] == '1':
				a2 = 0
			elif ch1[j] == '2':
				a2 = 0
			else:
				if ch2[j] == '1' or ch2[j] == '2':
					Test = False
				nb += 1
				a2 = 1
		elif a == 1:
			if ch2[j] == '1' or ch2[j] == '2':
				a2 = 1
			else:
				if ch1[j] == '1' or ch1[j] == '2':
					Test = False
				a2 = 0
				nb += 1
		a = a2
	if a == 1 and Test == True:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	s1 = input()
	s2 = input()
	came_from_left = True
	top_row = True
	possible = True
	j = 0
	while j < n:
		if top_row:
			current = int(s1[j])
		else:
			current = int(s2[j])
		if current <= 2:
			if not came_from_left:
				possible = False
				break
			else:
				j += 1
		elif came_from_left:
			top_row = not top_row
			came_from_left = False
		else:
			came_from_left = True
			j += 1
	if possible:
		if top_row or not came_from_left:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(t,) = I()
while t:
	t -= 1
	(n,) = I()
	s = []
	s.append(input())
	s.append(input())
	row = 1
	col = n - 1
	ans = 'YES'
	while col >= 0:
		k = int(s[row][col])
		if k >= 3 and int(s[1 - row][col]) >= 3:
			if row == 1:
				row = 0
			else:
				row = 1
		elif k >= 3:
			ans = 'NO'
		col -= 1
	if row == 0 and ans == 'YES':
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
straight = set(['1', '2'])
curved = set(['3', '4', '5', '6'])
for j in range(testcases):
	n = int(input())
	row1 = [k for k in input()]
	row2 = [k for k in input()]
	cur = [1, 1]
	previous = 0
	broke = False
	s = 0
	while cur[1] != n + 1:
		if cur[0] == 1:
			if s == 0:
				if row1[cur[1] - 1] in curved:
					cur[0] = 2
					previous = 1
				else:
					cur[1] += 1
					previous = 0
			elif previous == 0:
				if row1[cur[1] - 1] in curved:
					cur[0] = 2
					previous = 1
				else:
					cur[1] += 1
					previous = 0
			elif row1[cur[1] - 1] in curved:
				cur[1] += 1
				previous = 0
			else:
				broke = True
				break
		elif previous == 0:
			if row2[cur[1] - 1] in curved:
				cur[0] = 1
				previous = 1
			else:
				cur[1] += 1
				previous = 0
		elif row2[cur[1] - 1] in curved:
			cur[1] += 1
			previous = 0
		else:
			broke = True
			break
		s += 1
	if broke == False:
		if cur[1] == n + 1 and cur[0] == 2:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	up = 1
	down = 0
	i = 0
	c = 0
	n = int(input())
	List1 = list(input())
	List2 = list(input())
	while i < n:
		if down == 1:
			if List2[i] > '2':
				if List1[i] <= '2':
					c += 1
					break
				down = 0
				up = 1
		elif up == 1:
			if List1[i] > '2':
				if List2[i] <= '2':
					c += 1
					break
				down = 1
				up = 0
		i += 1
	if down == 1 and c == 0:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	N = int(input())
	pipe = [list(map(int, input().rstrip())) for _ in range(2)]
	dp = [[False] * (N + 1) for _ in range(2)]
	dp[0][0] = True
	for i in range(N):
		if pipe[0][i] <= 2 and dp[0][i]:
			dp[0][i + 1] = True
		if pipe[1][i] <= 2 and dp[1][i]:
			dp[1][i + 1] = True
		if pipe[0][i] > 2 and pipe[1][i] > 2:
			if dp[0][i]:
				dp[1][i + 1] = True
			if dp[1][i]:
				dp[0][i + 1] = True
	if dp[1][-1]:
		print('YES')
	else:
		print('NO')


def numberstotypes(pipes):
	for i in range(2):
		for j in range(len(pipes[i])):
			if pipes[i][j] in {'1', '2'}:
				pipes[i][j] = 'A'
			else:
				pipes[i][j] = 'B'
	return pipes

def main():
	queries = int(input())
	for query in range(queries):
		n = int(input())
		pipes = [list(input()), list(input())]
		pipes = numberstotypes(pipes)
		(level, pos, ans) = (0, 0, True)
		while pos < n:
			if pipes[level][pos] == 'A':
				pos += 1
			elif pipes[1 - level][pos] == 'B':
				level = 1 - level
				pos += 1
			else:
				ans = False
				break
		if ans == True and (level != 1 or pos != n):
			ans = False
		if ans:
			print('YES')
		else:
			print('NO')
main()


for _ in range(int(input())):
	n = int(input())
	arr1 = list(input())
	arr2 = list(input())
	matrix = [arr1, arr2]
	flag = 0
	final = 0
	for i in range(len(arr1)):
		if int(matrix[flag][i]) <= 2:
			continue
		else:
			flag = flag ^ 1
			if int(matrix[flag][i]) > 2:
				continue
			else:
				print('NO')
				final = 1
				break
		print('flag ', flag)
	if final == 0:
		if flag == 1:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	S = [s1, s2]
	d = [1, 0]
	it = 0
	i = 0
	flag = True
	while i < n:
		if S[it % 2][i] != '1' and S[it % 2][i] != '2':
			if S[d[it]][i] == '1' or S[d[it]][i] == '2':
				flag = False
				break
			else:
				it = d[it]
		i += 1
	if it % 2 == 0 or not flag:
		print('NO')
	else:
		print('YES')


q = int(input())
for _ in range(q):
	n = int(input())
	rows = [None, None]
	rows[0] = list(map(int, list(input())))
	rows[1] = list(map(int, list(input())))
	y = 0
	x = 0
	result = True
	last = 0
	while True:
		if rows[y][x] == 1 or rows[y][x] == 2:
			if last == 1:
				result = False
				break
			else:
				x += 1
				last = 0
		elif last == 1:
			x += 1
			last = 2
		else:
			if y == 0:
				y = 1
			else:
				y = 0
			last = 1
		if x == n:
			result = y == 1
			break
	if result:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = 1
t = int(input())
for _ in range(t):
	n = int(input())
	a = [input().split() for x in range(2)]
	curr = 0
	row = 0
	flag = 0
	while curr < n:
		if a[row][0][curr] == '1' or a[row][0][curr] == '2':
			curr += 1
		else:
			if row == 0:
				row = 1
			else:
				row = 0
			if a[row][0][curr] == '1' or a[row][0][curr] == '2':
				flag = 1
				break
			else:
				curr += 1
	if row == 0 or flag == 1:
		print('NO')
	else:
		print('YES')


q = int(input())
for _ in range(q):
	s = ['' for i in range(2)]
	n = int(input())
	s[0] = input()
	s[1] = input()
	row = 0
	pos = 0
	for i in range(n):
		if s[row][i] >= '3':
			if s[row ^ 1][i] < '3':
				break
			else:
				row ^= 1
		pos += 1
	if row == 1 and pos == n:
		print('YES')
	else:
		print('NO')


for q in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	flag = 1
	l = ['3', '4', '5', '6']
	i = 0
	j = 1
	while i < n:
		if j == 1:
			if a[i] in ['1', '2']:
				pass
			elif a[i] in l and b[i] in l:
				j = 2
			else:
				flag = 0
				break
		elif j == 2:
			if b[i] in ['1', '2']:
				pass
			elif b[i] in l and a[i] in l:
				j = 1
			else:
				flag = 0
				break
		i += 1
	if flag == 1 and j == 2:
		print('YES')
	else:
		print('NO')


import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

def INT():
	return int(input())

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

def LIST():
	return list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
t = INT()
while t != 0:
	n = INT()
	grid = []
	grid.append(list(input()))
	grid.append(list(input()))
	curRow = 0
	curCol = 0
	prev = 0
	endAt = 1
	while curCol < n:
		ch = grid[curRow][curCol]
		if ch == '1' or ch == '2':
			if endAt == 1:
				curCol += 1
				prev = 0
			else:
				break
		elif prev == 1:
			curCol += 1
			prev = 0
			endAt = 1
		else:
			curRow ^= 1
			prev = 1
			endAt = 0
	if curRow == 1 and curCol == n:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	x = [[i for i in a]] + [[j for j in b]]
	d = 1
	i = 0
	j = 0
	while True:
		if x[i][j] == '1' or x[i][j] == '2':
			if d == 1:
				if j == n - 1 and i == 1:
					print('YES')
					break
				elif j == n - 1:
					print('NO')
					break
				else:
					j += 1
			else:
				print('NO')
				break
		elif x[i][j] in '3456':
			if d == 1:
				if i == 0:
					i = 1
					d = 2
				elif i == 1:
					i = 0
					d = -2
			elif d == 2 or d == -2:
				if j == n - 1:
					if i == 0:
						print('NO')
					else:
						print('YES')
					break
				else:
					d = 1
					j += 1


def my_func(n, A, B):
	r = 0
	bul = True
	s = 0
	for i in range(n):
		if int(A[i]) > 2 and int(B[i]) > 2:
			s += 1
			r = (r + 1) % 2
		elif r == 0 and int(A[i]) > 2 and (int(B[i]) < 3) or (r == 1 and int(B[i]) > 2 and (int(A[i]) < 3)):
			bul = False
			break
	return bul and s % 2 == 1
q = int(input())
for j in range(q):
	n = int(input())
	A = input()
	B = input()
	if my_func(n, A, B):
		print('YES')
	else:
		print('NO')


q = int(input())
for qi in range(q):
	n = int(input())
	grid = [[0 for i in range(2)] for j in range(n)]
	row1 = input()
	row2 = input()
	for i in range(n):
		if row1[i] == '1' or row1[i] == '2':
			grid[i][0] = 1
		if row2[i] == '1' or row2[i] == '2':
			grid[i][1] = 1
	(inversions, y) = (0, 0)
	possible = 'YES'
	for i in range(n):
		if grid[i][0] + grid[i][1] == 0:
			inversions += 1
			y += 1
			y %= 2
		elif grid[i][y] != 1:
			possible = 'NO'
	if possible == 'NO' or inversions % 2 == 0:
		print('NO')
	else:
		print('YES')


import os, sys, math
import collections
if os.path.exists('testing'):
	name = os.path.basename(__file__)
	if name.endswith('.py'):
		name = name[:-3]
	src = open(name + '.in.txt', encoding='utf8')
	input = src.readline

def solve(row1, row2):
	mp = {'1': 1, '2': 1, '3': 2, '4': 2, '5': 2, '6': 2}
	row1 = [mp[q] for q in row1]
	row2 = [mp[q] for q in row2]
	current_row = 0
	current_col = 0
	rows = [row1, row2]
	length = len(row1)
	while True:
		if current_col == length:
			return current_row == 1
		p = rows[current_row][current_col]
		if p != 1:
			new_row = 1 - current_row
			new_p = rows[new_row][current_col]
			if new_p != 2:
				return False
			current_row = new_row
		current_col += 1
q = int(input().strip())
for _ in range(q):
	n = int(input().strip())
	row1 = input().strip()
	row2 = input().strip()
	r = solve(row1, row2)
	print('YES' if r else 'NO')


q = int(input())
while q:
	q += -1
	n = int(input())
	s1 = input()
	s2 = input()
	t = s1
	ch = 'YES'
	for i in range(n):
		if t[i] == '1' or t[i] == '2':
			continue
		elif t == s1:
			if s2[i] == '1' or s2[i] == '2':
				ch = 'NO'
				break
			else:
				t = s2
		elif t == s2:
			if s1[i] == '1' or s1[i] == '2':
				ch = 'NO'
				break
			else:
				t = s1
	if t == s1:
		print('NO')
	else:
		print(ch)


from collections import defaultdict as dc
from collections import deque as dq
import sys
import math
mod = 10 ** 9 + 7

def inp():
	p = sys.stdin.readline()
	return p
q = int(inp())
for _ in range(q):
	n = int(inp())
	a = str(input())
	b = str(input())
	p = []
	q = []
	(z1, z2) = (0, 0)
	for i in range(n):
		if a[i] == '1' or a[i] == '2':
			p.append(0)
		else:
			z1 += 1
			p.append(1)
		if b[i] == '1' or b[i] == '2':
			q.append(0)
		else:
			z2 += 1
			q.append(1)
	if z1 == 0 or z2 == 0:
		print('NO')
	else:
		if p[0] == 0:
			x = 0
			ans = 0
			for i in range(1, n):
				if x == 0:
					if p[i] == 0:
						x = 0
					elif q[i] == 0:
						ans = 1
						break
					else:
						x = 1
				elif x == 1:
					if q[i] == 0:
						x = 1
					elif p[i] == 0:
						ans = 1
						break
					else:
						x = 0
		else:
			x = 1
			if q[0] == 0:
				ans = 1
			else:
				ans = 0
				for i in range(1, n):
					if x == 0:
						if p[i] == 0:
							x = 0
							continue
						elif q[i] == 0:
							ans = 1
							break
						else:
							x = 1
					elif x == 1:
						if q[i] == 0:
							x = 1
							continue
						elif p[i] == 0:
							ans = 1
							break
						else:
							x = 0
		if x == 0 or ans == 1:
			print('NO')
		else:
			print('YES')


def solve(n, line1, line2):
	way = 'h'
	level = 0
	i = 0
	while i < n:
		p = line1[i] if level == 0 else line2[i]
		if way == 'v':
			if p in ['1', '2']:
				return 'NO'
			else:
				way = 'h'
				i += 1
		elif p in ['1', '2']:
			i += 1
		else:
			way = 'v'
			level = (level + 1) % 2
	if level == 0:
		return 'NO'
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	line1 = input()
	line2 = input()
	print(solve(n, line1, line2))


q = int(input())
for _ in range(0, q):
	n = int(input())
	s1 = input()
	s2 = input()
	flag = 0
	for j in range(0, n):
		if flag == 0 and s1[j] <= '2':
			continue
		elif flag == 1 and s2[j] <= '2':
			continue
		elif flag == 0 and s1[j] > '2' and (s2[j] > '2'):
			flag += 1
		elif flag == 1 and s2[j] > '2' and (s1[j] > '2'):
			flag -= 1
		else:
			flag = 0
			break
	if flag == 1:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	A = [None]
	B = [None]
	for i in input():
		if i == '1' or i == '2':
			A.append(0)
		else:
			A.append(1)
	for i in input():
		if i == '1' or i == '2':
			B.append(0)
		else:
			B.append(1)
	F1 = [0 for i in range(n + 1)]
	F1[0] = 1
	temp = 1
	for i in range(1, len(A) - 1):
		if temp == 1:
			F1[i] = 1
			if A[i] == 0:
				temp = 1
			elif A[i] == 1 and B[i] == 0:
				F1[i] = 0
				break
			else:
				temp = 2
		else:
			F1[i] = 1
			if B[i] == 0:
				temp = 2
			elif B[i] == 1 and A[i] == 0:
				F1[i] = 0
				break
			else:
				temp = 1
	if F1[n - 1] == 1:
		if temp == 1:
			if A[n] == 1 and B[n] == 1:
				F1[n] = 1
			else:
				F1[n] = 0
		elif B[n] == 0:
			F1[n] = 1
		else:
			F1[n] = 0
	flag = False
	for i in range(1, n + 1):
		if F1[i] == 0:
			flag = True
			break
	if flag:
		print('NO')
	else:
		print('YES')


q = int(input())
for _ in range(q):
	n = int(input())
	s1 = input()
	s2 = input()
	L1 = [0] * n
	L2 = [0] * n
	ptr = 1
	flag = 0
	if s1[0] == '1' or s1[0] == '2':
		L1[0] = 1
		ptr = 1
	elif int(s2[0]) > 2:
		L2[0] = 1
		ptr = 2
	else:
		flag = 1
	for i in range(1, len(s1)):
		if flag == 1:
			break
		if ptr == 1:
			if s1[i] == '1' or s1[i] == '2':
				L1[i] = 1
			elif int(s2[i]) > 2:
				L2[i] = 1
				ptr = 2
			else:
				flag = 1
		elif s2[i] == '1' or s2[i] == '2':
			L2[i] = 1
		elif int(s1[i]) > 2:
			L1[i] = 1
			ptr = 1
		else:
			flag = 1
	if L2[-1] == 1 and flag == 0:
		print('YES')
	else:
		print('NO')


import sys

def main():

	def input():
		return sys.stdin.readline()[:-1]
	q = int(input())
	for _ in range(q):
		n = int(input())
		s1 = input()
		s2 = input()
		c = ['3', '4', '5', '6']
		y = 0
		f = 1
		for now in range(n):
			if y == 0:
				if s1[now] == '1' or s1[now] == '2':
					pass
				elif s1[now] in c and s2[now] in c:
					y = 1
				else:
					f = 0
					break
			elif s2[now] == '1' or s2[now] == '2':
				pass
			elif s1[now] in c and s2[now] in c:
				y = 0
			else:
				f = 0
				break
		if f == 0 or y == 0:
			print('NO')
		else:
			print('YES')
main()


count = int(input())
result = []
for _ in range(count):
	num = int(input())
	pipes_1 = list(map(lambda num: int(num), list(input())))
	pipes_2 = list(map(lambda num: int(num), list(input())))
	curve = [3, 4, 5, 6]
	st = [1, 2]
	index = 0
	direction = 0
	while index < num:
		if pipes_1[index] in curve and pipes_2[index] in curve:
			index += 1
			if direction == 1:
				direction = 0
			else:
				direction = 1
		elif direction == 0 and pipes_1[index] in st or (direction == 1 and pipes_2[index] in st):
			index += 1
		elif pipes_1[index] in st and pipes_2[index] in curve:
			break
		elif pipes_2[index] in st and pipes_1[index] in curve:
			break
		elif direction == 1 and index == num - 1 and (pipes_2[index] in st):
			index += 1
		else:
			break
	if num == index and direction == 1:
		result.append('YES')
	else:
		result.append('NO')
print('\n'.join(result))


q = int(input())
for _ in range(q):
	n = int(input())
	mat = []
	mat.append(input())
	mat.append(input())
	tp = lambda x: 1 if int(x) < 3 else 2
	row = 0
	can = True
	for i in range(n):
		if tp(mat[row][i]) == 2:
			row = 1 if row == 0 else 0
			if tp(mat[row][i]) == 1:
				can = False
				break
	print('YES' if can and row == 1 else 'NO')
	while True:
		break
		if tp(mat[row][col]) == 1:
			col += 1
			ptp = 1
		else:
			if ptp == 1:
				row = 0 if row == 1 else 1
			else:
				col += 1
			ptp = 2


q = int(input())
HORIZONTAL = 1
VERTICAL = 2
for i in range(q):
	n = int(input())
	mapa = [None, None]
	mapa[0] = [int(i) for i in list(input())]
	mapa[1] = [int(i) for i in list(input())]
	x = 0
	y = 0
	mov = HORIZONTAL
	while True:
		if x == n and y == 1:
			print('YES')
			break
		if x >= n:
			print('NO')
			break
		atual = mapa[y][x]
		if atual == -1:
			print('NO')
			break
		if atual <= 2:
			if mov == VERTICAL:
				print('NO')
				break
			mov = HORIZONTAL
		elif mov == HORIZONTAL:
			mov = VERTICAL
		else:
			mov = HORIZONTAL
		mapa[y][x] = -1
		if mov == HORIZONTAL:
			x += 1
		elif mov == VERTICAL:
			if y == 0:
				y = 1
			else:
				y = 0


q = int(input())
I = {'1', '2'}
V = {'3', '4', '5', '6'}
for case in range(q):
	n = int(input())
	a = ['$' + input(), '$' + input()]
	dp = [[False for _ in range(1 + n)], [False for _ in range(1 + n)]]
	dp[0][0] = True
	for i in range(1, 1 + n):
		if a[0][i] in I:
			dp[0][i] = dp[0][i - 1]
		if a[1][i] in I:
			dp[1][i] = dp[1][i - 1]
		if a[0][i] in V and a[1][i] in V:
			dp[0][i] = dp[0][i] or dp[1][i - 1]
			dp[1][i] = dp[1][i] or dp[0][i - 1]
	print('YES' if dp[1][n] else 'NO')


for q in range(int(input())):
	control = 0
	flag = 0
	n = int(input())
	ra = list(map(int, list(input().strip())))
	rb = list(map(int, list(input().strip())))
	r = [ra, rb]
	for x in range(n):
		if r[control][x] in [1, 2]:
			pass
		elif r[1 - control][x] in [3, 4, 5, 6]:
			control = 1 - control
		else:
			flag = 1
			break
	if flag == 0 and control == 1:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	n = int(input())
	k = input()
	p = input()
	a = list(k)
	b = list(p)
	lis = [a, b]
	k = 'Yes'
	r = 0
	for i in range(n):
		if lis[r][i] in '12':
			continue
		elif lis[r ^ 1][i] not in '12':
			r ^= 1
			continue
		else:
			k = 'No'
			break
	if r == 0:
		k = 'No'
	print(k)


straight = set([1, 2])
nstraight = set([3, 4, 5, 6])
for _ in range(int(input())):
	n = int(input())
	r1 = [int(x) for x in input().strip()]
	r2 = [int(x) for x in input().strip()]
	poss = [True, False]
	for i in range(n):
		possnew = [False, False]
		if poss[0] and r1[i] in straight:
			possnew[0] = True
		if poss[1] and r2[i] in straight:
			possnew[1] = True
		if r1[i] in nstraight and r2[i] in nstraight:
			if poss[0]:
				possnew[1] = True
			if poss[1]:
				possnew[0] = True
		poss = possnew
	if poss[1]:
		print('YES')
	else:
		print('NO')


from collections import defaultdict as dc
import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(2):
		l.append(input()[:-1])
	r = 0
	f = 0
	i = 0
	while i < n:
		if l[r][i] >= '3':
			if l[1 - r][i] < '3':
				f = 1
				break
			else:
				r = 1 - r
		i += 1
	if i == n and r == 1:
		print('YES')
	else:
		print('NO')


import sys
q = int(sys.stdin.readline())
for i in range(q):
	n = int(sys.stdin.readline())
	s1 = sys.stdin.readline()
	s2 = sys.stdin.readline()
	s = [s1, s2]
	position = (0, 0)
	bad = False
	previous = (0, -1)
	while 0 <= position[0] <= 1 and 0 <= position[1] < n:
		(x, y) = position
		if s[x][y] < '3':
			if previous[0] == x:
				previous = position
				position = (x, y + 1)
			else:
				bad = True
				break
		elif previous[0] == x:
			previous = position
			position = ((x + 1) % 2, y)
		else:
			previous = position
			position = (x, y + 1)
	if bad or position != (1, n):
		print('NO')
	else:
		print('YES')


def run():
	n = eval(input())
	vals = []
	for _ in range(n):
		input()
		row1 = input()
		row2 = input()
		vals.append([row1, row2])
	pipes = dict()
	pipes['left_to_right'] = 1
	pipes['up_to_down'] = 1
	pipes['down_to_up'] = 1
	pipes['left_to_down'] = 6
	pipes['left_to_up'] = 6
	pipes['right_to_down'] = 6
	pipes['right_to_up'] = 6
	pipes['down_to_right'] = 6
	pipes['down_to_left'] = 6
	pipes['up_to_right'] = 6
	pipes['up_to_left'] = 6
	directions = dict()
	directions[1] = [1, 2]
	directions[6] = [3, 4, 5, 6]
	for i in range(n):
		row1 = [int(ch) for ch in vals[i][0]]
		row2 = [int(ch) for ch in vals[i][1]]
		rows = [row1, row2]
		current_row = 0
		current_col = 0
		current = 'left'
		j = 0
		next_direction = None
		while j < len(row1):
			current_pipe = rows[current_row][j]
			next_direction = None
			possible_directions = []
			for key in pipes.keys():
				if key.startswith(current) and current_pipe in directions[pipes[key]]:
					possible_directions.append(key.split('_')[2])
			if 'right' in possible_directions and (current_col < len(row1) - 1 and current_row == 0 or (current_col < len(row1) and current_row == 1)):
				next_direction = 'right'
			elif 'left' in possible_directions and current_col > 0:
				next_direction = 'left'
			elif 'up' in possible_directions and current_row == 1:
				next_direction = 'up'
			elif 'down' in possible_directions and current_row == 0:
				next_direction = 'down'
			if next_direction is None:
				break
			if next_direction != 'right' and current_row == 1 and (current_col == len(row1) - 1) and (j == len(row1) - 1):
				break
			if next_direction == 'right':
				current = 'left'
				j += 1
				current_col += 1
			elif next_direction == 'left':
				current = 'right'
				j -= 1
				current_col -= 1
			elif next_direction == 'up':
				current = 'down'
				current_row -= 1
			elif next_direction == 'down':
				current = 'up'
				current_row += 1
		if j == len(row1) and current_col == len(row1) and (current_row == 1) and (next_direction == 'right'):
			print('YES')
		else:
			print('NO')
run()


def yes_or_no(row1, row2, n):
	flag = False
	x = 0
	y = 0
	while x < n:
		row = {0: row1, 1: row2}[y]
		fig = row[x]
		if fig == 1 or fig == 2:
			if flag:
				return 'NO'
			x += 1
		elif flag:
			x += 1
			flag = False
		else:
			y = 0 if y == 1 else 1
			flag = True
	if y == 1:
		return 'YES'
	else:
		return 'NO'
q = int(input())
for _ in range(q):
	n = int(input())
	row1 = list(map(int, input()))
	row2 = list(map(int, input()))
	print(yes_or_no(row1, row2, n))


q = int(input())
for _ in range(q):
	n = int(input())
	tb = [list(map(int, input())) for _ in range(2)]
	(x, y) = (0, 0)
	sl = True
	while y < n:
		if tb[x][y] < 3 and sl:
			y += 1
			sl = True
		elif tb[x][y] >= 3 and sl:
			x ^= 1
			sl = False
		elif tb[x][y] >= 3 and (not sl):
			y += 1
			sl = True
		else:
			break
	if x == 1 and y == n:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	arr1 = input()
	arr1 = list(arr1)
	arr2 = input()
	arr2 = list(arr2)
	arr = []
	arr.append(arr1)
	arr.append(arr2)
	row = 0
	col = 0
	j = 0
	flag = 0
	while col < n:
		if arr[row][col] == '1' or arr[row][col] == '2':
			col += 1
		elif arr[1 - row][col] == '1' or arr[1 - row][col] == '2':
			print('NO')
			flag = 1
			break
		else:
			col += 1
			row = 1 - row
	if flag == 0 and col == n and (row == 1):
		print('YES')
	elif flag == 0 and (col != n or row != 1):
		print('NO')


for tc in range(int(input())):
	n = int(input())
	row = [[int(x) for x in list(input())], [int(x) for x in list(input())]]
	rowPos = 0
	for i in range(n):
		if row[rowPos][i] == 1 or row[rowPos][i] == 2:
			continue
		rowPos = 0 if rowPos == 1 else 1
		if row[rowPos][i] == 1 or row[rowPos][i] == 2:
			print('NO')
			break
	else:
		if rowPos == 1:
			print('YES')
		else:
			print('NO')


t = int(input())
for ts in range(t):
	l = int(input())
	a = [int(i) >= 3 for i in list(input())]
	a = [a, [int(i) >= 3 for i in list(input())]]
	w = 0
	for i in range(l):
		if a[0][i] and a[1][i]:
			w = (w + 1) % 2
		elif a[w][i]:
			w = 0
			break
	if w == 0:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	q = int(input())
	w = input()
	e = input()
	r = w
	k = 0
	l = 0
	p = 0
	for i in range(q):
		if r[i] != '1' and r[i] != '2':
			if k == 0:
				r = e
				p = 1
				k = 1
			else:
				k = 0
				r = w
				p = 0
			if r[i] == '1' or r[i] == '2':
				print('NO')
				l = 1
				break
	if l != 1 and p == 1:
		print('YES')
	elif l != 1:
		print('NO')


import sys, math, queue, collections
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)

def solve():
	n = int(input())
	a = []
	a.append(list(map(int, list(input()))))
	a.append(list(map(int, list(input()))))
	dp = [[[False for i in range(7)] for i in range(n)] for i in range(2)]
	if a[0][0] <= 2:
		dp[0][0][2] = True
	else:
		dp[0][0][4] = True
		if a[1][0] <= 2:
			dp[1][0][1] = True
		else:
			dp[1][0][5] = dp[1][0][6] = True
	for i in range(1, n):
		if a[0][i] <= 2:
			dp[0][i][2] = dp[0][i - 1][2] or dp[0][i - 1][3]
			if a[1][i] <= 2:
				dp[1][i][2] = dp[1][i - 1][2] or dp[1][i - 1][6]
			else:
				dp[1][i][5] = dp[1][i - 1][2] or dp[1][i - 1][6]
		else:
			dp[0][i][4] = dp[0][i - 1][2] or dp[0][i - 1][3]
			if a[1][i] <= 2:
				dp[1][i][2] = dp[1][i - 1][2] or dp[1][i - 1][6]
			else:
				dp[1][i][6] = dp[0][i][4]
				dp[1][i][5] = dp[1][i - 1][2] or dp[1][i - 1][6]
			dp[0][i][3] = dp[1][i][5]
	ans = dp[1][n - 1][2] or dp[1][n - 1][6]
	print('YES' if ans else 'NO')
for _ in range(int(input())):
	solve()


q = int(input())
for _ in range(q):
	n = int(input())
	row1 = input()
	row2 = input()
	pos = (0, 0)
	turn = '3456'
	straight = '12'
	while pos != (1, n) and pos[1] < n:
		if pos[0] == 0:
			if row1[pos[1]] in turn:
				if row2[pos[1]] in turn:
					pos = (1, pos[1] + 1)
				else:
					break
			else:
				pos = (0, pos[1] + 1)
		elif pos[0] == 1:
			if row2[pos[1]] in turn:
				if row1[pos[1]] in turn:
					pos = (0, pos[1] + 1)
				else:
					break
			else:
				pos = (1, pos[1] + 1)
	if pos == (1, n):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	fieldInLinesOfArray = (tuple(map(int, tuple(input()))), tuple(map(int, tuple(input()))))
	fieldInLine = 0
	YesNoFlag = False
	YesNoFlagOfswitching = False
	i = 0
	while i != n:
		if fieldInLinesOfArray[fieldInLine][i] < 3:
			i += 1
			YesNoFlagOfswitching = False
		elif fieldInLinesOfArray[1 - fieldInLine][i] > 2 and (not YesNoFlagOfswitching):
			fieldInLine = 1 - fieldInLine
			YesNoFlagOfswitching = True
		elif YesNoFlagOfswitching:
			i += 1
			YesNoFlagOfswitching = False
		else:
			YesNoFlag = True
			print('NO')
			break
	if YesNoFlag:
		continue
	if fieldInLine == 1:
		print('YES')
	else:
		print('NO')


def dfs():
	if nl[0][0] in R1:
		d = 0
	else:
		d = 1
	st = [[0, 0, d]]
	while st:
		(x, y, d) = st.pop()
		if x == N - 1 and y == 1:
			if d == 0:
				return True
			else:
				return False
		if d == 0:
			tx = x + 1
			ty = y
			if tx < N and 0 <= ty < 2:
				if nl[ty][tx] in R1:
					st.append([tx, ty, d])
				elif ty == 0:
					st.append([tx, ty, 1])
				else:
					st.append([tx, ty, 2])
		else:
			tx = x
			if d == 1:
				ty = y + 1
			else:
				ty = y - 1
			if nl[ty][tx] not in R1:
				st.append([tx, ty, 0])
	return False
R1 = {'1', '2'}
T = int(input())
for t in range(T):
	N = int(input())
	nl = [list(input()) for _ in range(2)]
	if dfs():
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s1 = str(input())
	s2 = str(input())
	d = [s1, s2]
	row = 0
	for i in range(n):
		if int(d[row][i]) > 2:
			row ^= 1
			if int(d[row][i]) <= 2:
				row = 0
				break
	if row == 0:
		print('NO')
	else:
		print('YES')


from typing import Tuple, List, Dict

class PipeType:
	STRAIGHT = 1
	BENT = 2

class Board:

	def __init__(self, num_of_cols: int, pipes: Tuple[List[int], List[int]]):
		self.num_of_cols = num_of_cols
		self.verticals = {'top': Board.init_false_array(num_of_cols + 1), 'bottom': Board.init_false_array(num_of_cols + 1)}
		self.pipes = {'top': list(map(Board.transform_pipe_type, pipes[0])), 'bottom': list(map(Board.transform_pipe_type, pipes[1]))}
		self.verticals['top'][0] = True

	@staticmethod
	def transform_pipe_type(original_pipe_type: int):
		if original_pipe_type in [1, 2]:
			return PipeType.STRAIGHT
		else:
			return PipeType.BENT

	def __connect(self, col_num: int):
		for row in ['top', 'bottom']:
			if self.pipes[row][col_num] == PipeType.STRAIGHT:
				self.verticals[row][col_num + 1] |= self.verticals[row][col_num]
		if self.pipes['top'][col_num] == PipeType.BENT and self.pipes['bottom'][col_num] == PipeType.BENT:
			self.verticals['top'][col_num + 1] |= self.verticals['bottom'][col_num]
			self.verticals['bottom'][col_num + 1] |= self.verticals['top'][col_num]

	@staticmethod
	def init_false_array(length: int):
		return [False] * length

	def __connect_all(self):
		for i in range(self.num_of_cols):
			self.__connect(i)

	def connected(self) -> bool:
		self.__connect_all()
		return self.verticals['bottom'][self.num_of_cols]

def test():
	assert Board(7, ([2, 3, 2, 3, 2, 1, 6], [1, 6, 1, 5, 1, 2, 4])).connected()
	assert Board(1, ([3], [4])).connected()
	assert Board(2, ([1, 3], [2, 4])).connected()
	assert not Board(2, ([1, 2], [3, 4])).connected()
	assert Board(3, ([5, 3, 6], [3, 4, 5])).connected()
	assert not Board(2, ([4, 6], [5, 4])).connected()
q = int(input())
for __ in range(q):
	n = int(input())
	top = [int(c) for c in input()]
	bottom = [int(c) for c in input()]
	if Board(n, (top, bottom)).connected():
		print('YES')
	else:
		print('NO')


q = int(input())
(ans, f) = ([], True)
for i in range(q):
	n = int(input())
	l = [input().replace('1', '-').replace('2', '-').replace('3', '*').replace('4', '*').replace('5', '*').replace('6', '*') for i in (1, 2)]
	f = True
	row = 0
	for j in range(n):
		if l[row][j] == '-':
			continue
		elif l[row ^ 1][j] == '*':
			row ^= 1
		else:
			f = False
			break
	if f and row:
		ans.append('YES')
	else:
		ans.append('NO')
print(*ans, sep='\n')


q = int(input())
for _ in range(q):
	n = int(input())
	a = input()
	b = input()
	pipe = []
	pipe.append(a)
	pipe.append(b)
	pos = 0
	ans = True
	for i in range(n):
		if pipe[pos][i] > '2':
			pos = 1 - pos
			if pipe[pos][i] <= '2':
				ans = False
				break
	if pos == 0:
		ans = False
	if ans:
		print('YES')
	else:
		print('NO')


st = ['1', '2']
tera = ['3', '4', '5', '6']
for _ in range(int(input())):
	n = int(input())
	li = [[], []]
	li[0] = input()
	li[1] = input()
	j = 0
	flag = 1
	i = 0
	while i < n:
		if li[j][i] in st:
			i += 1
		elif j == 0:
			if li[1][i] not in tera:
				flag = 0
				break
			else:
				j = 1
				i += 1
		elif li[0][i] not in tera:
			flag = 0
			break
		else:
			j = 0
			i += 1
	if flag == 1 and j == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
while t:
	n = int(input())
	r1 = input()
	r2 = input()
	lol = 1
	pr = 1
	i = 0
	while i < n:
		if lol == 1:
			if (r1[i] == '1' or r1[i] == '2') and pr == 2:
				lol = 1
				break
			elif (r1[i] == '1' or r1[i] == '2') and pr == 1:
				i += 1
				continue
			else:
				if pr == 1:
					lol = 2
				elif pr == 2:
					lol = 1
					i += 1
				pr = 1
		elif (r2[i] == '1' or r2[i] == '2') and pr == 1:
			lol = 1
			break
		elif (r2[i] == '1' or r2[i] == '2') and pr == 2:
			i += 1
			continue
		else:
			if pr == 1:
				lol = 2
				i += 1
			elif pr == 2:
				lol = 1
			pr = 2
	if lol == 2:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	plum = [list(map(int, list(input()))), list(map(int, list(input())))]
	h = 0
	answer = 'YES'
	for i in range(n):
		if plum[h][i] > 2:
			if plum[(h + 1) % 2][i] > 2:
				h = (h + 1) % 2
			else:
				answer = 'NO'
				break
	if h != 1:
		answer = 'NO'
	print(answer)


for _ in range(int(input())):
	n = int(input())
	r1 = [list(input()), list(input())]
	(i, j) = (0, 0)
	pi = 0
	while j <= n:
		if j == n:
			if i == 1:
				print('YES')
			else:
				print('NO')
			break
		elif i == pi:
			if r1[i][j] in ['1', '2']:
				j += 1
				pi = i
			else:
				pi = i
				i ^= 1
		elif r1[i][j] in ['1', '2']:
			print('NO')
			break
		else:
			j += 1
			pi = i


import string
import sys
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

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

def listStr():
	return list(input().strip())
import collections as col
import math, itertools

def solve():
	N = getInt()
	A = [int(s) for s in input().strip()]
	B = [int(s) for s in input().strip()]
	pos = [0, 0]
	left_flag = True
	while True:
		arr = A if pos[0] == 0 else B
		if left_flag:
			if arr[pos[1]] <= 2:
				pos[1] += 1
			else:
				pos[0] = 1 - pos[0]
				left_flag = False
		elif arr[pos[1]] <= 2:
			return 'NO'
		else:
			pos[1] += 1
			left_flag = True
		if pos == [1, N]:
			return 'YES'
		if pos[1] == N:
			return 'NO'
for _ in range(getInt()):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	l1 = input()
	l2 = input()
	arr = [l1, l2]
	position = 0
	for i in range(n):
		if arr[position][i] > '2':
			position = 1 - position
			if arr[position][i] <= '2':
				position = 0
				break
	if position:
		print('YES')
	else:
		print('NO')


import math
line = [1, 2]
circle = [3, 4, 5, 6]

def Pipes(n_, l1, l2):
	flag = 0
	for i in range(0, n_):
		if flag == 0:
			if l1[i] in line:
				continue
			else:
				if l2[i] in line:
					print('NO')
					return
				flag = 1
		elif l2[i] in line:
			continue
		else:
			if l1[i] in line:
				print('NO')
				return
			flag = 0
	if flag == 1:
		print('YES')
	else:
		print('NO')
n = int(input())
for i in range(0, n):
	n_ = int(input())
	l1 = list(map(int, input().rstrip().strip()))
	l2 = list(map(int, input().rstrip().strip()))
	Pipes(n_, l1, l2)


q = int(input())
for i in range(q):
	n = int(input())
	pole = []
	a = input()
	b = input()
	pole.append(a)
	pole.append(b)
	j = 0
	k = 0
	last = 0
	t = False
	while True:
		if k >= 2 or j >= n:
			break
		if last == 0 and (pole[k][j] == '1' or pole[k][j] == '2'):
			j += 1
		elif last != 0 and (pole[k][j] == '1' or pole[k][j] == '2'):
			t = True
			print('NO')
			break
		elif last == 0 and k == 0:
			k += 1
			last = 1
		elif last == 0 and k == 1:
			k -= 1
			last = 1
		elif last == 1:
			last = 0
			j += 1
	if not t:
		if k == 1 and j >= n:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	c = 1
	k = 0
	for i in range(n):
		if c == 1:
			if a[i] != '1' and a[i] != '2':
				c = 0
				if b[i] == '1' or b[i] == '2':
					print('NO')
					k = 1
					break
		elif b[i] != '1' and b[i] != '2':
			c = 1
			if a[i] == '1' or a[i] == '2':
				print('NO')
				k = 1
				break
	if k == 1:
		continue
	if c == 1:
		print('NO')
	else:
		print('YES')


q = int(input())
for _ in range(q):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	pos = 0
	flag = False
	for i in range(len(s1)):
		x = int(s1[i])
		y = int(s2[i])
		if pos == 0:
			if x <= 2 and y <= 2:
				pass
			elif x <= 2 and y > 2:
				pass
			elif x > 2 and y <= 2:
				flag = True
				break
			else:
				pos = 1
		elif x <= 2 and y <= 2:
			pass
		elif x <= 2 and y > 2:
			flag = True
			break
		elif x > 2 and y <= 2:
			pass
		else:
			pos = 0
	print('NO') if pos == 0 or flag else print('YES')


def solver():
	T = int(input().strip())
	for case in range(T):
		n = int(input().strip())
		s = []
		s.append(input())
		s.append(input())
		ans = [[0 for i in range(n + 1)] for j in range(5)]
		ans[1][0] = 1
		for i in range(n):
			t1 = 1 if s[0][i] in ('1', '2') else 2
			t2 = 1 if s[1][i] in ('1', '2') else 2
			if ans[1][i] == 1:
				if t1 == 1:
					ans[1][i + 1] = 1
				else:
					ans[4][i] = 1
			if ans[3][i] == 1:
				if t2 == 1:
					ans[3][i + 1] = 1
				else:
					ans[2][i] = 1
			if ans[2][i] == 1 and t1 == 2:
				ans[1][i + 1] = 1
			if ans[4][i] == 1 and t2 == 2:
				ans[3][i + 1] = 1
		if ans[3][n] == 1:
			print('YES')
		else:
			print('NO')

def main():
	while True:
		try:
			solver()
		except EOFError:
			break
main()


for _ in range(int(input())):
	n = int(input())
	s = []
	s.append(input())
	s.append(input())
	k = 0
	for i in range(n):
		if s[k % 2][i] in ('1', '2'):
			continue
		if s[(k + 1) % 2][i] not in ('3', '4', '5', '6'):
			print('NO')
			break
		k += 1
	else:
		if k % 2 == 1:
			print('YES')
		else:
			print('NO')


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd, log
import bisect
import sys
import copy

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	f = input()
	s = input()
	arr = [[f[i], s[i]] for i in range(n)]
	ends = 0
	ok = True
	for i in range(n):
		if arr[i][ends] >= '3':
			if arr[i][ends ^ 1] < '3':
				ok = False
				break
			else:
				ends ^= 1
	if ok and ends == 1:
		print('YES')
	else:
		print('NO')


import sys
q = int(sys.stdin.readline())
while q:
	q -= 1
	n = int(sys.stdin.readline())
	pipe = [[], []]
	pip_type = {1: 1, 2: 1, 3: 2, 4: 2, 5: 2, 6: 2}
	for i in range(2):
		tmp = map(int, sys.stdin.readline().rstrip())
		pipe[i] = [pip_type[k] for k in tmp]
	state = [1, 0]
	SUCCESS = True
	for i in range(n):
		if not state[0] and (not state[1]):
			SUCCESS = False
			break
		tmp = [0, 0]
		if state[0]:
			tmp[0] = 1 if pipe[0][i] == 1 else 0
			tmp[1] = 1 if pipe[0][i] == 2 and pipe[1][i] == 2 else 0
		if state[1]:
			tmp[1] = 1 if tmp[1] or pipe[1][i] == 1 else 0
			tmp[0] = 1 if tmp[0] or (pipe[0][i] == 2 and pipe[1][i] == 2) else 0
		state = tmp
	if SUCCESS and state[1]:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	tube = [[0] * 2 for i in range(n + 1)]
	a = [int(x) for x in list(input())]
	b = [int(x) for x in list(input())]
	k = 0
	for i in range(n):
		if a[i] == 1 or a[i] == 2:
			tube[i][0] = 1
		if b[i] == 1 or b[i] == 2:
			tube[i][1] = 1
	for i in range(n):
		if tube[i][k] == 0:
			if tube[i][(k + 1) % 2] == 0:
				k = (k + 1) % 2
			else:
				print('NO')
				break
	else:
		if k == 0:
			print('NO')
		else:
			print('YES')


q = int(input())
j = 0
j1 = 0
final = []

def super():
	global j, j1
	l = int(input())
	x1 = input()
	y1 = input()
	x = [[int(xx) for xx in str(x1)], [int(xx) for xx in str(y1)]]
	global j
	for j in [0, 1]:
		for i in range(0, len(x[j])):
			if x[j][i] in [1, 2]:
				x[j][i] = 0
			else:
				x[j][i] = 1
	j = 0
	j1 = 0

	def next():
		global j, j1
		j1 = j
		if j == 0:
			j = 1
			return 1
		else:
			j = 0
			return 0
	flip = False
	i = 0
	while i < l - 1:
		if x[j][i] == 1:
			if not flip:
				flip = True
				if x[next()][i] != 1:
					final.append('NO')
					return
			else:
				flip = False
				i += 1
		else:
			i += 1
	if j == 0 and x[0][l - 1] == 1 and (x[1][l - 1] == 1) and (not flip) or (j == 1 and flip and (x[1][l - 1] == 1) and (j == j1)) or (j == 1 and x[1][l - 1] == 0):
		final.append('YES')
	else:
		final.append('NO')
for i in range(0, q):
	super()
for t in final:
	print(t)


Q = int(input())

def solve():
	N = int(input())
	top = [int(x) > 2 for x in input()]
	bot = [int(x) > 2 for x in input()]
	dp = [set() for _ in range(N)]
	flows = {}
	flows[0, 0] = [(0, 0), (1, 1)]
	flows[0, 1] = [(0, 0)]
	flows[1, 0] = [(1, 1)]
	flows[1, 1] = [(0, 1), (1, 0)]
	for i in range(N - 1, -1, -1):
		tp = (top[i], bot[i])
		if i == N - 1:
			for f in flows[tp]:
				if f[1] == 1:
					dp[i].add(f)
		else:
			for f in flows[tp]:
				for n in dp[i + 1]:
					if f[1] == n[0]:
						dp[i].add(f)
	for x in dp[0]:
		if x[0] == 0:
			return True
	return False
for _ in range(Q):
	print('YES' if solve() else 'NO')


q = int(input())
for i in range(q):
	n = int(input())
	s1 = input()
	s2 = input()
	layer = False
	for i in range(n):
		if layer:
			if s2[i] in ['6', '5', '3', '4']:
				if s1[i] in ['6', '5', '3', '4']:
					layer = not layer
				else:
					layer = False
					break
		elif s1[i] in ['6', '5', '3', '4']:
			if s2[i] in ['6', '5', '3', '4']:
				layer = not layer
			else:
				layer = False
				break
	if layer:
		print('YES')
	else:
		print('NO')


line = {1, 2}
ugol = {3, 4, 5, 6}
q = int(input())
for ii in range(q):
	n = int(input())
	a = [int(i) for i in input()]
	b = [int(i) for i in input()]
	t = 1
	for i in range(n):
		if t == 0:
			break
		if t == 1 and a[i] in line:
			continue
		if t == 1 and a[i] in ugol and (b[i] in ugol):
			t = 2
			continue
		if t == 2 and b[i] in line:
			continue
		if t == 2 and b[i] in ugol and (a[i] in ugol):
			t = 1
			continue
		if t == 3:
			if a[i] in line and b[i] in line:
				continue
			if a[i] in ugol and b[i] in ugol:
				continue
			if a[i] in line:
				t = 1
				continue
			if b[i] in line:
				t = 2
				continue
		t = 0
		break
	if t == 0 or t == 1:
		print('NO')
	else:
		print('YES')


q = int(input())
for _ in range(q):
	n = int(input())
	r1 = input()
	r2 = input()
	r = [r1, r2]
	from_side = True
	from_up = True
	pos = 0
	possible = True
	while pos < n:
		if from_side:
			if r[0 if from_up else 1][pos] in '12':
				pos += 1
			else:
				from_side = False
				from_up = from_up
		elif r[1 if from_up else 0][pos] in '12':
			possible = False
			break
		else:
			pos += 1
			from_side = True
			from_up = not from_up
	if from_up:
		possible = False
	if possible:
		print('YES')
	else:
		print('NO')


x = lambda i: 1 if i in ['1', '2'] else 0

def is_possible(m, d, i, j, n):
	while True:
		if j == n:
			return 'NO' if i == 0 else 'YES'
		if i == 0:
			if d == 'e':
				if m[i][j] == 1:
					j += 1
				else:
					d = 'd'
					i = 1
			elif d == 'u':
				if m[i][j] == 1:
					return 'NO'
				else:
					d = 'e'
					j += 1
			else:
				return 'NO'
		elif d == 'd':
			if m[i][j] == 1:
				return 'NO'
			else:
				j += 1
				d = 'e'
		elif d == 'e':
			if m[i][j] == 1:
				j += 1
			else:
				d = 'u'
				i = 0
		else:
			return 'NO'
for _ in range(int(input())):
	n = int(input())
	m = [list(map(x, input().strip())) for _ in range(2)]
	print(is_possible(m, 'e', 0, 0, n))


q = int(input())
h = {1: 0, 2: 0, 3: 1, 4: 1, 5: 1, 6: 1}
for w in range(q):
	n = int(input())
	a = [[int(i) for i in input()] for j in range(2)]
	dp = [[False for i in range(n)] for j in range(2)]
	if h[a[0][0]] == 1 and h[a[1][0]] == 0:
		print('NO')
	else:
		if h[a[0][0]] == 0:
			k = 0
		else:
			k = 1
		dp[k][0] = True
		f = 1
		for i in range(1, n):
			if h[a[k][i]] == 0:
				dp[k][i] = True
			elif h[a[1 - k][i]] == 0:
				break
			else:
				k = 1 - k
				dp[k][i] = True
		if dp[1][n - 1] == True:
			print('YES')
		else:
			print('NO')


from sys import stdin
from collections import defaultdict
p_type = {1: 1, 2: 1, 3: 2, 4: 2, 5: 2, 6: 2}

def c_poss(l1, l2, n):
	lvl = 0
	for i in range(n):
		c_p = l1[i] if lvl == 0 else l2[i]
		p_t = p_type[c_p]
		if p_t == 1:
			if i == n - 1:
				return lvl
		else:
			lvl = 1 - lvl
			n_p = l1[i] if lvl == 0 else l2[i]
			if p_type[n_p] == 1:
				return False
			elif i == n - 1:
				return lvl
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	l1 = list(map(int, list(stdin.readline().rstrip())))
	l2 = list(map(int, list(stdin.readline().rstrip())))
	print('YES' if c_poss(l1, l2, n) else 'NO')


def changerow(crow):
	if crow == 0:
		crow = 1
	else:
		crow = 0
	return crow
t = int(input())
d = {'s': (1, 2), 'c': (3, 4, 5, 6)}
while t > 0:
	t -= 1
	n = int(input())
	r1 = input()
	r2 = input()
	mat = [[int(i) for i in r1], [int(i) for i in r2]]
	crow = 0
	prv = mat[0][0]
	flag = 0
	for i in range(n):
		ele = mat[crow][i]
		if ele == 1 or ele == 2:
			continue
		else:
			crow2 = changerow(crow)
			if mat[crow][i] >= 3 and mat[crow2][i] >= 3:
				crow = changerow(crow)
				continue
			else:
				flag = 1
				break
	if flag == 1:
		print('NO')
	elif crow == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = [[int(x) for x in input()] for i in range(2)]
	cur = 0
	for i in range(n):
		if a[0][i] > 2 and a[1][i] > 2:
			cur ^= 1
		elif a[cur][i] > 2:
			print('NO')
			break
	else:
		print('YES' if cur == 1 else 'NO')


def solve(n, a):
	p = 0
	if n == 1:
		return 'YES' if a[0][0] == a[1][0] == 2 else 'NO'
	for i in range(n):
		if a[p][i] == 2:
			if a[p ^ 1][i] == 2:
				p ^= 1
			else:
				return 'NO'
	return 'YES' if p == 1 else 'NO'

def main():
	q = int(input())
	for i in range(q):
		n = int(input())
		a = []
		a.append([1 if int(x) == 1 or int(x) == 2 else 2 for x in input()])
		a.append([1 if int(x) == 1 or int(x) == 2 else 2 for x in input()])
		print(solve(n, a))
main()


t = int(input())
for i in range(t):
	n = int(input())
	tubes = []
	for j in range(2):
		tubes.append(list(map(int, list(input()))))
	r = [0, 0]
	fl_ord = False
	while True:
		if tubes[r[0]][r[1]] <= 2:
			if fl_ord:
				print('NO')
				break
			else:
				r[1] += 1
		else:
			if fl_ord:
				r[1] += 1
			else:
				r[0] = 1 - r[0]
			fl_ord = not fl_ord
		if r == [1, n]:
			print('YES')
			break
		elif r == [0, n]:
			print('NO')
			break


q = int(input())
for i in range(q):
	n = int(input())
	a = [input(), input()]
	ans = True
	x = 0
	y = 0
	h = 0
	while True:
		if y >= n:
			if x == 0:
				ans = False
			break
		if x == 0 and y == 0:
			if a[0][0] < '3':
				y = 1
			else:
				x = 1
		elif x == 0:
			if h == 0:
				if a[x][y] < '3':
					y += 1
				else:
					x = 1
			else:
				h = 0
				if a[x][y] < '3':
					ans = False
					break
				else:
					y += 1
		elif h == 0:
			h = 1
			if a[x][y] < '3':
				ans = False
				break
			else:
				y += 1
		elif a[x][y] < '3':
			y += 1
		else:
			x = 0
	if ans:
		print('YES')
	else:
		print('NO')


q = input()
inp = [input() for i in range(int(q) * 3)]
i = 0
j = 0
while i < int(q):
	l = int(inp[j])
	up = inp[j + 1]
	down = inp[j + 2]
	flow_down = False
	end = False
	for k in range(l):
		if k == 0:
			if int(up[k]) > 2 and int(down[k]) < 3:
				print('NO')
				end = True
				break
		if int(up[k]) > 2 and int(down[k]) > 2:
			flow_down = True if not flow_down else False
		elif flow_down and int(down[k]) > 2 and (int(up[k]) < 3):
			print('NO')
			end = True
			break
		elif not flow_down and int(down[k]) < 3 and (int(up[k]) > 2):
			print('NO')
			end = True
			break
	if not end:
		if flow_down:
			print('YES')
		else:
			print('NO')
	i += 1
	j += 3


from sys import *
for i in range(int(input())):
	n = int(stdin.readline())
	l1 = list(map(int, input()))
	l2 = list(map(int, input()))
	if n == 1:
		if l1[0] > 2 and l2[0] > 2:
			print('YES')
		else:
			print('NO')
		continue
	(top, bot) = (0, 0)
	if l1[0] < 3:
		top = 1
	if l1[0] > 2 and l2[0] > 2:
		bot = 1
	f = 0
	for i in range(1, n - 1):
		if top == 0 and bot == 0:
			f = 1
			break
		if top == 1 and bot == 0:
			if l1[i] < 3:
				continue
			if l1[i] > 2 and l2[i] > 2:
				bot = 1
				top = 0
			else:
				f = 1
				break
		elif top == 0 and bot == 1:
			if l2[i] < 3:
				continue
			if l2[i] > 2 and l1[i] > 2:
				top = 1
				bot = 0
			else:
				f = 1
				break
	if f:
		print('NO')
	elif top == 1 and l1[-1] > 2 and (l2[-1] > 2):
		print('YES')
	elif bot == 1 and l2[-1] < 3:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	l1 = list(map(int, input()))
	l2 = list(map(int, input()))
	(row, col) = (0, 0)
	vert = False
	ans = ''
	type1 = [1, 2]
	type2 = [3, 4, 5, 6]
	while True:
		if row not in [0, 1] or col >= n:
			ans = 'NO'
			break
		if row == 1 and col == n - 1:
			if vert == True:
				ans = 'YES' if l2[col] in type2 else 'NO'
			else:
				ans = 'YES' if l2[col] in type1 else 'NO'
			break
		elif row == 0 and col == 0:
			if l1[col] in type1:
				vert = False
				col += 1
			else:
				vert = True
				row += 1
		elif row == 0:
			if l1[col] in type1:
				if vert == True:
					row -= 1
				else:
					col += 1
					vert = False
			elif vert == True:
				col += 1
				vert = False
			else:
				row += 1
				vert = True
		elif l2[col] in type1:
			if vert == True:
				row += 1
			else:
				col += 1
				vert = False
		elif vert == True:
			col += 1
			vert = False
		else:
			row -= 1
			vert = True
	print(ans)


import os
T = int(input())
for t in range(T):
	n = int(input())
	s = [[int(i) for i in input()] for j in range(2)]
	idx = 0
	for i in range(n):
		if s[0][i] > 2 and s[1][i] > 2:
			idx ^= 1
		else:
			if s[0][i] > 2 and idx == 0:
				break
			if s[1][i] > 2 and idx == 1:
				idx = 0
				break
	if idx:
		print('YES')
	else:
		print('NO')


def solve():
	n = int(input())
	r1 = input()
	r2 = input()
	top = 1
	for i in range(n):
		if top:
			if int(r1[i]) > 2:
				if int(r2[i]) > 2:
					top = 0
				else:
					print('NO')
					return
		elif int(r2[i]) > 2:
			if int(r1[i]) > 2:
				top = 1
			else:
				print('NO')
				return
	if top:
		print('NO')
		return
	print('YES')
for _ in range(int(input())):
	solve()


def sol():
	w = int(input())
	path = []
	for i in range(2):
		arr = list(map(int, list(input())))
		for g in range(w):
			if arr[g] == 2 or arr[g] == 1:
				arr[g] = 1
			else:
				arr[g] = 2
		path.append(arr)
	allOkay = True
	nowX = 0
	nowY = 0
	lastDir = 0
	if path[0][0] == 1:
		nowX += 1
		lastDir = 2
	else:
		nowY += 1
		lastDir = 1
	for i in range(2 * w + 1):
		if nowY == 1 and nowX == w:
			break
		elif nowX < 0 or nowX >= w:
			allOkay = False
			break
		elif nowY < 0 or nowY >= 2:
			allOkay = False
			break
		picked = False
		if lastDir == 2:
			if path[nowY][nowX] == 1:
				nowX += 1
				lastDir = 2
			elif nowY == 0:
				lastDir = 1
				nowY += 1
			else:
				lastDir = 3
				nowY -= 1
			picked = True
		elif lastDir == 1 or lastDir == 3:
			if path[nowY][nowX] == 2:
				nowX += 1
				lastDir = 2
				picked = True
		if picked:
			continue
		else:
			allOkay = False
			break
	if allOkay:
		print('YES')
	else:
		print('NO')
for _ in range(int(input())):
	sol()


q = int(input())
for i in range(q):
	n = int(input())
	tab = [[True, False]]
	s1 = input()
	s2 = input()
	for j in range(1, n + 1):
		up = False
		down = False
		if int(s1[j - 1]) < 3 and tab[j - 1][0]:
			up = True
		if int(s2[j - 1]) < 3 and tab[j - 1][1]:
			down = True
		if int(s1[j - 1]) > 2 and int(s2[j - 1]) > 2 and tab[j - 1][0]:
			down = True
		if int(s1[j - 1]) > 2 and int(s2[j - 1]) > 2 and tab[j - 1][1]:
			up = True
		tab.append([up, down])
	if tab[n][1]:
		print('YES')
	else:
		print('NO')


que = int(input())
a = []
for i in range(que):
	n = int(input())
	bool_map = lambda x: True if int(x) <= 2 else False
	row1 = list(map(bool_map, input().strip('\n')))
	row2 = list(map(bool_map, input().strip('\n')))
	current = False
	for (r1, r2) in zip(row1, row2):
		if r1 and (not current):
			pass
		elif r2 and current:
			pass
		elif not r1 and (not r2):
			current = not current
		else:
			current = False
			break
	if current:
		a.append('YES')
	else:
		a.append('NO')
print('\n'.join(a))


for _ in range(int(input())):
	n = int(input())
	r1 = input()
	r2 = input()
	flag = 1
	count = 0
	f = 1
	for i in range(n):
		if r1[i] in '3456' and r2[i] in '3456':
			count += 1
			if f:
				f = 0
			else:
				f = 1
		elif f and (r1[i] in '3456' and r2[i] in '12'):
			flag = 0
			break
		elif not f and (r1[i] in '12' and r2[i] in '3456'):
			flag = 0
			break
	if count % 2 and flag:
		print('YES')
	else:
		print('NO')


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(str, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
T = int(input())
while T > 0:
	n = int(input())
	string1 = input()
	string2 = input()
	dp1 = [False] * n
	dp2 = [False] * n
	if '1' <= string1[0] <= '2':
		dp1[0] = True
	if '3' <= string1[0] <= '6' and '3' <= string2[0] <= '6':
		dp2[0] = True
	for i in range(n - 1):
		if dp1[i] and '1' <= string1[i + 1] <= '2':
			dp1[i + 1] = True
		if dp1[i] and '3' <= string1[i + 1] <= '6' and ('3' <= string2[i + 1] <= '6'):
			dp2[i + 1] = True
		if dp2[i] and '1' <= string2[i + 1] <= '2':
			dp2[i + 1] = True
		if dp2[i] and '3' <= string2[i + 1] <= '6' and ('3' <= string1[i + 1] <= '6'):
			dp1[i + 1] = True
	print(['No', 'Yes'][dp2[-1]])
	T -= 1


for q in range(int(input())):
	n = int(input())
	s = [None, None]
	s[0] = input()
	s[1] = input()
	o = 'YES'
	r = 0
	for i in range(n):
		if s[r][i] in '12':
			continue
		elif s[r ^ 1][i] not in '12':
			r ^= 1
		else:
			o = 'NO'
			break
	if r == 0:
		o = 'NO'
	print(o)


t = int(input())
for test in range(t):
	n = int(input())
	line = []
	dp = []
	for i in range(2):
		dp.append([False] * (n + 2))
	line.append(list('0' + input() + '0'))
	line.append(list('0' + input() + '0'))
	sol = True
	last = [True, False]
	for i in range(1, n + 1):
		new = [False, False]
		both = 0
		if line[0][i] == '1' or line[0][i] == '2':
			new[0] = last[0]
		else:
			both += 1
		if line[1][i] == '1' or line[1][i] == '2':
			new[1] = last[1]
		else:
			both += 1
		if both == 2:
			new[0] = last[1]
			new[1] = last[0]
		last = new
		if not last[0] and (not last[1]):
			break
			sol = False
	if last[1]:
		print('YES')
	else:
		print('NO')


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	grid = [None] * 2
	grid[0] = list(map(int, list(input())))
	grid[1] = list(map(int, list(input())))
	cur = 0
	for i in range(N):
		if grid[0][i] <= 2 and grid[1][i] <= 2:
			pass
		elif grid[0][i] > 2 and grid[1][i] > 2:
			cur = 1 - cur
		elif grid[cur][i] > 2:
			NO()
			break
	else:
		if cur == 1:
			YES()
		else:
			NO()


def main():
	q = int(input())
	for i in range(q):
		n = int(input())
		a = input()
		b = input()
		t = 0
		level = 0
		while t < n:
			if level == 0 and (a[t] == '2' or a[t] == '1'):
				t += 1
			elif level == 0 and (a[t] == '3' or a[t] == '4' or a[t] == '5' or (a[t] == '6')) and (b[t] == '1' or b[t] == '2'):
				print('NO')
				break
			elif level == 0 and (a[t] == '3' or a[t] == '4' or a[t] == '5' or (a[t] == '6')) and (b[t] == '3' or b[t] == '4' or b[t] == '5' or (b[t] == '6')):
				level = 1
				t += 1
			elif level == 1 and (b[t] == '3' or b[t] == '4' or b[t] == '5' or (b[t] == '6')) and (a[t] == '1' or a[t] == '2'):
				print('NO')
				break
			elif level == 1 and (b[t] == '3' or b[t] == '4' or b[t] == '5' or (b[t] == '6')) and (a[t] == '3' or a[t] == '4' or a[t] == '5' or (a[t] == '6')):
				level = 0
				t += 1
			elif level == 1 and (b[t] == '2' or b[t] == '1'):
				t += 1
		if t == n and level == 1:
			print('YES')
		if t == n and level == 0:
			print('NO')
main()


from sys import stdin
q = int(stdin.readline().strip())
for _ in range(q):
	n = int(stdin.readline().strip())
	arr = []
	for k in range(2):
		arr.append(list(map(int, list(stdin.readline().strip()))))
	i = 0
	j = 0
	f = 'l'
	while True:
		if j == n:
			break
		if i < 0 or i >= 2:
			break
		if f == 'l':
			if arr[i][j] in [1, 2]:
				j += 1
				f = 'l'
			elif arr[i][j] in [3, 4, 5, 6]:
				if i == 0:
					f = 't'
					i += 1
				elif i == 1:
					f = 'd'
					i -= 1
				else:
					break
		elif f == 'd':
			if arr[i][j] in [1, 2]:
				break
			elif arr[i][j] in [3, 4, 5, 6]:
				if i == 0:
					j += 1
					f = 'l'
				else:
					break
		elif f == 't':
			if arr[i][j] in [1, 2]:
				break
			elif arr[i][j] in [3, 4, 5, 6]:
				if i == 1:
					j += 1
					f = 'l'
				else:
					break
	if i == 1 and j == n:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	row_1 = input().replace('2', '1').replace('3', '2').replace('4', '2').replace('5', '2').replace('6', '2')
	row_2 = input().replace('2', '1').replace('3', '2').replace('4', '2').replace('5', '2').replace('6', '2')
	place = 1
	flag = True
	for i in range(len(row_2)):
		if place == 1 and row_1[i] == '2' and (row_2[i] == '2'):
			place = 2
		elif place == 2 and row_1[i] == '2' and (row_2[i] == '2'):
			place = 1
		elif place == 1 and (row_1[i] == '2' and row_2[i] == '1') or (place == 2 and (row_1[i] == '1' and row_2[i] == '2')):
			flag = False
	if flag and place == 2:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	s1 = [int(x) for x in input().strip()]
	s2 = [int(x) for x in input().strip()]
	a = [s1, s2]
	j = 0
	i = 0
	b = 0
	if n == 1:
		if a[0][0] >= 3 and a[1][0] >= 3:
			print('YES')
		else:
			print('NO')
	else:
		if a[i][j] < 3:
			j += 1
			b = 0
		else:
			i = 1
			j = 0
			b = 0
		while j < n:
			if a[i][j] < 3:
				if i != b:
					break
				j += 1
			elif b == i:
				b = i
				i = 1 - i
			else:
				j += 1
				b = i
		if n == j and i == 1:
			print('YES')
		else:
			print('NO')


tc = int(input())
for i in range(tc):
	n = int(input())
	p1 = input()
	p2 = input()
	l = 0
	c = 0
	hor = True
	ok = True
	while ok:
		if l == n:
			if c == 1:
				ok = True
			else:
				ok = False
			break
		if c == 0:
			crt = p1[l]
		else:
			crt = p2[l]
		if crt == '1' or crt == '2':
			tp = 0
		else:
			tp = 1
		if c == 0:
			if tp == 0:
				if hor:
					l += 1
				else:
					ok = False
					break
			else:
				if hor:
					c += 1
				else:
					l += 1
				hor = not hor
		elif tp == 0:
			if hor:
				l += 1
			else:
				ok = False
				break
		else:
			if hor:
				c -= 1
			else:
				l += 1
			hor = not hor
	if ok:
		print('YES')
	else:
		print('NO')


def solve(n, a):
	(row, pos) = (0, -1)
	for i in range(n):
		if int(a[row][i]) >= 3 and int(a[row ^ 1][i]) <= 2:
			break
		else:
			if int(a[row][i]) >= 3 and int(a[row ^ 1][i]) >= 3:
				row = row ^ 1
			pos = i
	if row == 1 and pos == n - 1:
		return 1
	return 0
t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	for _ in range(2):
		a.append(input())
	if solve(n, a):
		print('YES')
	else:
		print('NO')


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

def num():
	return int(input())
from itertools import repeat
q = num()
st = {1, 2}
for _ in repeat(None, q):
	n = num()
	tubes = [list(map(int, input())) for _ in range(2)]
	c = [1, 0]
	for i in range(n):
		if not c[0] and (not c[1]):
			break
		p = (tubes[0][i], tubes[1][i])
		r = [0, 0]
		if c[0]:
			if p[0] not in st and p[1] not in st:
				r[1] = 1
			if p[0] in st:
				r[0] = 1
		if c[1]:
			if p[0] not in st and p[1] not in st:
				r[0] = 1
			if p[1] in st:
				r[1] = 1
		c = r
	print('YES' if c[1] else 'NO')


for _ in range(int(input())):
	n = int(input())
	s = [''] * 2
	s[0] = input()
	s[1] = input()
	p = 0
	for i in range(n):
		if s[p][i] > '2':
			p = 1 - p
			if s[p][i] <= '2':
				p = 0
				break
	print('YES' if p else 'NO')


for _ in range(int(input())):
	n = int(input())
	s = [input(), input()]
	x = 0
	for i in range(n):
		if s[x][i] != '1' and s[x][i] != '2':
			x ^= 1
			if s[x][i] == '1' or s[x][i] == '2':
				x = 0
				break
	if x == 1:
		print('YES')
	else:
		print('NO')


a = int(input())
for i in range(a):
	ln = int(input())
	pipe = [[], []]
	for j in range(2):
		pipe[j] = list(input())
		pipe[j] = list(map(int, pipe[j]))
	for j in range(2):
		for k in range(ln):
			if pipe[j][k] <= 2:
				pipe[j][k] = 1
			else:
				pipe[j][k] = 2
	prev = 0
	crd = [0, 0]
	while crd[1] < ln and (crd[0] == 0 or crd[0] == 1):
		if crd[0] == 0:
			if prev == 0:
				if pipe[crd[0]][crd[1]] == 1:
					crd[1] += 1
				else:
					crd[0] += 1
					prev = 1
			elif pipe[crd[0]][crd[1]] == 1:
				crd[0] += prev
			else:
				crd[1] += 1
				prev = 0
		elif prev == 0:
			if pipe[crd[0]][crd[1]] == 1:
				crd[1] += 1
			else:
				crd[0] += -1
				prev = -1
		elif pipe[crd[0]][crd[1]] == 1:
			crd[0] += prev
		else:
			crd[1] += 1
			prev = 0
	if crd == [1, ln]:
		print('YES')
	else:
		print('NO')


input = __import__('sys').stdin.readline
print = __import__('sys').stdout.write
thres = 3
for _ in range(int(input())):
	current = False
	N = int(input())
	tmp = [list(map(int, list(input()[:-1]))), list(map(int, list(input()[:-1])))]
	for i in range(N):
		if tmp[current][i] < thres:
			continue
		elif tmp[not current][i] < thres:
			break
		else:
			current = not current
	else:
		if current:
			print('YES\n')
		else:
			print('NO\n')
		continue
	print('NO\n')


q = int(input())
for iter in range(q):
	arr = []
	n = int(input())
	for read in range(2):
		arr.append([int(x) for x in list(input())])
	curr_i = 0
	curr_j = 0
	flag = 0
	while curr_j < n:
		ele = arr[curr_i][curr_j]
		if ele == 1 or ele == 2:
			curr_j += 1
		else:
			curr_i = 1 - curr_i
			new_ele = arr[curr_i][curr_j]
			if new_ele == 1 or new_ele == 2:
				flag = 1
				break
			curr_j += 1
	if curr_i == 0 or flag == 1:
		print('NO')
	else:
		print('YES')


q = int(input().strip())
for _ in range(q):
	n = int(input().strip())
	s = []
	s.append(input())
	s.append(input())
	possible = True
	from_pipe = 0
	other_pipe = 1
	for i in range(n):
		if not (s[from_pipe][i] == '1' or s[from_pipe][i] == '2'):
			if not (s[other_pipe][i] == '1' or s[other_pipe][i] == '2'):
				from_pipe = 1 - from_pipe
				other_pipe = 1 - other_pipe
			else:
				possible = False
				break
	if possible == False or from_pipe == 0:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	n = int(input())
	S = [input()[:-1] for _ in range(2)]
	(cx, cy, dire) = (0, 0, 0)
	while True:
		if dire == 0 and S[cx][cy] in ['1', '2']:
			cy += 1
		elif dire == 0 and S[cx][cy] in ['3', '4', '5', '6']:
			if cx == 0:
				cx = 1
				dire = 2
			elif cx == 1:
				cx = 0
				dire = 1
		elif dire == 1 and S[cx][cy] in ['1', '2']:
			print('NO')
			break
		elif dire == 1 and S[cx][cy] in ['3', '4', '5', '6']:
			cy += 1
			dire = 0
		elif dire == 2 and S[cx][cy] in ['1', '2']:
			print('NO')
			break
		elif dire == 2 and S[cx][cy] in ['3', '4', '5', '6']:
			cy += 1
			dire = 0
		if cy == n:
			if cx == 1:
				print('YES')
			else:
				print('NO')
			break


for i in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	a = [s1, s2]
	lvl = 0
	f = True
	for i in range(n):
		if '1' <= a[lvl][i] <= '2':
			continue
		elif '1' <= a[(lvl + 1) % 2][i] <= '2':
			f = False
			break
		else:
			lvl = (lvl + 1) % 2
	print('YES' if f and lvl == 1 else 'NO')


q = int(input())
for k in range(q):
	n = int(input())
	arr1 = input()
	arr2 = input()
	arr = []
	for i in range(n):
		arr.append([int(arr1[i]), int(arr2[i])])
	path = True
	new = 0
	for i in range(n):
		if 1 <= arr[i][new] <= 2:
			continue
		elif 1 <= arr[i][(new + 1) % 2] <= 2:
			path = False
			break
		else:
			new = (new + 1) % 2
	print('YES' if path and new == 1 else 'NO')


for q in range(int(input())):
	n = int(input())
	d1 = [c > '2' for c in input()]
	d2 = [c > '2' for c in input()]
	dp = [[1, 0]]
	for i in range(n):
		ans = [0, 0]
		if dp[-1][0]:
			if d1[i] == 0:
				ans[0] = 1
			elif d1[i] and d2[i]:
				ans[1] = 1
		if dp[-1][1]:
			if d2[i] == 0:
				ans[1] = 1
			elif d1[i] and d2[i]:
				ans[0] = 1
		dp.append(ans)
	print(['NO', 'YES'][dp[-1][1]])


for x in range(int(input())):
	n = int(input())
	a = []
	for y in range(2):
		a.append(list(input()))
	(i, j) = (0, 0)
	prev = [i, j]
	ok = False
	while True:
		if j == n - 1:
			if i == 0:
				if a[i][j] not in '12' and a[i + 1][j] not in '12':
					ok = True
			elif i == 1:
				if a[i][j] in '12':
					ok = True
			break
		if a[i][j] in '12':
			prev[0] = i
			prev[1] = j
			j += 1
		elif i == j == 0:
			if a[1][0] not in '12':
				i += 1
			else:
				break
		elif i == 1 and prev[0] + 1 == i:
			prev[0] = i
			prev[1] = j
			j += 1
		elif i == 1 and prev[1] + 1 == j:
			if a[i - 1][j] in '12':
				break
			else:
				prev[0] = i
				prev[1] = j
				i -= 1
		elif i == 0 and prev[0] - 1 == i:
			prev[0] = i
			prev[1] = j
			j += 1
		elif i == 0 and prev[1] + 1 == j:
			if a[i + 1][j] in '12':
				break
			else:
				prev[0] = i
				prev[1] = j
				i += 1
	if ok == True:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, list(input())))
	l2 = list(map(int, list(input())))
	line = 0
	for i in range(n):
		if line == 0:
			if l1[i] == 1 or l1[i] == 2:
				continue
			elif l2[i] != 1 and l2[i] != 2:
				line = 1
			else:
				line = 0
				break
		elif l2[i] == 1 or l2[i] == 2:
			continue
		elif l1[i] != 1 and l1[i] != 2:
			line = 0
		else:
			line = 0
			break
	if line == 1:
		print('YES')
	else:
		print('NO')


mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 6)
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import collections
import math
import heapq
import random

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	t = inin()
	for _ in range(t):
		n = inin()
		a = []
		a.append(list(sin()))
		a.append(list(sin()))
		for i in range(2):
			for j in range(n):
				x = int(a[i][j])
				if x / 3 < 1:
					a[i][j] = 1
				else:
					a[i][j] = 2
		x = 0
		ans = 'NO'
		tt = 1
		for i in range(n - 1):
			if a[x][i] == 2:
				if a[x ^ 1][i] == 2:
					x = x ^ 1
				else:
					tt = 0
					break
		if x == 0 and tt == 1 and (a[x][n - 1] == 2) and (a[x ^ 1][n - 1] == 2):
			ans = 'YES'
		if x == 1 and tt == 1 and (a[x][n - 1] == 1):
			ans = 'YES'
		print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


import sys
import math
from collections import defaultdict
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass

def takeInput():
	return [int(x) for x in input().strip().split()]

class Graph:

	def __init__(self):
		self.neighbours = defaultdict(list)

	def addEdge(self, u, v):
		self.neighbours[u].append(v)

	def BFS(self, destination):
		queue = [1]
		visited = defaultdict(lambda : False)
		while queue:
			u = queue.pop(0)
			if u == destination:
				return True
			for v in self.neighbours[u]:
				if not visited[v]:
					visited[v] = True
					queue.append(v)
		return False
t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	row1 = input()
	row2 = input()
	row1 = [int(x) for x in list(row1)]
	row2 = [int(x) for x in list(row2)]
	for (i, r) in enumerate(row1):
		if r == 1 or r == 2:
			row1[i] = 1
		else:
			row1[i] = 3
	for (i, r) in enumerate(row2):
		if r == 1 or r == 2:
			row2[i] = 1
		else:
			row2[i] = 3
	maze = [0] + row1 + row2 + [0]
	g = Graph()
	for i in range(1, 2 * n + 1):
		if maze[i] == 1:
			if i != n:
				g.addEdge(i, i + 1)
		if i <= n:
			if maze[i] == 3 and maze[i + n] == 3:
				g.addEdge(i, i + n + 1)
		elif maze[i] == 3 and maze[i - n] == 3:
			if i != 2 * n:
				g.addEdge(i, i - n + 1)
	destination = 2 * n + 1
	if g.BFS(destination):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s = [input(), input()]
	i = -1
	j = 0
	while i < n - 1:
		if s[j][i + 1] < '3':
			i += 1
		elif s[j ^ 1][i + 1] > '2':
			i += 1
			j ^= 1
		else:
			print('NO')
			break
	else:
		if j == 1:
			print('YES')
		else:
			print('NO')


for nt in range(int(input())):
	n = int(input())
	dp = []
	dp.append(input())
	dp.append(input())
	curr = [1, 1]
	prev = 0
	while True:
		if int(dp[curr[0] - 1][curr[1] - 1]) <= 2:
			if prev == 1:
				flag = 0
				break
			curr = [curr[0], curr[1] + 1]
			prev = 0
		elif prev == 0:
			if curr[0] == 1:
				curr = [curr[0] + 1, curr[1]]
			else:
				curr = [curr[0] - 1, curr[1]]
			prev = 1
		elif prev == 1:
			curr = [curr[0], curr[1] + 1]
			prev = 0
		if curr[0] == 2 and curr[1] == n + 1:
			flag = 1
			break
		if curr[0] > 2 or curr[1] > n:
			flag = 0
			break
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	o = input()
	o1 = input()
	arr = [[], []]
	for i in range(n):
		if o[i] == '1' or o[i] == '2':
			arr[0] += [1]
		else:
			arr[0] += [2]
		if o1[i] == '1' or o1[i] == '2':
			arr[1] += [1]
		else:
			arr[1] += [2]
	a = 0
	b = 0
	flag = True
	while b < n:
		if arr[a][b] == 1:
			b += 1
		elif arr[a][b] == 2 and a == 0:
			a = 1
			if arr[a][b] == 1:
				flag = False
				break
			else:
				b += 1
		elif arr[a][b] == 2 and a == 1:
			a = 0
			if arr[a][b] == 1:
				flag = False
				break
			else:
				b += 1
	if flag and a == 1:
		print('YES')
	else:
		print('NO')


for rpt in range(int(input())):
	pipelength = int(input())
	cross = [input(), input()]
	parity = 0
	for i in range(pipelength):
		if not (cross[parity][i] == '1' or cross[parity][i] == '2'):
			if not (cross[(parity + 1) % 2][i] == '1' or cross[(parity + 1) % 2][i] == '2'):
				parity = (parity + 1) % 2
			else:
				parity = 0
				break
	if parity == 1:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	s = [input(), input()]
	l2 = ['1', '2']
	g2 = ['3', '4', '5', '6']
	s = [[c for c in l] for l in s]
	b = [[True], [False]]
	for i in range(n):
		for j in range(2):
			c = s[j][i]
			x = False
			if c in l2 and b[j][i]:
				x = True
			if c in g2 and s[j ^ 1][i] in g2 and b[j ^ 1][i]:
				x = True
			b[j].append(x)
	print('YES' if b[1][-1] else 'NO')


import heapq
import math
import sys
input = sys.stdin.readline

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def value():
	return int(input())

def typ(a):
	if a < 3:
		return 1
	return 2
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().rstrip('\n')))
	b = list(map(int, input().rstrip('\n')))
	for i in range(n):
		a[i] = [a[i], b[i]]
	ans = 1
	currline = 0
	for i in range(n):
		if typ(a[i][currline]) == 2:
			currline = not currline
			if typ(a[i][currline]) == 1:
				ans = 0
				break
	if currline == 0:
		ans = 0
	if ans:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	reachable = True
	path = zip(map(int, list(input().strip())), map(int, list(input().strip())))
	level = False
	for step in path:
		if step[level] in {1, 2}:
			pass
		elif 1 not in step and 2 not in step:
			level = not level
		else:
			reachable = False
			break
	print('YES' if reachable and level else 'NO')


n = int(input())
ans = []
for _ in range(n):
	a = int(input())
	b = input()
	c = input()
	s = [b, c]
	row = 0
	count = 0
	for i in range(a):
		if s[row][i] >= '3':
			if s[row ^ 1][i] < '3':
				break
			else:
				row = row ^ 1
		count += 1
	if row == 1 and count == a:
		ans.append('YES')
	else:
		ans.append('NO')
for i in ans:
	print(i)


tc = int(input())

def check(p, n):
	if 0 <= p[0] <= 1 and 0 <= p[1] <= n:
		return True
	else:
		return False
outs = []
for i in range(tc):
	n = int(input())
	strs = []
	strs.append(input())
	strs.append(input())
	p = [0, 0]
	flag = 0
	while True:
		if strs[p[0]][p[1]] in ['1', '2']:
			p[1] += 1
		elif strs[p[0]][p[1]] not in ['1', '2'] and strs[1 - p[0]][p[1]] not in ['1', '2']:
			p[0] = 1 - p[0]
			p[1] += 1
		else:
			flag = 0
			break
		if not check(p, n - 1):
			flag = 1
			break
	if flag == 0:
		outs.append('NO')
	elif p != [1, n]:
		outs.append('NO')
	else:
		outs.append('YES')
for i in outs:
	print(i)


R = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	mx = [list(map(int, input())), list(map(int, input()))]
	vis = [[0] * (n + 1) for i in range(2)]
	vis[0][0] = 1
	for c in range(n):
		for r in range(2):
			if vis[r][c] > 0:
				if 1 <= mx[r][c] <= 2:
					vis[r][c + 1] = 1
				elif 3 <= mx[r][c] <= 6 and 3 <= mx[1 - r][c] <= 6:
					vis[1 - r][c + 1] = 1
	print('YES' if vis[1][n] else 'NO')


def function(a):
	r = 0
	c = 0
	flip = False
	n = len(a[0])
	if n == 1:
		if a[0][0] > 2 and a[1][0] > 2:
			return 'YES'
		else:
			return 'NO'
	while c < n:
		if a[r][c] > 2 and (not flip):
			r = 0 if r else 1
			flip = True
		elif flip and a[r][c] <= 2:
			return 'NO'
		elif a[r][c] > 2:
			flip = False
			c += 1
		else:
			c += 1
			flip = False
	if r == 0:
		return 'NO'
	if c == n:
		return 'YES'
	return 'NO'
n = int(input())
for _ in range(n):
	_ = input()
	a = []
	a.append(list(map(int, input())))
	a.append(list(map(int, input())))
	print(function(a))


def soln() -> None:

	def logic() -> None:
		n = int(input())
		A = list(input())
		B = list(input())
		one = ('1', '2')
		two = ('3', '4', '5', '6')
		shift = False
		for (i, j) in zip(A, B):
			if not shift:
				if i not in one:
					shift = not shift
					if j not in two:
						print('NO')
						break
			elif j not in one:
				shift = not shift
				if i not in two:
					print('NO')
					break
		else:
			if shift:
				print('YES')
			else:
				print('NO')
	for _ in range(int(input())):
		logic()
soln()


for i in range(int(input())):
	n = int(input())
	(s1, s2) = (input(), input())
	b = [[int(s1[i]), int(s2[i])] for i in range(n)][::-1]
	a = 1
	ans = 'YES'
	for i in b:
		if i[a] > 2:
			if i[a ^ 1] < 3:
				ans = 'NO'
			else:
				a ^= 1
	if a != 0:
		ans = 'NO'
	print(ans)


q = int(input())
res = list()
for i in range(q):
	n = int(input())
	pt = input()
	pb = input()
	flag = True
	counter = 1
	for i in range(n):
		if counter == 1:
			if pt[i] == '3' or pt[i] == '4' or pt[i] == '5' or (pt[i] == '6'):
				if pb[i] == '3' or pb[i] == '4' or pb[i] == '5' or (pb[i] == '6'):
					counter = 2
					flag = True
				else:
					flag = False
					break
		elif counter == 2:
			if pb[i] == '3' or pb[i] == '4' or pb[i] == '5' or (pb[i] == '6'):
				flag = False
				if pt[i] == '3' or pt[i] == '4' or pt[i] == '5' or (pt[i] == '6'):
					counter = 1
					flag = True
				else:
					flag = False
					break
	if counter == 2 and flag == True:
		res.append('YES')
	else:
		res.append('NO')
for i in res:
	print(i)


q = int(input())
for _ in range(q):
	n = int(input())
	p = 0
	a = [1, 1]
	a[0] = input()
	a[1] = input()
	(f, h, i) = (0, 1, 0)
	while i < n - 1:
		k = a[h - 1][i]
		if f == 0:
			if k == '1' or k == '2':
				i += 1
			else:
				if h == 1:
					h = 2
				else:
					h = 1
				f = 1
		elif k == '1' or k == '2':
			print('NO')
			p = p + 1
			break
		else:
			f = 0
			i += 1
	if p == 0:
		if h == 2:
			k = a[h - 1][i]
			if k == '1' or k == '2':
				print('YES')
			else:
				print('NO')
		else:
			(k, t) = (a[0][i], a[1][i])
			z = ['3', '4', '5', '6']
			if k in z and t in z:
				print('YES')
			else:
				print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	t1 = list(input())
	t2 = list(input())
	l1 = list(t1)
	l2 = list(t2)
	flag = 0
	for i in range(n):
		if int(l1[i]) >= 3:
			if int(l2[i]) >= 3:
				(l1, l2) = (l2, l1)
			else:
				flag = 1
				break
	if flag == 1:
		print('NO')
	elif l1 == t2 and l1 != t1:
		print('YES')
	else:
		print('NO')


def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		row1 = [0] + [int(x) for x in input()]
		row2 = [0] + [int(x) for x in input()]
		i = 1
		j = 0
		ok = True
		while j < n and ok:
			if i == 1:
				if row1[j + 1] <= 2:
					j += 1
				elif row2[j + 1] >= 3:
					i = 2
					j += 1
				else:
					ok = False
			elif row2[j + 1] <= 2:
				j += 1
			elif row1[j + 1] >= 3:
				i = 1
				j += 1
			else:
				ok = False
		if not ok:
			print('NO')
		elif i == 2:
			print('YES')
		else:
			print('NO')
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(i, j):
	print('? {} {}'.format(i, j))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(' '.join([str(x) for x in ans])))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


q = int(input())
for i in range(q):
	n = int(input())
	l1 = list(input())
	l1 = [int(i) for i in l1]
	l2 = list(input())
	l2 = [int(i) for i in l2]
	l = [l1, l2]
	a = 0
	b = 0
	possible = 'YES'
	while True:
		if b == n and a == 1:
			break
		elif b == n and a == 0:
			possible = 'NO'
			break
		elif l[a][b] == 1 or l[a][b] == 2:
			b += 1
		elif a == 0 and l[a + 1][b] > 2:
			a += 1
			b += 1
		elif a == 1 and l[a - 1][b] > 2:
			b += 1
			a -= 1
		else:
			possible = 'NO'
			break
	print(possible)


for _ in range(int(input())):
	n = int(input())
	a = list(map('12'.__contains__, input().strip()))
	b = list(map('12'.__contains__, input().strip()))
	(u, d) = (True, False)
	for i in range(n):
		if a[i]:
			if not b[i]:
				d = False
		elif b[i]:
			u = False
		else:
			(u, d) = (d, u)
		if not (u or d):
			break
	print('YES' if d else 'NO')


from sys import stdin, exit
from typing import List, Tuple

def swap_row(row: int) -> int:
	return abs(row - 1)

def is_curved(pipe: int) -> bool:
	return 3 <= pipe <= 6

def is_straight(pipe: int) -> bool:
	return 1 <= pipe <= 2

def can_water_flow(pipes: List[List[int]]) -> bool:
	curr_row = 0
	for i in range(len(pipes[0])):
		if is_straight(pipes[curr_row][i]):
			continue
		elif is_straight(pipes[swap_row(curr_row)][i]):
			return False
		else:
			curr_row = swap_row(curr_row)
	return curr_row == 1
queries = int(stdin.readline().rstrip())
for _ in range(queries):
	stdin.readline()
	pipes = [None, None]
	pipes[0] = [int(v) for v in stdin.readline().rstrip()]
	pipes[1] = [int(v) for v in stdin.readline().rstrip()]
	print(('NO', 'YES')[can_water_flow(pipes)])


import sys
input = sys.stdin.readline
from collections import *
q = int(input())
for _ in range(q):
	n = int(input())
	pipes = ['', '']
	pipes[0] = input().strip()
	pipes[1] = input().strip()
	pos = 0
	ans = 'YES'
	for i in range(n):
		if pipes[pos][i] > '2':
			if pipes[1 - pos][i] > '2':
				pos = 1 - pos
			else:
				ans = 'NO'
				break
	if pos == 0:
		ans = 'NO'
	print(ans)


import sys
input = lambda : sys.stdin.readline()
MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : list(map(int, input().split()))
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
lstr = lambda : list(input().split())
st2 = {'3', '4', '5', '6'}
for _ in range(ii()):
	n = ii()
	s1 = si()
	s2 = si()
	l = [s1, s2]
	pfg = 0
	fg = 0
	for i in range(n):
		if l[pfg][i] in st2:
			if not l[pfg ^ 1][i] in st2:
				fg = 1
				break
			else:
				pfg ^= 1
	if fg == 0 and pfg == 1:
		print('YES')
	else:
		print('NO')


from collections import defaultdict, Counter
import os
import sys
from io import BytesIO, IOBase
ii = lambda : int(input())
lmii = lambda : list(map(int, input().split()))
slmii = lambda : sorted(map(int, input().split()))
li = lambda : list(input())
mii = lambda : map(int, input().split())
msi = lambda : map(str, input().split())

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def main():
	for _ in ' ' * int(input()):
		n = ii()
		a = li()
		b = li()
		for i in range(n):
			if int(a[i]) in [1, 2]:
				a[i] = 's'
			else:
				a[i] = 't'
			if int(b[i]) in [1, 2]:
				b[i] = 's'
			else:
				b[i] = 't'
		s = 'YES'
		f = 1
		i = 0
		while 1:
			if f == 2 and i == n - 1:
				if b[i] == 't':
					if a[i] == '1':
						b[i] = '1'
						break
					else:
						s = 'NO'
						break
				else:
					b[i] = '1'
					break
			if f == 1:
				if a[i] == 't':
					if i == 0 or a[i - 1] == '1':
						if b[i] == 's':
							s = 'NO'
							break
						a[i] = '1'
						if i:
							a[i - 1] = 'f'
						f = 2
					elif i + 1 < n:
						a[i] = '1'
						b[i] = 'f'
						i += 1
					else:
						s = 'NO'
						break
				elif i + 1 < n:
					a[i] = '1'
					i += 1
				else:
					s = 'NO'
					break
			elif b[i] == 't':
				if i > 0 and b[i - 1] == '1':
					if a[i] == 's':
						s = 'NO'
						break
					b[i] = '1'
					b[i - 1] = 'f'
					f = 1
				elif i + 1 < n:
					b[i] = '1'
					a[i] = 'f'
					i += 1
				else:
					s = 'NO'
					break
			elif i + 1 < n:
				b[i] = '1'
				a[i] = 'f'
				i += 1
			else:
				s = 'NO'
				break
		print(s)
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import re, math, decimal, bisect

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

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
for i in range(iread()):
	n = iread()
	upper = read()
	lower = read()
	up = True
	col = 0
	while col < n:
		if up:
			if upper[col] == '1' or upper[col] == '2':
				col += 1
			elif lower[col] != '1' and lower[col] != '2':
				up = False
				col += 1
			else:
				break
		elif lower[col] == '1' or lower[col] == '2':
			col += 1
		elif upper[col] != '1' and upper[col] != '2':
			up = True
			col += 1
		else:
			break
	if col == n and up == False:
		print('YES')
	else:
		print('NO')


from sys import stdin

def main():
	l = stdin.read().splitlines()
	(l, l1) = (l[2::3], l[3::3])
	for (i, ab) in enumerate(zip(l, l1)):
		p = 2
		for (a, b) in zip(*ab):
			p = (0, 2, 1, 0, 1, 0, 0, 0, 2, 0, 1, 2)[((a < '3') * 2 + (b < '3')) * 3 + p]
		l[i] = ('NO', 'YES')[p & 1]
	print('\n'.join(l))
main()


def solve(matrix, n):
	(i, j) = (0, 0)
	prev = 'L'
	while j < n:
		if matrix[i][j] == '1' or matrix[i][j] == '2':
			if prev != 'L':
				print('NO')
				return
			j += 1
			prev = 'L'
		elif matrix[i][j] == '3' or matrix[i][j] == '4' or matrix[i][j] == '5' or (matrix[i][j] == '6'):
			if i == 0:
				if prev == 'L':
					i = 1
					prev = 'U'
				else:
					j += 1
					prev = 'L'
			elif prev == 'L':
				i = 0
				prev = 'D'
			else:
				j += 1
				prev = 'L'
	if i == 1:
		print('YES')
	else:
		print('NO')
q = int(input())
while q > 0:
	n = int(input())
	solve([input(), input()], n)
	q -= 1


q = int(input().split()[0])
for x in range(q):
	a = int(input().split()[0])
	s1 = input()
	s2 = input()
	c = 1
	for i in range(a):
		if c == 1:
			if ord(s1[i]) > 50:
				c = 2
				if ord(s2[i]) <= 50:
					print('NO')
					c = 3
					break
		elif ord(s2[i]) > 50:
			c = 1
			if ord(s1[i]) <= 50:
				print('NO')
				c = 3
				break
	if c == 2:
		print('YES')
	elif c == 1:
		print('NO')


def solve():
	n = int(input())
	a = [list(map(lambda x: 1 if int(x) <= 2 else 2, input())) for i in range(2)]
	j = 0
	for i in range(n):
		if a[j][i] == 2:
			if a[j ^ 1][i] == 1:
				return False
			j ^= 1
	return j == 1

def main():
	q = int(input())
	for i in range(q):
		print('YES' if solve() else 'NO')
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = [list(map(int, input())), list(map(int, input()))]
	pred = 'L'
	c = [0, 0]
	done = False
	while c[0] < 2 and c[1] < n and (not done):
		if a[c[0]][c[1]] < 3:
			if pred == 'L':
				c[1] += 1
			else:
				break
		elif c[0] == 0:
			if pred == 'L':
				pred = 'UP'
				c[0] += 1
			else:
				pred = 'L'
				c[1] += 1
		elif pred == 'L':
			pred = 'DOWN'
			c[0] -= 1
		else:
			pred = 'L'
			c[1] += 1
		if c == [1, n]:
			done = True
	if done:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	a = [input(), input()]
	r = c = 0
	rowChange = False
	while c < n:
		if rowChange == True and a[r][c] in '3456':
			c += 1
			rowChange = False
		elif rowChange == False and a[r][c] in '12':
			c += 1
		elif rowChange == False and a[r][c] in '3456':
			r = (r + 1) % 2
			rowChange = True
		else:
			r = -1
			break
	if r == 1 and c == n:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	q = int(input())
	s1 = input()
	s2 = input()
	a = [[], []]
	for j in range(q):
		if s1[j] == '1' or s1[j] == '2':
			a[0].append(1)
		else:
			a[0].append(2)
		if s2[j] == '1' or s2[j] == '2':
			a[1].append(1)
		else:
			a[1].append(2)
	counter = 0
	typ = 0
	flag = False
	while counter < q:
		sv_counter = counter
		while counter < q and a[typ % 2][counter] == 1:
			counter += 1
		if counter < q:
			if a[0][counter] == 2 and a[1][counter] == 2:
				counter += 1
				typ += 1
			else:
				flag = True
		if counter == sv_counter:
			counter += 1
	if not flag and typ % 2 == 1:
		print('YES')
	else:
		print('NO')


import sys
data = int(input())
for i in range(data):
	ans = 0
	num = int(input())
	arr = []
	arr.append(str(input().strip()))
	arr.append(str(input().strip()))
	(inf, virus, corona) = (0, 0, 0)
	while inf < num:
		if arr[corona][inf] == '1' or arr[corona][inf] == '2':
			if virus == 0:
				inf += 1
			else:
				break
		elif virus == 0:
			virus = 1
			if corona == 0:
				corona = 1
			else:
				corona = 0
		else:
			virus = 0
			inf += 1
	if inf == num and corona == 1:
		print('YES')
		ans = 1
	if ans == 0:
		print('NO')


from sys import stdin, stdout
query = int(input())
for i in range(query):
	n = int(input())
	rows = [list(input()), list(input())]
	rowi = 0
	ans = True
	for k in range(n):
		if rows[rowi][k] >= '3':
			if rows[rowi - 1][k] <= '2':
				ans = False
				break
			else:
				rowi = (rowi - 1) % 2
	if rowi == 0:
		print('NO')
	else:
		print('YES' if ans else 'NO')


def main():
	n = int(input())
	for _ in range(n):
		num = int(input())
		top = input()
		bottom = input()
		check = ['1', '2']
		flag = True
		bot = False
		for i in range(num):
			if top[i] in check and (not bot):
				continue
			elif bottom[i] in check and bot:
				continue
			elif top[i] not in check and bottom[i] not in check:
				if bot:
					bot = False
				else:
					bot = True
			else:
				flag = False
				break
		if flag and bot:
			print('YES')
		else:
			print('NO')
main()


import os
import sys
from io import BytesIO, IOBase
import math
import itertools
import bisect
import heapq

def main():
	pass
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	for i in range(2, n + 1):
		if primes[i]:
			for j in range(i + i, n + 1, i):
				primes[j] = False
	p = []
	for i in range(0, n + 1):
		if primes[i]:
			p.append(i)
	return p

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def chk(n, d):
	if str(d) in str(n):
		return True
	return False
for xyz in range(0, int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	up = True
	type = {'1', '2'}
	ans = True
	for i in range(0, n + 1):
		if i == n:
			if up == True:
				ans = False
			break
		if up:
			if s1[i] not in type:
				up = False
				if s2[i] in type:
					ans = False
					break
		elif s2[i] not in type:
			up = True
			if s1[i] in type:
				ans = False
				break
	if ans:
		print('YES')
	else:
		print('NO')


req = int(input())
for z in range(req):
	isit = True
	amount = int(input())
	current = [list(map(int, list(input()))), list(map(int, list(input())))]
	water = 0
	for i in range(amount):
		if current[0][i] <= 2:
			current[0][i] = 1
		else:
			current[0][i] = 2
		if current[1][i] <= 2:
			current[1][i] = 1
		else:
			current[1][i] = 2
		if current[0][i] == 2 and current[1][i] == 2:
			water = 1 - water
		elif current[water][i] == 1:
			pass
		else:
			isit = False
			break
	if water == 0:
		isit = False
	if isit:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(0, n):
	k = int(input())
	str1 = input()
	str2 = input()
	str0 = str1 + str2
	s = 0
	x = 1
	while True:
		if s == k - 1:
			if int(str0[s]) <= 2:
				print('NO')
				break
			else:
				s += k
				x = -1
		if s == 2 * k - 1:
			if (int(str0[s]) - 2.5) * x < 0:
				print('YES')
				break
			else:
				print('NO')
				break
		if int(str0[s]) <= 2:
			if x == -1:
				print('NO')
				break
			else:
				s += 1
		else:
			if x == 1:
				s = (s + k) % (2 * k)
			else:
				s += 1
			x = -x


import sys
from collections import deque, defaultdict
from fractions import gcd
from math import ceil

def N():
	return int(sys.stdin.readline())

def NK():
	return map(int, sys.stdin.readline().split())

def LS_I():
	return [int(x) for x in sys.stdin.readline().split()]

def LS_S():
	return list(input())

def main():
	q = N()
	for _ in range(q):
		n = N()
		(ls1, ls2) = ([0 for _ in range(n)], [0 for _ in range(n)])
		for (num, i) in enumerate(list(input())):
			if int(i) == 1 or int(i) == 2:
				ls1[num] = 1
			else:
				pass
		for (num, i) in enumerate(list(input())):
			if int(i) == 1 or int(i) == 2:
				ls2[num] = 1
			else:
				pass
		flg = False
		ans = 'YES'
		for (i, j) in zip(ls1, ls2):
			if flg == False:
				if i == 1:
					pass
				elif int(i + j) == 0:
					flg = True
				else:
					ans = 'NO'
					break
			elif j == 1:
				pass
			elif int(i + j) == 0:
				flg = False
			else:
				ans = 'NO'
				break
		if flg:
			print(ans)
		else:
			print('NO')
main()


for _ in range(int(input())):
	n = int(input())
	f = [*map(int, input())]
	s = [*map(int, input())]
	t = 1
	ans = 'YES'
	for i in range(n - 1, -1, -1):
		if t:
			if s[i] > 2:
				t = 0
				s[i] = 6
				if f[i] > 2:
					f[i] = 4
				else:
					ans = 'NO'
					break
			else:
				s[i] = 2
		elif f[i] > 2:
			t = 1
			f[i] = 3
			if s[i] > 2:
				s[i] = 5
			else:
				ans = 'NO'
				break
		else:
			f[i] = 2
	print(ans if t == 0 else 'NO')


answer = []
for _ in range(int(input())):
	n = int(input())
	uc = input()
	lc = input()
	count = 0
	for (u, l) in zip(uc, lc):
		if u in ['3', '4', '5', '6'] and l in ['1', '2'] and (count % 2 == 0):
			answer.append('NO')
			break
		if l in ['3', '4', '5', '6'] and u in ['1', '2'] and (count % 2 == 1):
			answer.append('NO')
			break
		if u in ['3', '4', '5', '6'] and l in ['3', '4', '5', '6']:
			count += 1
	else:
		if count % 2:
			answer.append('YES')
		else:
			answer.append('NO')
for ans in answer:
	print(ans)


q = int(input())
for i in range(q):
	n = int(input())
	a = str(input())
	a = list(map(int, a))
	b = str(input())
	b = list(map(int, b))
	pipe = [a, b]
	j = 0
	k = 0
	no = 0
	while k < n:
		if pipe[j][k] <= 2:
			k = k + 1
		elif j == 0:
			if pipe[j + 1][k] <= 2:
				no = 1
				break
			j = j + 1
			k = k + 1
		else:
			if pipe[j - 1][k] <= 2:
				no = 1
				break
			j = j - 1
			k = k + 1
	if no == 1:
		print('NO')
	elif j == 0:
		print('NO')
	else:
		print('YES')


q = int(input())
for i in range(q):
	n = int(input())
	s = input()
	r = input()
	x = [s, r]
	i = 0
	flag = 0
	for j in range(n):
		if x[i][j] == '1' or x[i][j] == '2':
			continue
		i ^= 1
		if x[i][j] == '1' or x[i][j] == '2':
			flag = 1
			break
	if flag == 0 and i == 1:
		print('YES')
	else:
		print('NO')


from sys import stdin
import math
A = int(stdin.readline())
for t in range(0, A):
	B = int(stdin.readline())
	C = stdin.readline()
	D = stdin.readline()
	row = 1
	column = 1
	state = 1
	P = 0
	while column <= B:
		if row == 1:
			if state == 1:
				if C[column - 1] == '1' or C[column - 1] == '2':
					if column == B:
						print('NO')
						P = 1
						break
					else:
						column += 1
				else:
					row = 2
					state = 2
			elif state == 4:
				if C[column - 1] == '1' or C[column - 1] == '2':
					P = 1
					print('NO')
					break
				else:
					row = 1
					if column == B:
						print('NO')
						P = 1
						break
					else:
						column += 1
						state = 1
		if row == 2:
			if state == 1:
				if D[column - 1] == '1' or D[column - 1] == '2':
					column += 1
				else:
					state = 4
					row = 1
			elif state == 2:
				if D[column - 1] == '1' or D[column - 1] == '2':
					P = 1
					print('NO')
					break
				else:
					column += 1
					state = 1
	if P == 0:
		print('YES')


for itr in range(int(input())):
	n = int(input())
	arr = []
	a = list(str(input()))
	b = list(str(input()))
	for i in range(n):
		if a[i] == '1' or a[i] == '2':
			a[i] = 0
		else:
			a[i] = 1
		if b[i] == '1' or b[i] == '2':
			b[i] = 0
		else:
			b[i] = 1
	arr.append(a)
	arr.append(b)
	i = 0
	j = 0
	ans = 1
	direction = 0
	while 1:
		if arr[i][j] == 0:
			if direction == 0:
				j += 1
			elif direction == 1:
				i += 1
			elif direction == 2:
				i -= 1
		elif direction == 0:
			if i == 0:
				i = 1
				direction = 1
			else:
				i = 0
				direction = 2
		elif direction == 1:
			direction = 0
			j += 1
		elif direction == 2:
			direction = 0
			j += 1
		if i == 1 and j == n:
			break
		if i > 1 or i < 0 or j >= n:
			ans = 0
			break
	if ans:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	c = 0
	(first, second) = ([], [])
	for i in range(n):
		if a[i] == '1' or a[i] == '2':
			first.append(1)
		else:
			first.append(2)
		if b[i] == '1' or b[i] == '2':
			second.append(1)
		else:
			second.append(2)
	water = 0
	f = 0
	(a, b) = (first.copy(), second.copy())
	for i in range(n):
		if water == 0:
			if a[i] == 2:
				water = 1
				if b[i] == 1:
					f = 1
					break
		elif b[i] == 2:
			water = 0
			if a[i] == 1:
				f = 1
				break
	if water == 1 and f == 0:
		print('YES')
	else:
		print('NO')


import time
import collections
LOCAL = False
start_time = None
if LOCAL:
	start_time = time.time()
q = int(input())
while q:
	q -= 1
	n = int(input())
	f = input()
	s = input()
	t = True
	b = False
	lin = ['1', '2']
	for i in range(n):
		top_is_line = f[i] in lin
		bot_is_line = s[i] in lin
		newTop = False
		newBot = False
		if top_is_line and t:
			newTop = True
		if bot_is_line and b:
			newBot = True
		if not top_is_line and (not bot_is_line):
			newTop = b
			newBot = t
		t = newTop
		b = newBot
	print('YES' if b else 'NO')
if LOCAL:
	print('--- %s seconds ---' % (time.time() - start_time))


q = int(input())
for _ in range(q):
	n = int(input())
	s = [list(input()) for i in range(2)]
	u = True
	for i in range(n):
		if s[0][i] == '1' or s[0][i] == '2':
			if s[1][i] == '1' or s[1][i] == '2':
				u = u
			elif not u:
				print('NO')
				break
			else:
				u = u
		elif s[1][i] == '1' or s[1][i] == '2':
			if u:
				print('NO')
				break
			else:
				u = u
		else:
			u ^= True
	else:
		if u == False:
			print('YES')
		else:
			print('NO')


import sys
input = sys.stdin.readline

def check(N: int, P: 'Array[Array[int]]') -> str:
	cur = 0
	for i in range(N):
		if P[cur][i] > 2:
			if P[cur ^ 1][i] > 2:
				cur ^= 1
			else:
				return 'NO'
	return 'YES' if cur else 'NO'

def main():
	Q = int(input())
	ans = []
	for _ in range(Q):
		N = int(input())
		P = [list(map(int, input().rstrip())) for _ in range(2)]
		ans.append(check(N, P))
	print('\n'.join(map(str, ans)))
main()


import sys
s1 = set((1, 2))

class Direction:
	__slots__ = ['left', 'top', 'down']

	def __init__(self, left, top, down):
		self.left = left
		self.top = top
		self.down = down
mydir = Direction(left=1, top=2, down=3)

def move(arr, i, j, dir, n):
	if j == n:
		if dir == mydir.left and i == 1:
			return True
		return False
	v = arr[i][j]
	if v in s1:
		if dir == mydir.left:
			return move(arr, i, j + 1, mydir.left, n)
	elif i == 0:
		if dir == mydir.left:
			return move(arr, 1, j, mydir.top, n)
		elif dir == mydir.down:
			return move(arr, 0, j + 1, mydir.left, n)
	elif dir == mydir.left:
		return move(arr, 0, j, mydir.down, n)
	elif dir == mydir.top:
		return move(arr, 1, j + 1, mydir.left, n)
	return False

def solution():
	input = sys.stdin.readline
	q = int(input())
	for i in range(q):
		n = int(input())
		arr1 = [int(x) for x in input().strip()]
		arr2 = [int(x) for x in input().strip()]
		arr3 = [arr1, arr2]
		try:
			out = move(arr3, 0, 0, 1, n)
			if out:
				print('YES')
			else:
				print('NO')
		except:
			print('YES')
solution()


(l1, l2) = (['1', '2'], ['3', '4', '5', '6'])
for i in range(int(input())):
	(n, s1, cur) = (int(input()), [input() for i in range(2)], 0)
	for j in range(n):
		if s1[cur][j] in l2:
			cur ^= 1
			if s1[cur][j] not in l2:
				cur = 0
				break
	print('YES' if cur else 'NO')


q = int(input())
while q > 0:
	n = int(input())
	n1 = n
	row1 = list(input())
	row2 = list(input())
	c_row = row1
	c2_row = row2
	i = 0
	line = [1, 2]
	curve = [3, 4, 5, 6]
	while i < n:
		if int(c_row[i]) in line:
			i += 1
		elif int(c_row[i]) in curve:
			if int(c2_row[i]) in curve:
				temp_row = c2_row
				c2_row = c_row
				c_row = temp_row
				i += 1
			else:
				print('NO')
				break
	if i == n and c_row is row2:
		print('YES')
	if i == n and c_row is row1:
		print('NO')
	q = q - 1


T = int(input())
for i in range(T):
	n = int(input())
	l1 = input()
	l2 = input()
	l1 = list(map(int, l1))
	l2 = list(map(int, l2))
	row = 0
	if l1[0] == 1 or l1[0] == 2:
		pipe = 'L'
		prev = 'L'
		row = 1
		j = 1
	else:
		pipe = 'C'
		prev = 'T'
		row = 2
		j = 0
	while j < n:
		if row == 1:
			x = l1[j]
			if x == 1 or x == 2:
				pipe = 'L'
			else:
				pipe = 'C'
		elif row == 2:
			x = l2[j]
			if x == 1 or x == 2:
				pipe = 'L'
			else:
				pipe = 'C'
		if row == 1 and pipe == 'L' and (prev == 'L'):
			j += 1
		elif row == 1 and pipe == 'L' and (prev == 'T'):
			break
			print('NO')
			j += 1
		elif row == 1 and pipe == 'C' and (prev == 'L'):
			row = 2
			prev = 'T'
		elif row == 1 and pipe == 'C' and (prev == 'T'):
			row = 1
			prev = 'L'
			j += 1
		elif row == 2 and pipe == 'L' and (prev == 'L'):
			j += 1
		elif row == 2 and pipe == 'L' and (prev == 'T'):
			break
			print('NO')
			j += 1
		elif row == 2 and pipe == 'C' and (prev == 'L'):
			row = 1
			prev = 'T'
		elif row == 2 and pipe == 'C' and (prev == 'T'):
			row = 2
			j += 1
			prev = 'L'
	if row == 2 and j == n:
		print('YES')
	else:
		print('NO')


def main():
	Q = int(input())
	data = []
	for _ in range(Q):
		N = int(input())
		S1 = [int(a) for a in list(input())]
		S2 = [int(a) for a in list(input())]
		data.append((N, [S1, S2]))
	A = [3, 4, 5, 6]
	B = [1, 2]
	for (N, S) in data:
		dp = [[0, 0] for _ in range(N + 1)]
		dp[0][0] = 1
		for n in range(N):
			if S[0][n] in A and S[1][n] in A:
				dp[n + 1][0] = dp[n][1]
				dp[n + 1][1] = dp[n][0]
			elif S[0][n] in B and S[1][n] in A:
				dp[n + 1][0] = dp[n][0]
				dp[n + 1][1] = 0
			elif S[0][n] in A and S[1][n] in B:
				dp[n + 1][0] = 0
				dp[n + 1][1] = dp[n][1]
			else:
				dp[n + 1][0] = dp[n][0]
				dp[n + 1][1] = dp[n][1]
		if dp[N][1] == 1:
			print('YES')
		else:
			print('NO')

def __starting_point():
	main()
__starting_point()


import math
from collections import deque
q = int(input())
for _ in range(q):
	n = int(input())
	lst = list()
	row1 = [int(x) for x in input()]
	row2 = [int(x) for x in input()]
	lst.append(row1)
	lst.append(row2)
	x = 0
	y = 0
	wait = -1
	ans = 1
	while x < n:
		if wait == -1:
			if lst[y][x] == 1 or lst[y][x] == 2:
				wait = 0
				x += 1
			else:
				wait = 1
				y = (y + 1) % 2
		elif (lst[y][x] == 1 or lst[y][x] == 2) and wait == 0:
			wait = 0
			x += 1
		elif lst[y][x] > 2 and wait == 0:
			wait = 1
			y = (y + 1) % 2
		elif lst[y][x] > 2 and wait == 1:
			wait = 0
			x += 1
		else:
			break
	if y == 1 and x == n:
		print('YES')
	else:
		print('NO')


def solve(line1, line2, n):
	for i in range(n):
		if line1[i] == '0' and line2[i] == '1' or (line1[i] == '1' and line2[i] == '0'):
			return False
	if line1.count('0') % 2 == 0:
		return False
	return True

def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		line1 = input().replace('2', '1')
		line2 = input().replace('2', '1')
		for c in '3456':
			line1 = line1.replace(c, '0')
			line2 = line2.replace(c, '0')
		grid = [line1, line2]
		i = j = 0
		prev = 1
		iprev = 0
		while True:
			if not (0 <= i <= 1 and 0 <= j < n):
				print('NO')
				break
			new_iprev = i
			if grid[i][j] == '0':
				if prev == 1:
					i = i + 1 if i == 0 else i - 1
				elif prev == 0:
					if iprev != i:
						j += 1
					else:
						i = i + 1 if i == 0 else i - 1
				prev = 0
			else:
				if prev == 0 and iprev != i:
					print('NO')
					break
				j += 1
				prev = 1
			iprev = new_iprev
			if i == 1 and j == n:
				print('YES')
				break
main()


from sys import setcheckinterval, stdin, setrecursionlimit
setcheckinterval(1000)
setrecursionlimit(10 ** 7)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))
chg = {1: {2, 1}, 2: {1, 2}, 3: {3, 4, 5, 6}, 4: {3, 4, 5, 6}, 5: {3, 4, 5, 6}, 6: {3, 4, 5, 6}}
sol = {0: {2, 4}, (2, 0): {4, 2}, (2, 1): {2, 5}, (3, 0): {4, 2}, (3, 1): {}, (4, 0): {6}, (4, 1): {}, (5, 1): {3}, (5, 0): {}, (6, 1): {2, 5}, (6, 0): {}}
for _ in range(iin()):
	n = iin()
	a = [list(map(int, list(input()))), list(map(int, list(input())))]
	nxt = [0, 0]
	for i in chg[a[0][0]]:
		if i in sol[0]:
			a[0][0] = i
			break
	else:
		print('NO')
		continue
	while 1:
		(x, y) = nxt
		(nx, ny) = (x, y + 1)
		if a[x][y] != 2:
			xx = a[x][y]
			if xx == 3:
				nx = 0
				ny = y + 1
			elif xx == 4:
				nx = 1
				ny = y
			elif xx == 5:
				nx = 0
				ny = y
			elif xx == 6:
				nx = 1
				ny = y + 1
		if ny >= n:
			if nx == 1 and ny == n:
				print('YES')
			else:
				print('NO')
			break
		for i in chg[a[nx][ny]]:
			if i in sol[a[x][y], x]:
				a[nx][ny] = i
				break
		else:
			print('NO')
			break
		nxt = [nx, ny]


q = int(input())
for i in range(q):
	n = int(input())
	lines = [list(input()), list(input())]
	linei = 0
	ans = True
	for k in range(n):
		if lines[linei][k] >= '3':
			if lines[linei - 1][k] <= '2':
				ans = False
				break
			else:
				linei = (linei - 1) % 2
	if linei == 0:
		print('NO')
	else:
		print('YES' if ans else 'NO')


import sys
import bisect
try:
	fin = open('in')
except:
	fin = sys.stdin
input = lambda : fin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	g = [list(input()) for _ in range(2)]
	row = 0
	col = 0
	while col < n:
		if g[row][col] >= '3':
			if g[row ^ 1][col] <= '2':
				break
			else:
				row ^= 1
		col += 1
	if row == 1 and col == n:
		print('YES')
	else:
		print('NO')


q = int(input())
for qq in range(q):
	n = int(input())
	t0 = list(map(int, input()))
	t1 = list(map(int, input()))
	tube = [[0] * (n + 1) for _ in range(2)]
	tube[0][0] = 1
	for i in range(n):
		for _ in range(2):
			if t0[i] <= 2 and tube[0][i] % 10 > 0:
				tube[0][i + 1] += 1
			if t1[i] <= 2 and tube[1][i] % 10 > 0:
				tube[1][i + 1] += 1
			if t0[i] > 2 and tube[0][i] // 10 > 0:
				tube[0][i + 1] += 1
			if t1[i] > 2 and tube[1][i] // 10 > 0:
				tube[1][i + 1] += 1
			if t0[i] > 2 and tube[0][i] % 10 > 0:
				tube[1][i] += 10
			if t1[i] > 2 and tube[1][i] % 10 > 0:
				tube[0][i] += 10
	print('YES' if tube[1][n] > 0 else 'NO')


import sys
import math
from collections import defaultdict
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass

def takeInput():
	return [int(x) for x in input().strip().split()]
t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	row1 = input()
	row2 = input()
	row1 = [int(x) for x in list(row1)]
	row2 = [int(x) for x in list(row2)]
	for (i, r) in enumerate(row1):
		if r == 1 or r == 2:
			row1[i] = 1
		else:
			row1[i] = 3
	for (i, r) in enumerate(row2):
		if r == 1 or r == 2:
			row2[i] = 1
		else:
			row2[i] = 3
	row1 = [0] + row1
	row2 = [0] + row2
	rows = [[], row1, row2]
	r = 1
	c = 1
	possible = True
	for c in range(1, n + 1):
		if rows[r][c] == 3:
			if r == 1:
				if rows[2][c] == 3:
					r = 2
				else:
					possible = False
			elif r == 2:
				if rows[1][c] == 3:
					r = 1
				else:
					possible = False
	if r == 1 or not possible:
		print('NO')
	else:
		print('YES')


def solver(length, pipes):
	stuck = False
	coords = [0, 0]
	flowType = 1
	while True:
		underInspection = pipes[coords[0]][coords[1]]
		componentType = 1 if underInspection == 1 or underInspection == 2 else 2
		if componentType == 1:
			if flowType == 1:
				flowType = 1
				coords[1] += 1
			else:
				stuck = True
				break
		elif flowType == 2:
			flowType = 1
			coords[1] += 1
		elif flowType == 3:
			flowType = 1
			coords[1] += 1
		elif coords[0] == 0:
			flowType = 2
			coords[0] += 1
		else:
			flowType = 3
			coords[0] -= 1
		if coords[1] == length:
			if coords[0] == 0:
				stuck = True
				break
			else:
				break
	return 'NO' if stuck else 'YES'

def main():
	for _ in range(int(input().strip())):
		length = int(input().strip())
		pipes = []
		pipes.append([int(x) for x in str(input().strip())])
		pipes.append([int(x) for x in str(input().strip())])
		print(solver(length, pipes))
main()


def evaluate(a, n):
	prev = (1, n)
	curr = (1, n - 1)
	while curr != (0, -1):
		if curr[1] == -1 and curr[0] != 0:
			return 'NO'
		tmp = curr
		if prev[0] == curr[0] + 1 or prev[0] == curr[0] - 1:
			if a[curr[0]][curr[1]] == '1' or a[curr[0]][curr[1]] == '2':
				return 'NO'
			curr = (curr[0], curr[1] - 1)
		elif prev[1] == curr[1] + 1:
			if a[curr[0]][curr[1]] == '1' or a[curr[0]][curr[1]] == '2':
				curr = (curr[0], curr[1] - 1)
			else:
				curr = (int(curr[0] == 0), curr[1])
		prev = tmp
	return 'YES'
for _ in range(int(input())):
	n = int(input())
	(row1, row2) = (input(), input())
	print(evaluate([row1, row2], n))


import math
from collections import deque, defaultdict
from sys import stdin, stdout
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(2):
		s = input()
		z = [int(i) for i in s]
		a.append(z)
	i = 0
	j = 0
	move = 'l'
	flag = True
	while True:
		if i == 0:
			if a[i][j] <= 2 and move == 'l':
				j += 1
			elif a[i][j] <= 2 and move == 'u':
				flag = False
				break
			elif a[i][j] > 2 and move == 'u':
				j += 1
				move = 'l'
			else:
				i += 1
				move = 'd'
		elif a[i][j] <= 2 and move == 'd':
			flag = False
			break
		elif a[i][j] <= 2 and move == 'l':
			j += 1
		elif a[i][j] > 2 and move == 'd':
			j += 1
			move = 'l'
		else:
			i -= 1
			move = 'u'
		if j == n and i == 1:
			break
		elif j == n and i == 0:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	a = input()
	b = input()
	curr = 'u'
	now = 0
	st = {'1', '2'}
	curv = {'3', '4', '5', '6'}
	ans = True
	while now <= n - 1:
		if curr == 'u':
			if a[now] in st:
				pass
			elif a[now] in curv and b[now] in curv:
				curr = 'd'
				pass
			else:
				ans = False
		elif curr == 'd':
			if b[now] in st:
				pass
			elif a[now] in curv and b[now] in curv:
				curr = 'u'
				pass
			else:
				ans = False
		now += 1
	if ans == True and curr == 'd':
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	siz = int(input())
	so = [[int(s) for s in input()], [int(q) for q in input()]]
	(beg, r, c, flag) = (so[0][0], 0, 0, True)
	while 1:
		if beg == 1 or beg == 2:
			if c + 1 < siz:
				c += 1
				beg = so[r][c]
			elif c + 1 == siz and r == 1:
				break
			else:
				flag = False
				break
		elif r + 1 < 2 and so[r + 1][c] != '*':
			if so[r + 1][c] > 2:
				so[r][c] = '*'
				r += 1
				beg = so[r][c]
			else:
				flag = False
				break
		elif r - 1 > -1 and so[r - 1][c] != '*':
			if so[r - 1][c] > 2:
				so[r][c] = '*'
				r -= 1
				beg = so[r][c]
			else:
				flag = False
				break
		elif c + 1 < siz:
			so[r][c] = '*'
			c += 1
			beg = so[r][c]
		elif c + 1 == siz and r == 1:
			break
		else:
			flag = False
			break
	print('YES' if flag else 'NO')


from sys import stdin, stdout
from os import path
rd = lambda : stdin.readline().strip()
wr = stdout.write
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
import math
for _ in range(int(rd())):
	x = int(rd())
	amr = [rd(), rd()]
	i = j = 0
	flag = True
	visited = [[0] * x, [0] * x]
	while True:
		if j > x - 1:
			break
		elif amr[i][j] == '1' or amr[i][j] == '2':
			visited[i][j] = 1
			j += 1
		elif i == 0 and int(amr[i + 1][j]) > 2 and (visited[i + 1][j] != 1):
			visited[i][j] = 1
			visited[i + 1][j] = 1
			i += 1
			j += 1
		elif i == 1 and int(amr[i - 1][j]) > 2 and (visited[i - 1][j] != 1):
			visited[i][j] = 1
			visited[i - 1][j] = 1
			i -= 1
			j += 1
		else:
			i = 0
			break
	print('YES' if i == 1 else 'NO')


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		n = ri()
		a = []
		a.append(list(rs()))
		a.append(list(rs()))
		curr = 0
		ans = 'YES'
		for i in range(n):
			if a[curr][i] > '2':
				if a[1 - curr][i] < '3':
					ans = 'NO'
					break
				else:
					curr = 1 - curr
		if curr:
			print(ans)
		else:
			print('NO')
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


q = int(input())
for _ in range(q):
	n = int(input())
	up = input()
	down = input()
	pipe = []
	pipe.append(up)
	pipe.append(down)
	pos = 0
	can = True
	for i in range(n):
		if pipe[pos][i] > '2':
			pos ^= 1
			if pipe[pos][i] <= '2':
				can = False
				break
	if pos == 0:
		can = False
	if can:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	s = ['', input(), input()]
	i = 1
	j = 0
	flow = '-'
	for p in range(10 * n):
		c = s[i][j]
		if flow == '-':
			if i == 1:
				if c == '1' or c == '2':
					j += 1
				else:
					i = 2
					flow = '|'
			elif c == '1' or c == '2':
				j += 1
			else:
				i = 1
				flow = '|'
		elif i == 1:
			if c == '1' or c == '2':
				break
			else:
				j += 1
				flow = '-'
		elif c == '1' or c == '2':
			break
		else:
			j += 1
			flow = '-'
		if j >= n:
			break
	if i == 2 and j == n and (flow == '-'):
		print('YES')
	else:
		print('NO')


I = lambda : int(input())

def is_possible():
	cr = 0
	n = I()
	get_row = lambda : list(map(lambda x: 0 if x < 3 else 1, map(int, list(input()))))
	rows = [get_row(), get_row()]
	for i in range(n):
		if rows[cr][i]:
			if not rows[not cr][i]:
				return False
			else:
				cr = not cr
	return not not cr
for _ in range(I()):
	print('YES' if is_possible() else 'NO')


q = int(input())
ans = list()
for i in range(q):
	n = int(input())
	r = [input() for i in range(2)]
	flag = True
	curR = 0
	for i in range(n):
		if int(r[0][i]) > 2 and int(r[1][i]) > 2:
			curR = (curR + 1) % 2
			continue
		if int(r[curR][i]) <= 2:
			continue
		flag = False
		break
	if flag and curR == 1:
		ans.append('YES')
	else:
		ans.append('NO')
for i in ans:
	print(i)


q = int(input())
conv = {'1': 1, '2': 1, '3': 2, '4': 2, '5': 2, '6': 2}
for _ in range(q):
	n = int(input())
	pipes = [input(), input()]
	pipes = list(map(lambda row: list(map(lambda x: conv[x], row)), pipes))
	dp = [[0] * n, [0] * n]
	dp[0][0] = 1 if pipes[0][0] == 1 else 0
	dp[1][0] = 1 if pipes[0][0] == 2 and pipes[1][0] == 2 else 0
	for i in range(1, n):
		dp[0][i] = 1 if dp[0][i - 1] == 1 and pipes[0][i] == 1 or (dp[1][i - 1] == 1 and pipes[0][i] == 2 and (pipes[1][i] == 2)) else 0
		dp[1][i] = 1 if dp[1][i - 1] == 1 and pipes[1][i] == 1 or (dp[0][i - 1] == 1 and pipes[0][i] == 2 and (pipes[1][i] == 2)) else 0
	print('YES' if dp[1][n - 1] == 1 else 'NO')


import sys
input = sys.stdin.readline

def canForm(rows):
	n = len(rows[0])
	cur = ['2', (0, -1)]
	while True:
		(shape, loc) = cur
		if loc == (1, n - 1) and (shape == '2' or shape == '6'):
			return True
		nxt = None
		if shape == '1':
			return False
		elif shape == '2' or shape == '3' or shape == '6':
			if loc[1] == n - 1:
				return False
			elif rows[loc[0]][loc[1] + 1] in '3456':
				if loc[0] == 0:
					nxt = ['4', (loc[0], loc[1] + 1)]
				else:
					nxt = ['5', (loc[0], loc[1] + 1)]
			else:
				nxt = ['2', (loc[0], loc[1] + 1)]
		elif shape == '4':
			if loc[0] == 1:
				return False
			elif rows[1][loc[1]] in '3456':
				nxt = ['6', (1, loc[1])]
			else:
				nxt = ['1', (1, loc[1])]
		elif shape == '5':
			if loc[0] == 0:
				return False
			elif rows[0][loc[1]] in '3456':
				nxt = ['3', (0, loc[1])]
			else:
				nxt = ['1', (0, loc[1])]
		cur = nxt

def main():
	lq = int(input())
	for _ in range(lq):
		n = int(input())
		rows = [input(), input()]
		if canForm(rows):
			print('YES')
		else:
			print('NO')
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	r1 = [0] + list(map(int, input().strip()))
	r2 = [0] + list(map(int, input().strip()))
	dp = [[False, False] for i in range(n + 1)]
	dp[0][0] = True
	dp[0][1] = False
	for i in range(1, n + 1):
		if r1[i] in (1, 2):
			dp[i][0] = dp[i - 1][0]
		if r2[i] in (1, 2):
			dp[i][1] = dp[i - 1][1]
		if r1[i] in (3, 4, 5, 6) and r2[i] in (3, 4, 5, 6):
			dp[i][0] = dp[i - 1][1]
			dp[i][1] = dp[i - 1][0]
	if dp[-1][-1]:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	a = [[int(i) for i in list(input().strip())], [int(i) for i in list(input().strip())]]
	r = 0
	d = 0
	i = 0
	while i < n:
		if a[r][i] < 3:
			i += 1
		else:
			r = 1 - r
			if a[r][i] < 3:
				r = 0
				break
			else:
				i += 1
	if r == 1:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	s1 = input()
	s2 = input()
	arr = []
	arr.append(s1)
	arr.append(s2)
	i1 = 0
	j1 = 0
	bad = False
	while j1 < n:
		if arr[i1][j1] < '3':
			j1 += 1
		else:
			if i1 == 0:
				i1 += 1
			else:
				i1 -= 1
			if arr[i1][j1] > '2':
				j1 += 1
			else:
				bad = True
				break
	if i1 == 1 and j1 == n and (not bad):
		print('YES')
	else:
		print('NO')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	d = []
	f1 = 0
	f2 = 0
	a = input()
	a = list(a)
	for i in range(n):
		if a[i] == '1' or a[i] == '2':
			a[i] = 0
		else:
			a[i] = 1
	b = input()
	b = list(b)
	for i in range(n):
		if b[i] == '1' or b[i] == '2':
			b[i] = 0
		else:
			b[i] = 1
	for i in range(n):
		if i == 0:
			c = a
			f1 = 1
			f2 = 0
		if a[i] == 1 and b[i] == 0 and (f1 == 1):
			print('NO')
			break
		if a[i] == 0 and b[i] == 1 and (f2 == 1):
			print('NO')
			break
		if i == n - 1 and f1 == 1:
			if a[n - 1] == 1 and b[n - 1] == 1:
				print('YES')
			else:
				print('NO')
			break
		if i == n - 1 and f2 == 1:
			if b[n - 1] == 0:
				print('YES')
			else:
				print('NO')
		if c[i] == 1:
			if f1 == 1:
				c = b
				f2 = 1
				f1 = 0
			else:
				c = a
				f1 = 1
				f2 = 0


T = int(input())
for _ in range(T):
	x = int(input())
	y1 = list(map(int, input()))
	y1.insert(0, 0)
	y2 = list(map(int, input()))
	y2.insert(0, 0)
	xpos = 1
	ypos = 1
	xdir = 1
	ydir = 0
	while xpos <= x:
		if ypos == 1:
			if y1[xpos] == 1 or y1[xpos] == 2:
				if xdir == 1:
					xpos += 1
				else:
					break
			elif xdir == 1:
				xdir = 0
				ydir = -1
				ypos = 2
			else:
				xdir = 1
				ydir = 0
				xpos += 1
		if ypos == 2:
			if y2[xpos] == 1 or y2[xpos] == 2:
				if xdir == 1:
					xpos += 1
				else:
					break
			elif xdir == 1:
				xdir = 0
				ydir = 1
				ypos = 1
			else:
				xdir = 1
				ydir = 0
				xpos += 1
	if xpos == x + 1 and ypos == 2:
		print('Yes')
	else:
		print('No')


t = int(input())
while t > 0:
	n = int(input())
	u = input()
	d = input()
	c = 1
	flag = 1
	for i in range(n):
		if c == 1:
			if i == n - 1 and (u[i] == '1' or u[i] == '2'):
				flag = -1
				break
			elif i == n - 1 and u[i] != '1' and (u[i] != '2') and (d[i] == '1' or d[i] == '2'):
				flag = -1
				break
			elif (u[i] != '1' and u[i] != '2') and (d[i] == '2' or d[i] == '1'):
				flag = -1
				break
			elif (u[i] != '1' and u[i] != '2') and (d[i] != '1' and d[i] != '2'):
				c = 0
		elif i == n - 1 and d[i] != '1' and (d[i] != '2'):
			flag = -1
			break
		elif (d[i] != '1' and d[i] != '2') and (u[i] == '2' or u[i] == '1'):
			flag = -1
			break
		elif (u[i] != '1' and u[i] != '2') and (d[i] != '1' and d[i] != '2'):
			c = 1
	if flag == -1:
		print('NO')
	else:
		print('YES')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	r = [[], []]
	r[0] = input()
	r[1] = input()
	stck = [[1, n - 1, -1]]
	flag = True
	while stck:
		(x, y, direc) = stck.pop()
		if x < 0 or y < 0:
			break
		if direc == -1:
			if r[x][y] == '1' or r[x][y] == '2':
				stck.append([x, y - 1, -1])
				continue
			else:
				stck.append([1 - x, y, 1])
				continue
		elif r[x][y] == '1' or r[x][y] == '2':
			flag = False
			break
		else:
			stck.append([x, y - 1, -1])
			continue
	if flag and x == 0 and (y == -1):
		print('YES')
	else:
		print('NO')


def f(c1, c2):
	flag = True
	i = 0
	while i < len(c1):
		if i == len(c1) - 1 and flag == True:
			if c1[i] in [1, 2] or c2[i] in [1, 2]:
				return 'NO'
		elif i == len(c1) - 1 and flag == False:
			if c2[i] not in [1, 2]:
				return 'NO'
		if flag == True:
			if c1[i] in [1, 2]:
				i = i + 1
			else:
				if c2[i] in [1, 2]:
					return 'NO'
				flag = False
				i = i + 1
		elif flag == False:
			if c2[i] in [1, 2]:
				i = i + 1
			else:
				if c1[i] in [1, 2]:
					return 'NO'
				flag = True
				i = i + 1
	return 'YES'
a = int(input())
for tc in range(a):
	b = input()
	c1 = list(map(int, input()))
	c2 = list(map(int, input()))
	print(f(c1, c2))


q = int(input())
i = 0
z = []
while i < q:
	b = []
	c = int(input())
	b.append(input())
	b.append(input())
	(y, x) = (0, 0)
	p = 0
	while True:
		if b[y][x] == '1' or b[y][x] == '2':
			if p == y:
				p = y
				x += 1
			else:
				z.append(False)
				break
		elif p == y:
			p = y
			y = -y + 1
		else:
			p = y
			x += 1
		if x == c:
			if y == 1:
				z.append(True)
				break
			else:
				z.append(False)
				break
	i += 1
for a in z:
	print('YES') if a is True else print('NO')


q = int(input())
for query in range(q):
	n = int(input())
	a = input()
	b = input()
	switch = 0
	s1 = ['1', '2']
	s2 = ['3', '4', '5', '6']
	turns = 0
	flag = 0
	for i in range(n):
		if switch == 0:
			if a[i] in s1:
				continue
			elif a[i] in s2:
				if b[i] in s1:
					print('NO')
					flag = 1
					break
				else:
					switch = 1
					turns += 1
		elif b[i] in s1:
			continue
		elif b[i] in s2:
			if a[i] in s1:
				print('NO')
				flag = 1
				break
			else:
				switch = 0
				turns += 1
	if flag == 1:
		continue
	elif switch == 0:
		print('NO')
		continue
	elif turns % 2 == 0:
		print('NO')
		continue
	else:
		print('YES')


q = int(input())
for _ in range(q):
	n = int(input())
	s = input()
	r = input()
	l = [[0, 0] for _ in range(n + 1)]
	for i in range(n):
		l[i][0] = int(s[i])
		l[i][1] = int(r[i])
	s1 = set([1, 2])
	s2 = set([3, 4, 5, 6])
	tx = 0
	ty = 0
	if int(s[0]) in s2:
		x = 0
		y = 1
	else:
		x = 1
		y = 0
	while 1:
		if x == n:
			if y == 1:
				tf = True
				break
			else:
				tf = False
				break
		if l[x][y] in s1:
			if tx == x - 1 and ty == y:
				tx = x
				ty = y
				x += 1
			else:
				tf = False
				break
		elif tx == x - 1 and ty == y:
			tx = x
			ty = y
			y += 1
			y %= 2
		else:
			ty = y
			x += 1
	if tf:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	(p1, p2) = (input(), input())
	s1 = set(['1', '2'])
	s2 = set(['3', '4', '5', '6'])
	in_ = 1
	i = 1
	while in_ != 0 and i <= n:
		i_ = i - 1
		if in_ == 1:
			if p1[i_] in s2 and p2[i_] not in s2:
				in_ = 0
			elif p1[i_] in s2 and p2[i_] in s2:
				in_ = 2
		elif in_ == 2:
			if p2[i_] in s2 and p1[i_] not in s2:
				in_ = 0
			elif p2[i_] in s2 and p1[i_] in s2:
				in_ = 1
		i += 1
	if in_ == 2:
		print('YES')
	else:
		print('NO')


q = int(input())
Tube = list()
line = set('12')
sqr = set('3456')
for i in range(q):
	n = int(input())
	Tube.clear()
	myX = 2
	myY = n - 1
	backX = 2
	backY = n
	backTube = '1'
	Tube.append('0')
	Tube.append(input())
	Tube.append(input())
	flag = True
	while flag:
		myTube = Tube[myX][myY]
		if myTube in line:
			c = myX
			myX = myX - (backX - myX)
			backX = c
			c = myY
			myY = myY * 2 - backY
			backY = c
		elif backY == myY:
			myY -= 1
			if backX == 2:
				backX -= 1
			else:
				backX += 1
		elif myX == backX:
			if myX == 1:
				myX += 1
				backY -= 1
			else:
				myX -= 1
				backY -= 1
		backTube = myTube
		if myX == 1 and myY == -1:
			flag = True
			break
		if myY > backY or myY <= -1:
			flag = False
			break
		if myX > 2 or myX < 1:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	str1 = input()
	str2 = input()
	m = 'd'
	s = 0
	while True:
		if s == n:
			break
		elif m[0] == 'd':
			if len(m) == 1:
				if int(str1[s]) < 3:
					s += 1
				elif int(str1[s]) > 2:
					m = 'ur'
				else:
					break
			elif int(str1[s]) > 2:
				s += 1
				m = 'd'
			else:
				break
		elif len(m) == 1:
			if int(str2[s]) < 3:
				s += 1
			elif int(str2[s]) > 2:
				m = 'dr'
			else:
				break
		elif int(str2[s]) > 2:
			s += 1
			m = 'u'
		else:
			break
	if m == 'u':
		print('YES')
	else:
		print('NO')


q = int(input())
for asdga in range(q):
	n = int(input())
	lines = []
	lines.append(input())
	lines.append(input())
	dp = []
	dp.append(list(lines[0]))
	dp.append(list(lines[1]))
	currentLine = 0
	prevWasTurned = False
	ans = 'YES'
	i = 0
	while i < n:
		if dp[currentLine][i] >= '3' and (not prevWasTurned):
			currentLine = (currentLine + 1) % 2
			prevWasTurned = True
			i -= 1
		elif dp[currentLine][i] >= '3' and prevWasTurned:
			prevWasTurned = False
		elif prevWasTurned:
			ans = 'NO'
			break
		i += 1
	if currentLine == 1 and dp[1][n - 1] < '3' and prevWasTurned:
		ans = 'NO'
	if currentLine == 0:
		ans = 'NO'
	print(ans)


import sys
import math
mapp = {'1': 'line', '2': 'line', '3': 'angle', '4': 'angle', '5': 'angle', '6': 'angle'}

def gr(x):
	return fr if x == 0 else sc

def solve(fr, sc, n):
	completed = False
	prev_row = 0
	cur_row = 0
	cur_col = 0
	while not completed:
		if cur_col == n:
			return cur_row == 1
		if mapp[gr(cur_row)[cur_col]] == 'line':
			if prev_row != cur_row:
				break
			else:
				cur_col += 1
		elif prev_row == cur_row:
			(prev_row, cur_row) = (cur_row, 0 if prev_row == 1 else 1)
		else:
			cur_col += 1
			prev_row = cur_row
	return completed
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	fr = sys.stdin.readline().strip()
	sc = sys.stdin.readline().strip()
	print('YES' if solve(fr, sc, n) else 'NO')


x = int(input())
for a in range(0, x):
	y = int(input())
	arr = [input()]
	arr.append(input())
	i = 0
	f = True
	for b in range(0, len(arr[0])):
		if int(arr[i][b]) > 2:
			if i == 1:
				i = 0
			else:
				i = 1
			p = [i, b]
			if int(arr[i][b]) < 3:
				f = False
	if i == 1 and b == y - 1 and f:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	p1 = [int(i) for i in input()]
	p2 = [int(i) for i in input()]
	top = True
	ok = True
	for i in range(n):
		if p1[i] == 2:
			p1[i] = 1
		if p1[i] == 4 or p1[i] == 5 or p1[i] == 6:
			p1[i] = 3
		if p2[i] == 2:
			p2[i] = 1
		if p2[i] == 4 or p2[i] == 5 or p2[i] == 6:
			p2[i] = 3
	for i in range(n - 1):
		if not ok:
			break
		if top:
			if p1[i] == 3:
				top = False
				if p2[i] == 1:
					ok = False
		elif p2[i] == 3:
			top = True
			if p1[i] == 1:
				ok = False
	if top:
		if p1[-1] == 1 or p2[-1] == 1:
			ok = False
	elif p2[-1] == 3:
		ok = False
	if ok:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	a = [s1, s2]
	(x, y) = (0, 0)
	q = True
	bad = False
	while q:
		if y > 1 or x > n - 1:
			break
		if a[y][x] == '1' or a[y][x] == '2':
			x += 1
		elif 6 >= int(a[y][x]) >= 3 and y == 0:
			if 6 >= int(a[y + 1][x]) >= 3:
				x += 1
				y += 1
			else:
				bad = True
				q = False
		elif 6 >= int(a[y][x]) >= 3 and y == 1:
			if 6 >= int(a[y - 1][x]) >= 3:
				x += 1
				y -= 1
			else:
				bad = True
				q = False
		else:
			q = False
	if bad:
		print('NO')
	elif x != n or y != 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = input()
	brr = input()
	row = 0
	a = [1, 2]
	b = [3, 4, 5, 6]
	f = 0
	for i in range(n):
		(x, y) = (int(arr[i]), int(brr[i]))
		if row == 0 and x in a:
			row = 0
		elif row == 0 and x in b:
			row = 1
			if y in a:
				f = 1
				break
		elif row == 1 and y in a:
			row = 1
		elif row == 1 and y in b:
			row = 0
			if x in a:
				f = 1
				break
	if f == 1 or row == 0:
		print('NO')
	else:
		print('YES')


import sys
import itertools
import math
import collections
from collections import Counter

def pow(x, y, mod):
	r = 1
	x = x % mod
	while y > 0:
		if y & 1:
			r = r * x % mod
		y = y >> 1
		x = x * x % mod
	return r

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

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

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

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)
q = ii()
for _ in range(q):
	n = ii()
	d = []
	d.append(input())
	d.append(input())
	s1 = {'1', '2'}
	s2 = {'3', '4', '5', '6'}
	cr = 0
	f = False
	prev = i = 0
	while i < n:
		if d[cr][i] in s2 and d[1 - cr][i] in s2:
			cr = 1 - cr
			i += 1
		elif d[cr][i] in s1:
			i += 1
		if i == prev:
			break
		prev = i
		if i == n and cr == 1:
			f = True
			break
	print('YES') if f else print('NO')


def main():
	n = int(input())
	arr = []
	arr.append(list(input()))
	arr.append(list(input()))
	row = 0
	col = 0
	while col < n:
		if arr[row][col] >= '3':
			if arr[row ^ 1][col] < '3':
				break
			else:
				row = row ^ 1
		col += 1
	if col == n and row == 1:
		print('YES')
	else:
		print('NO')

def test():
	t = int(input())
	while t:
		main()
		t -= 1
	return
test()


q = int(input())
x = 0
while x < q:
	x += 1
	n = int(input())
	first = input()
	second = input()
	(rows, cols) = (2, n)
	arr = [[0 for i in range(cols)] for j in range(rows)]
	arr[0][0] = 1
	arr[1][0] = 2 if first[0] > '2' else 0
	for col in range(1, n):
		arr[0][col] = arr[0][col] | 1 if arr[0][col - 1] & 1 and first[col - 1] <= '2' else arr[0][col]
		arr[1][col] = arr[1][col] | 1 if arr[1][col - 1] & 1 and second[col - 1] <= '2' else arr[1][col]
		arr[0][col] = arr[0][col] | 1 if arr[0][col - 1] & 2 and first[col - 1] > '2' else arr[0][col]
		arr[1][col] = arr[1][col] | 1 if arr[1][col - 1] & 2 and second[col - 1] > '2' else arr[1][col]
		arr[0][col] = arr[0][col] | 2 if arr[1][col] & 1 and second[col] > '2' else arr[0][col]
		arr[1][col] = arr[1][col] | 2 if arr[0][col] & 1 and first[col] > '2' else arr[1][col]
	if arr[1][n - 1] & 1 and second[n - 1] <= '2':
		print('YES')
	elif arr[1][n - 1] & 2 and second[n - 1] > '2':
		print('YES')
	else:
		print('NO')


I = lambda : int(input())

def is_possible():
	cr = 0
	n = I()
	s1 = list(map(lambda x: 0 if x < 3 else 1, map(int, list(input()))))
	s2 = list(map(lambda x: 0 if x < 3 else 1, map(int, list(input()))))
	for i in range(n):
		if not cr:
			if s1[i]:
				if not s2[i]:
					return False
				else:
					cr = 1
		elif s2[i]:
			if not s1[i]:
				return False
			else:
				cr = 0
	return not not cr
for _ in range(I()):
	print('YES' if is_possible() else 'NO')


for _ in range(int(input())):
	n = int(input())
	l1 = list(input())
	l2 = list(input())
	o = ('1', '2')
	t = ('3', '4', '5', '6')
	turn = False
	for (i, j) in zip(l1, l2):
		if turn == False:
			if i not in o:
				turn = not turn
				if j not in t:
					print('NO')
					break
		elif j not in o:
			turn = not turn
			if i not in t:
				print('NO')
				break
	else:
		if turn:
			print('YES')
		else:
			print('NO')


def solve(n):
	row = [0, 0]
	row[0] = input()
	row[1] = input()
	crow = 0
	i = 0
	while i < n - 1:
		if row[crow][i] in '12':
			i += 1
			continue
		if crow == 0:
			if row[1][i] in '12':
				return 'NO'
			else:
				crow = 1
				i += 1
		elif row[0][i] in '12':
			return 'NO'
		else:
			crow = 0
			i += 1
	if crow == 0 and row[0][i] not in '12' and (row[1][i] not in '12'):
		return 'YES'
	if crow == 1 and row[1][i] in '12':
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solve(int(input())))


import os
from collections import Counter, defaultdict
from io import BytesIO, IOBase
import sys
from math import inf, ceil

def main():
	for i in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().strip()]
		b = [int(x) for x in input().strip()]
		for j in range(n):
			if a[j] <= 2:
				a[j] = 1
			else:
				a[j] = 2
			if b[j] <= 2:
				b[j] = 1
			else:
				b[j] = 2
		fg = 1
		p = 1
		for j in range(n):
			if p == 1:
				if a[j] == 2 and b[j] == 1:
					print('NO')
					fg = 0
					break
				elif a[j] == 2:
					p = 0
			elif a[j] == 1 and b[j] == 2:
				print('NO')
				fg = 0
				break
			elif b[j] == 2:
				p = 1
		if p and fg:
			print('NO')
		elif not p and fg:
			print('YES')
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
for i in range(n):
	a = int(input())
	d = input()
	f = input()
	e = 0
	e1 = 0
	re = 0
	tr = False
	while re <= a - 1:
		if re == a - 1:
			if e1 == 0 and (d[re] == '1' or d[re] == '2' or f[re] == '1' or (f[re] == '2')):
				tr = True
			elif e1 == 1 and (f[re] == '3' or f[re] == '4' or f[re] == '5' or (f[re] == '6')):
				tr = True
			re += 1
		elif e == 0:
			if d[re] == '1' or d[re] == '2':
				if e1 != 0:
					tr = True
					break
				re += 1
			if d[re] == '3' or d[re] == '4' or d[re] == '5' or (d[re] == '6'):
				if e1 == 0:
					e = 1
				else:
					re += 1
			e1 = 0
		else:
			if f[re] == '1' or f[re] == '2':
				if e1 != 1:
					tr = True
					break
				re += 1
			if f[re] == '3' or f[re] == '4' or f[re] == '5' or (f[re] == '6'):
				if e1 == 1:
					e = 0
				else:
					re += 1
			e1 = 1
	if tr:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	fl = 1
	pre = 0
	pfl = 1
	i = 0
	ans = 0
	while True:
		if fl == 1:
			if pfl == 1:
				if a[i] == '1' or a[i] == '2':
					pre = 1
					i += 1
				else:
					fl = 0
			elif a[i] == '1' or a[i] == '2':
				break
			else:
				i += 1
				pfl = 1
		elif pfl == 1:
			if b[i] == '1' or b[i] == '2':
				break
			else:
				i += 1
				pfl = 0
		elif b[i] == '1' or b[i] == '2':
			i += 1
		else:
			fl = 1
		if i == n:
			if fl == 0:
				ans = 1
			break
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for case in range(t):
	n = int(input())
	g = []
	for _ in range(2):
		g.append(list(input()))
	x = 0
	y = 0
	state = 'x'
	while True:
		if g[y][x] == '1' or g[y][x] == '2':
			if state == 'x':
				x += 1
			else:
				y = 999
				break
		elif state == 'x':
			if y == 1:
				y -= 1
				state = 'y'
			else:
				y += 1
				state = 'y'
		else:
			x += 1
			state = 'x'
		if x >= n:
			break
	if y == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	mat = [list(map(int, input())), list(map(int, input()))]
	x = y = cnt = 0
	while x < n:
		if mat[y][x] in [1, 2] and cnt % 2 == 0:
			x += 1
		elif mat[y][x] in [1, 2] and cnt % 2 != 0:
			break
		else:
			if cnt % 4 == 0:
				y += 1
			elif cnt % 4 == 2:
				y -= 1
			else:
				x += 1
			cnt += 1
	print(['NO', 'YES'][x == n and (cnt - 2) % 4 == 0])


for _ in range(int(input())):
	n = int(input())
	s = [input(), input()]
	cur = 0
	(x, y) = (0, 0)
	b = False
	while 1:
		if x == 1 and y == n:
			b = True
			break
		elif y >= n:
			break
		elif cur == 1 and s[x][y] < '3':
			break
		elif cur == 0 and s[x][y] < '3':
			y += 1
		elif cur == 0 and s[x][y] > '2':
			x = 1 - x
			cur = 1 - cur
		elif cur == 1 and s[x][y] > '2':
			y += 1
			cur = 1 - cur
	print('YNEOS'[not b::2])


for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(2):
		arr.append(list(input()))
	row = 0
	position = 0
	while position < n:
		if arr[row][position] >= '3':
			if arr[row ^ 1][position] < '3':
				break
			else:
				row ^= 1
		position += 1
	if position == n and row == 1:
		print('YES')
	else:
		print('NO')


q = int(input())
for rer in range(q):
	n = int(input())
	top = input()
	bottom = input()
	t = list(top)
	b = list(bottom)
	mat = [t, b]
	prev = [1, n]
	pos = [1, n - 1]
	while True:
		if pos == [0, -1]:
			print('YES')
			break
		if pos[0] not in [0, 1] or pos[1] < 0 or pos[1] > n - 1:
			print('NO')
			break
		if mat[pos[0]][pos[1]] == '1' or mat[pos[0]][pos[1]] == '2':
			if prev[0] != pos[0]:
				print('NO')
				break
			else:
				prev = pos
				pos = [prev[0], prev[1] - 1]
		elif prev[0] != pos[0]:
			prev = pos
			pos = [prev[0], prev[1] - 1]
		else:
			prev = pos
			pos = [(prev[0] + 1) % 2, prev[1]]


for _ in range(int(input())):
	n = int(input())
	a1 = list(input())
	a2 = list(input())
	row = 1
	flag = True
	for i in range(n):
		if row == 1:
			if a1[i] == '1' or a1[i] == '2':
				continue
			else:
				row = 2
				if a2[i] == '1' or a2[i] == '2':
					flag = False
					break
		elif row == 2:
			if a2[i] == '1' or a2[i] == '2':
				continue
			else:
				row = 1
				if a1[i] == '1' or a1[i] == '2':
					flag = False
					break
	if flag and row == 2:
		print('YES')
	else:
		print('NO')


import sys

def rint():
	return map(int, sys.stdin.readline().split())
q = int(input())
for _ in range(q):
	n = int(input())
	t0 = input()
	t1 = input()
	r0 = []
	r1 = []
	r = [[0 for i in range(n)] for j in range(2)]
	for i in range(n):
		tmp = int(t0[i])
		if tmp > 2:
			tmp = 1
		else:
			tmp = 0
		r[0][i] = tmp
	for i in range(n):
		tmp = int(t1[i])
		if tmp > 2:
			tmp = 1
		else:
			tmp = 0
		r[1][i] = tmp
	pos = (0, 0)
	prev = 'h'
	not_ok = 0
	while pos[1] < n:
		rr = pos[0]
		cc = pos[1]
		if prev == 'h':
			if r[rr][cc] == 0:
				pos = (rr, cc + 1)
			else:
				pos = ((rr + 1) % 2, cc)
				prev = 'v'
		elif r[rr][cc] == 0:
			not_ok = 1
			break
		else:
			pos = (rr, cc + 1)
			prev = 'h'
	if not_ok or pos[0] != 1:
		print('NO')
	else:
		print('YES')


a = int(input())
for i in range(a):
	b = int(input())
	c = input()
	d = input()
	l = [c, d]
	k = 0
	ans = 1
	for i in range(b):
		if l[k][i] == '1' or l[k][i] == '2':
			pass
		elif l[1 - k][i] == '3' or l[1 - k][i] == '4' or l[1 - k][i] == '5' or (l[1 - k][i] == '6'):
			k = 1 - k
		else:
			ans = 0
	if k == 1 and ans == 1:
		print('YES')
	else:
		print('NO')


q = int(input())
while q > 0:
	q -= 1
	n = int(input())
	a = input()
	b = input()
	s = []
	s.append([0, 0, 'ul'])
	done = False
	while s:
		c = s.pop(0)
		if c[0] == 1 and c[1] == n:
			done = True
			break
		if c[1] == n:
			break
		if c[0] == 0:
			l = int(a[c[1]])
		else:
			l = int(b[c[1]])
		if l == 1 or l == 2:
			if c[2] == 'ul' or c[2] == 'bl':
				s.append([c[0], c[1] + 1, c[2]])
		elif c[2] == 'ul':
			s.append([c[0] + 1, c[1], 'bu'])
		elif c[2] == 'bl':
			s.append([c[0] - 1, c[1], 'ub'])
		elif c[2] == 'bu':
			s.append([c[0], c[1] + 1, 'bl'])
		elif c[2] == 'ub':
			s.append([c[0], c[1] + 1, 'ul'])
	if done:
		print('YES')
	else:
		print('NO')


q = int(input())
for qi in range(q):
	n = int(input())
	m = [[int(x) for x in input()], [int(x) for x in input()]]
	yi = 0
	r = True
	for xi in range(n):
		if m[yi][xi] >= 3:
			yi = abs(yi - 1)
			if m[yi][xi] <= 2:
				r = False
				break
	else:
		r = yi == 1
	print('YES' if r else 'NO')


q = int(input())
for _ in range(q):
	i = 0
	up = 1
	down = 0
	c = 0
	n = int(input())
	l1 = list(map(int, input()))
	l2 = list(map(int, input()))
	while i < n:
		if down == 1:
			if l2[i] > 2:
				if l1[i] <= 2:
					c += 1
					break
				up = 1
				down = 0
		elif up == 1:
			if l1[i] > 2:
				if l2[i] <= 2:
					c += 1
					break
				up = 0
				down = 1
		i += 1
	if down == 1 and c == 0:
		print('YES')
	else:
		print('NO')


q = int(input())
types = {'1': False, '2': False, '3': True, '4': True, '5': True, '6': True}
for i in range(q):
	n = int(input())
	rows = [[types[ch] for ch in input()] for j in range(2)]
	cur_row = 0
	valid = True
	for j in range(n):
		if not rows[cur_row][j]:
			continue
		cur_row = (cur_row + 1) % 2
		if rows[cur_row][j]:
			continue
		else:
			valid = False
			break
	valid = valid and cur_row == 1
	if valid:
		print('YES')
	else:
		print('NO')


def checkPipe(upList, downList, n):
	checkUp = True
	for i in range(n):
		if checkUp:
			if upList[i] != 1 and upList[i] != 2:
				if downList[i] == 1 or downList[i] == 2:
					return False
				checkUp = False
		elif downList[i] != 1 and downList[i] != 2:
			if upList[i] == 1 or upList[i] == 2:
				return False
			checkUp = True
	if checkUp:
		return False
	else:
		return True
q = int(input())
for i in range(q):
	n = int(input())
	up = list(map(int, input()))
	down = list(map(int, input()))
	if checkPipe(up, down, n):
		print('YES')
	else:
		print('NO')


from collections import deque
for _ in range(int(input())):
	n = int(input())
	g = []
	g.append(list(input()))
	g.append(list(input()))
	f = 0
	i = 0
	x = 0
	while i < n:
		if f == 0:
			if g[f][i] in '12':
				if x == 1:
					break
				i += 1
			elif x == 0:
				(x, f) = (1, 1)
			else:
				(x, f) = (0, 0)
				i += 1
		elif g[f][i] in '12':
			if x == 1:
				break
			i += 1
		elif x == 0:
			(x, f) = (1, 0)
		else:
			(x, f) = (0, 1)
			i += 1
	if i == n and f == 1:
		print('YES')
	else:
		print('NO')


q = int(input())
for it in range(q):
	n = int(input())
	a = []
	a.append(list(map(int, list(input()))))
	a.append(list(map(int, list(input()))))
	i = j = 0
	for i in range(n):
		if a[j][i] < 3:
			continue
		elif a[j][i] >= 3 and a[1 - j][i] >= 3:
			j = 1 - j
		else:
			j = 0
			break
	print('YES' if j == 1 else 'NO')


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import combinations, permutations
from bisect import *
from fractions import Fraction
from heapq import *
from random import randint

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().rstrip()))
		b = list(map(int, input().rstrip()))
		for i in range(n):
			if a[i] < 3:
				a[i] = 1
			else:
				a[i] = 2
			if b[i] < 3:
				b[i] = 1
			else:
				b[i] = 2
		dp = [[0, 0] for _ in range(n)]
		if a[0] == 1:
			dp[0][0] = 1
		if b[0] == 2 and a[0] == 2:
			dp[0][1] = 1
		for i in range(1, n):
			if dp[i - 1][0] and a[i] == 1 or (dp[i - 1][1] and b[i] == 2 and (a[i] == 2)):
				dp[i][0] = 1
			if dp[i - 1][1] and b[i] == 1 or (dp[i - 1][0] and b[i] == 2 and (a[i] == 2)):
				dp[i][1] = 1
		if dp[-1][1]:
			print('YES')
		else:
			print('NO')
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


q = int(input())
for _ in range(q):
	n = int(input())
	a = [[], []]
	a[0] = input()
	a[1] = input()
	r = 0
	w = 1
	flag = False
	i = 0
	while i < n:
		if r == 0:
			if w == 1:
				if int(a[r][i]) <= 2:
					t = 1
				else:
					t = 2
				if t == 1:
					i += 1
					continue
				else:
					r = 1
					w = 2
			elif w == 3:
				if int(a[r][i]) <= 2:
					t = 1
				else:
					t = 2
				if t == 1:
					flag = True
					break
				else:
					i += 1
					w = 1
					continue
			else:
				flag = True
				break
		elif w == 1:
			if int(a[r][i]) <= 2:
				t = 1
			else:
				t = 2
			if t == 1:
				i += 1
				continue
			else:
				r = 0
				w = 3
		elif w == 2:
			if int(a[r][i]) <= 2:
				t = 1
			else:
				t = 2
			if t == 2:
				i += 1
				w = 1
				continue
			else:
				flag = True
				break
		else:
			flag = True
			break
	if flag:
		print('NO')
	elif i == n and r == 1:
		print('YES')
	else:
		print('NO')


import sys
import os
from io import IOBase, BytesIO
import math
import collections
mod = 10 ** 9 + 7
pie = 3.1415926536

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def ain():
	return list(map(int, sin().split()))

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

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def read2DIntArray(row, col):
	arr = []
	for i in range(0, row):
		temp = list(map(int, sin().split()))
		arr.append(temp)
	return arr

def read2DCharArray(row, col):
	arr = []
	for i in range(0, row):
		temp = str(sin())
		arr.append(temp)
	return arr

def smallestNumber(n):
	lst = list(str(n))
	lst.sort()
	tmp = ''
	for (i, n) in enumerate(lst):
		if n != '0':
			tmp = lst.pop(i)
			break
	return str(tmp) + ''.join(lst)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	lst = []
	for p in range(n + 1):
		if prime[p]:
			lst.append(p)
	return lst

def nCr(n, r):
	a = 1
	b = 1
	c = 1
	for i in range(1, n + 1):
		c *= i
	for i in range(1, r + 1):
		b *= i
	for i in range(1, n - r + 1):
		a *= i
	return c // (a * b)

def sieveOfEratosthenes1(N, s):
	prime = [False] * (N + 1)
	for i in range(2, N + 1, 2):
		s[i] = 2
	for i in range(3, N + 1, 2):
		if prime[i] == False:
			s[i] = i
			for j in range(i, int(N / i) + 1, 2):
				if prime[i * j] == False:
					prime[i * j] = True
					s[i * j] = i

def generatePrimeFactors(N):
	s = [0] * (N + 1)
	sieveOfEratosthenes1(N, s)
	curr = s[N]
	cnt = 1
	factors = []
	power = []
	while N > 1:
		N //= s[N]
		if curr == s[N]:
			cnt += 1
			continue
		factors.append(curr)
		power.append(cnt)
		curr = s[N]
		cnt = 1
	return (factors, power)

def main():
	for _ in range(int(sin())):
		n = int(sin())
		s1 = sin()
		s2 = sin()
		lst = []
		lst.append(s1)
		lst.append(s2)
		i = 0
		j = 0
		st = 'R'
		while i != n:
			pipe = lst[j][i]
			if st == 'R':
				if pipe == '1' or pipe == '2':
					i += 1
				elif j == 0:
					st = 'D'
					j = 1
				else:
					st = 'U'
					j = 0
			elif pipe == '1' or pipe == '2':
				break
			else:
				st = 'R'
				i += 1
		if i == n and j == 1:
			print('YES')
		else:
			print('NO')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

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


ans = []
for _ in range(int(input())):
	n = int(input())
	s = list(input())
	t = list(input())
	lvl = 0
	X = [s, t]
	f = 1
	for i in range(n):
		if s[i] in '3456' and t[i] in '3456':
			lvl = 1 - lvl
		elif X[lvl][i] in '3456':
			f = 0
			ans.append('NO')
			break
	if f and lvl == 1:
		ans.append('YES')
	elif f:
		ans.append('NO')
print('\n'.join(ans))


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	s = list(input())
	normal = {'1', '2'}
	curved = {'3', '4', '5', '6'}
	arr = []
	arr.append(a)
	arr.append(s)
	row = 0
	where = 0
	i = 0
	while i < n:
		if arr[row][i] in normal:
			if where == row:
				i += 1
			else:
				print('NO')
				break
		elif where != row:
			where = row
			i += 1
		else:
			where = row
			row ^= 1
	else:
		if row == 1:
			print('YES')
		else:
			print('NO')


q = int(input())
corners = {3, 4, 5, 6}
edges = {1, 2}
for _ in range(q):
	n = int(input())
	l = [[int(x) for x in input()], [int(x) for x in input()]]
	i = 0
	j = 0
	while True:
		if i == n:
			print('YES' if j == 1 else 'NO')
			break
		if l[j][i] in corners:
			j ^= 1
			if l[j][i] in edges:
				print('NO')
				break
			i += 1
		else:
			i += 1


t = int(input())
while t:
	n = int(input())
	str1 = input()
	str2 = input()
	arr = [0, str1, str2]
	j = 1
	for i in range(n):
		if int(arr[j][i]) == 1 or int(arr[j][i]) == 2:
			j = j
		else:
			if j == 1:
				j = 2
			else:
				j = 1
			if int(arr[j][i]) == 1 or int(arr[j][i]) == 2:
				j = 0
				break
	if j == 2 and i == n - 1:
		print('YES')
	else:
		print('NO')
	t -= 1


for i in range(int(input())):
	n = int(input())
	s1 = list(map(int, list(input())))
	s2 = list(map(int, list(input())))
	dp = [s1, s2]
	x = 0
	y = 0
	(d, u, s) = (0, 0, 0)
	ans = 'YES'
	while x < n:
		if x == 0 and y == 0:
			if dp[y][x] == 1 or dp[y][x] == 2:
				s = 1
				x += 1
			else:
				(s, u) = (0, 0)
				(d, y) = (1, 1)
		elif s == 1:
			if y == 0:
				if dp[y][x] == 1 or dp[y][x] == 2:
					x += 1
					s = 1
					(y, d, u) = (0, 0, 0)
				else:
					y = 1
					d = 1
					(s, u) = (0, 0)
			elif dp[y][x] == 1 or dp[y][x] == 2:
				x += 1
				s = 1
				(d, u) = (0, 0)
			else:
				y = 0
				u = 1
				(s, d) = (0, 0)
		elif u == 1:
			if dp[y][x] == 1 or dp[y][x] == 2:
				ans = 'NO'
				break
			else:
				x += 1
				s = 1
				(d, u) = (0, 0)
		elif d == 1:
			if dp[y][x] == 1 or dp[y][x] == 2:
				ans = 'NO'
				break
			else:
				x += 1
				s = 1
				(d, u) = (0, 0)
	if x == n and y == 1:
		print(ans)
	else:
		print('NO')


q = int(input())
type1 = '12'
type2 = '3456'
for i in range(q):
	n = int(input())
	row1 = list(input())
	row2 = list(input())
	rows = [row1, row2]
	column = 0
	row = 0
	while column < n:
		if rows[row][column] in type1:
			column += 1
		elif rows[1 - row][column] in type2:
			column += 1
			row = 1 - row
		else:
			break
	if column == n and row == 1:
		print('YES')
	else:
		print('NO')


q = int(input())

def switch(x):
	if x == 1:
		return 0
	return 1
for _ in range(q):
	n = int(input())
	s1 = input()
	s2 = input()
	r1 = [1 if x == '1' or x == '2' else 0 for x in s1]
	r2 = [1 if x == '1' or x == '2' else 0 for x in s2]
	r1.append(1)
	r2.append(1)
	A = [r1, r2]
	temp = 0
	check = False
	for i in range(n):
		if A[temp][i] == 1:
			continue
		elif A[temp][i] == 0 and A[switch(temp)][i] == 1:
			check = True
			break
		else:
			temp = switch(temp)
	if check:
		print('NO')
	elif temp == 0:
		if A[switch(temp)][n] == 1:
			print('NO')
		else:
			print('YES')
	elif A[temp][n] == 1:
		print('YES')
	else:
		print('NO')


q = int(input())
for case in range(q):
	n = int(input())
	r1 = input()
	r2 = input()
	(r, c, s, f) = (1, 1, 'i', True)
	if r1[0] == '3' or r1[0] == '4' or r1[0] == '5' or (r1[0] == '6'):
		s = 'd'
	elif r1[0] == '1' or r1[0] == '2':
		s = 'r'
	while c < n:
		if s == 'u' and (r1[c - 1] == '1' or r1[c - 1] == '2'):
			f = False
			break
		elif s == 'd' and (r2[c - 1] == '1' or r2[c - 1] == '2'):
			f = False
			break
		elif s == 'u':
			(r, s) = (1, 'r')
		elif s == 'd':
			(r, s) = (2, 'r')
		elif s == 'r' and r == 1:
			c += 1
			if r1[c - 1] == '3' or r1[c - 1] == '4' or r1[c - 1] == '5' or (r1[c - 1] == '6'):
				s = 'd'
		elif s == 'r' and r == 2:
			c += 1
			if r2[c - 1] == '3' or r2[c - 1] == '4' or r2[c - 1] == '5' or (r2[c - 1] == '6'):
				s = 'u'
	if r == 1 and (s != 'd' or r2[n - 1] == '1' or r2[n - 1] == '2'):
		f = False
	elif r == 2 and s != 'r':
		f = False
	if f:
		print('YES')
	else:
		print('NO')


q = int(input())
for q in range(q):
	n = int(input())
	str1 = input()
	str2 = input()
	curr = 0
	conc = []
	flag = True
	for i in range(n):
		conc.append((str1[i], str2[i]))
	for i in range(n):
		if conc[i][curr] == '1' or conc[i][curr] == '2':
			continue
		else:
			if conc[i][1 - curr] not in ['3', '4', '5', '6']:
				flag = False
				break
			curr = 1 - curr
	if not flag or curr != 1:
		print('NO')
	else:
		print('YES')


Q = int(input())
for q in range(Q):
	n = int(input())
	arr = []
	arr.append(list(input()))
	arr.append(list(input()))
	(x, y) = (0, 0)
	d = 0
	pos = 1
	while pos:
		p = arr[y][x]
		if p == '1' or p == '2':
			if d == 0:
				x += 1
			else:
				pos = 0
				break
		elif y == 0:
			if d == 0:
				y = 1
				d = 1
			else:
				x += 1
				d = 0
		elif d == 0:
			y = 0
			d = -1
		else:
			x += 1
			d = 0
		if x == n and y == 1:
			pos = 1
			break
		if x > n - 1 or y > 1:
			pos = 0
			break
	if pos:
		print('YES')
	else:
		print('NO')


q = int(input())
ans = []
trubi = {1: 1, 2: 1, 3: 2, 4: 2, 5: 2, 6: 2}
for i in range(q):
	n = int(input())
	row1 = list(map(int, input()))
	row2 = list(map(int, input()))
	row = row1 + row2
	if not (1 in row or 2 in row):
		if n % 2 == 0:
			ans.append('NO')
		else:
			ans.append('YES')
	elif not (3 in row1 or 4 in row1 or 5 in row1 or (6 in row1)):
		ans.append('NO')
	else:
		count = 0
		for j in range(n):
			if count % 2 == 0:
				if trubi[row1[j]] == 2:
					if trubi[row2[j]] != 2:
						ans.append('NO')
						break
					else:
						count += 1
			elif trubi[row2[j]] == 2:
				if trubi[row1[j]] != 2:
					ans.append('NO')
					break
				else:
					count += 1
			if j == n - 1:
				if count % 2 == 0:
					ans.append('NO')
				else:
					ans.append('YES')
print(*ans, sep='\n')


q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, list(input())))
	b = list(map(int, list(input())))
	c = [[0 for i in range(n)] for i in range(2)]
	for i in range(n):
		if a[i] < 3:
			c[0][i] = 1
		else:
			c[0][i] = 2
		if b[i] < 3:
			c[1][i] = 1
		else:
			c[1][i] = 2
	last = True
	now = 0
	ind = 0
	last_now = 0
	flag = True
	while ind < n and flag:
		if c[now][ind] == 1:
			if now != last_now:
				flag = False
			else:
				ind += 1
				last_now = now
		elif last_now != now:
			ind += 1
			last_now = now
		else:
			last_now = now
			now ^= 1
	if now == 1 and ind == n and flag:
		print('YES')
	else:
		print('NO')


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

def solve():
	N = int(input())
	L = [[v for v in input()[:-1]] for _ in range(2)]
	cur_x = 0
	cur_y = 0
	prev_flow_from = 'L'
	ans = 'YES'
	while True:
		cur_pipe = L[cur_y][cur_x]
		if cur_pipe == '1' or cur_pipe == '2':
			if prev_flow_from == 'L':
				next_x = cur_x + 1
				next_y = cur_y
			elif prev_flow_from == 'D':
				ans = 'NO'
				break
			elif prev_flow_from == 'U':
				ans = 'NO'
				break
		elif prev_flow_from == 'L':
			if cur_y == 0:
				next_x = cur_x
				next_y = cur_y + 1
				prev_flow_from = 'D'
			elif cur_y == 1:
				next_x = cur_x
				next_y = cur_y - 1
				prev_flow_from = 'U'
		elif prev_flow_from == 'D':
			next_x = cur_x + 1
			next_y = cur_y
			prev_flow_from = 'L'
		elif prev_flow_from == 'U':
			next_x = cur_x + 1
			next_y = cur_y
			prev_flow_from = 'L'
		if next_x == N and next_y == 1:
			if prev_flow_from == 'L':
				ans = 'YES'
			else:
				ans = 'NO'
			break
		elif 0 <= next_x < N and 0 <= next_y < 2:
			cur_x = next_x
			cur_y = next_y
			continue
		else:
			ans = 'NO'
			break
	print(ans)
N = int(input())
for _ in range(N):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(input())
	b = list(input())
	f = 0
	c = 0
	for i in range(n):
		if c == 0:
			if a[i] == '1' or a[i] == '2':
				pass
			else:
				c = 1
				if b[i] == '1' or b[i] == '2':
					f = 1
					break
		elif b[i] == '1' or b[i] == '2':
			pass
		else:
			c = 0
			if a[i] == '1' or a[i] == '2':
				f = 1
				break
	if f == 0 and c == 1:
		print('YES')
	else:
		print('NO')


num = int(input())
for i in range(num):
	numPipes = int(input())
	row1 = input()
	row1 = [int(x) for x in row1]
	row2 = input()
	row2 = [int(x) for x in row2]
	row1Bool = True
	row2Bool = False
	for j in range(numPipes):
		temp1 = row1Bool and row1[j] < 3 or (row2Bool and row1[j] > 2 and (row2[j] > 2))
		temp2 = row2Bool and row2[j] < 3 or (row1Bool and row1[j] > 2 and (row2[j] > 2))
		row1Bool = temp1
		row2Bool = temp2
	print('YES' if row2Bool else 'NO')


import sys
input = lambda : sys.stdin.readline().strip()
ipnut = input
for i in range(int(input())):
	n = int(ipnut())
	field = [list(map(int, ipnut())), list(map(int, input()))]
	(x, y) = (0, 0)
	fr = 0
	flag = True
	for i in range(2 * n):
		if y == n:
			break
		if fr:
			if fr == 1:
				if field[x][y] in [1, 2]:
					y += 1
				else:
					x = (x + 1) % 2
					fr = 2
			elif field[x][y] in [1, 2]:
				flag = False
				break
			else:
				y += 1
				fr = 1
		elif field[x][y] in [1, 2]:
			y += 1
			fr = 1
		else:
			x = (x + 1) % 2
			fr = 2
	if flag and x:
		print('Yes')
	else:
		print('NO')


def is_A(x):
	return x == '1' or x == '2'

def is_B(x):
	return x == '3' or x == '4' or x == '5' or (x == '6')
q = int(input())
for _ in range(q):
	n = int(input())
	s1 = input()
	s2 = input()
	s = [s1, s2]
	(res, p, j, i) = (True, 0, 0, 0)
	while i < n:
		if p == 0 and is_A(s[j][i]):
			p = 0
		elif p == 1 and is_B(s[j][i]):
			p = 0
		elif p == 0 and is_B(s[j][i]):
			if j == 0:
				p = 1
			else:
				p = 2
			j = 1 - j
			i -= 1
		elif p == 2 and is_B(s[j][i]):
			p = 0
		else:
			res = False
		i += 1
	print('YES' if res and j == 1 else 'NO')


q = int(input())
for i in range(q):
	n = int(input())
	a = []
	a.append([int(i) for i in list(input())])
	a.append([int(i) for i in list(input())])
	pos = 0
	for i in range(n):
		if a[pos][i] > 2:
			if a[abs(pos - 1)][i] > 2:
				pos = abs(pos - 1)
			else:
				print('NO')
				break
	else:
		if pos == 1:
			print('YES')
		else:
			print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	s1 = input()
	s2 = input()
	r = 1
	ch = 1
	for i in range(n):
		if r == 1:
			if s1[i] == '1' or s1[i] == '2':
				ch = ch
				r = 1
			else:
				r = 2
				if s2[i] == '1' or s2[i] == '2':
					ch = 0
		elif s2[i] == '1' or s2[i] == '2':
			ch = ch
			r = 2
		else:
			r = 1
			if s1[i] == '1' or s1[i] == '2':
				ch = 0
	if ch == 0 or r == 1:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	s = int(input())
	p = [[int(i) for i in input()], [int(i) for i in input()]]
	d = 3
	q = [0, 0]
	while q != [1, s]:
		if 0 <= q[0] < 2 and 0 <= q[1] < s:
			r = p[q[0]][q[1]]
			if r < 3:
				if d == 3:
					q = [q[0], q[1] + 1]
				else:
					print('NO')
					break
			elif q[0] == 1 and d == 0:
				q = [1, q[1] + 1]
				d = 3
			elif q[0] == 1 and d == 3:
				q = [0, q[1]]
				d = 2
			elif q[0] == 0 and d == 3:
				q = [1, q[1]]
				d = 0
			elif q[0] == 0 and d == 2:
				q = [0, q[1] + 1]
				d = 3
			else:
				print('NO')
				break
		else:
			print('NO')
			break
	else:
		if d == 3:
			print('YES')
		else:
			print('NO')


test = int(input())
for _ in range(test):
	n = int(input())
	arr = [[int(el) for el in str(input())] for i in range(2)]
	matrix = [[0 for y in range(n + 1)] for i in range(2)]
	matrix[0][0] = True
	is_ok = [1, 2]
	is_not_ok = [3, 4, 5, 6]
	for i in range(1, n + 1):
		if arr[0][i - 1] in is_ok:
			matrix[0][i] = matrix[0][i - 1]
		if arr[1][i - 1] in is_ok:
			matrix[1][i] = matrix[1][i - 1]
		if arr[0][i - 1] in is_not_ok and arr[1][i - 1] in is_not_ok:
			matrix[0][i] = matrix[0][i] or matrix[1][i - 1]
			matrix[1][i] = matrix[1][i] or matrix[0][i - 1]
	print('YES' if bool(matrix[1][n]) else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input()]
	brr = [int(i) for i in input()]
	grid = list(zip(arr, brr))
	way = 0
	flag = 0
	rule1 = [1, 2]
	rule2 = [3, 4, 5, 6]
	for i in grid:
		if i[way] == 1 or i[way] == 2:
			pass
		elif i[1] in rule1 or i[0] in rule1:
			flag = 1
			break
		elif way == 1:
			way = 0
		else:
			way = 1
	if flag == 1 or way == 0:
		print('NO')
	else:
		print('YES')


cases = int(input())
for _ in range(cases):
	numPipes = int(input())
	pipesTop = input()
	pipesBot = input()
	row = 0
	col = 0
	topTurn = 2
	botTurn = 2
	lastPipe = -1
	while col < numPipes:
		if row == 0:
			pipe = int(pipesTop[col])
			if pipe <= 2:
				col += 1
				if topTurn == 1:
					col = -1
					break
			elif topTurn == 2:
				row = 1
				topTurn = 1
				botTurn = 1
			else:
				topTurn = 2
				col += 1
		else:
			pipe = int(pipesBot[col])
			if pipe <= 2:
				col += 1
				if botTurn == 1:
					col = -1
					break
			elif botTurn == 2:
				row = 0
				topTurn = 1
				botTurn = 1
			else:
				botTurn = 2
				col += 1
	if row == 1 and col == numPipes:
		print('YES')
	else:
		print('NO')


dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]

def next_xy(x, y, d):
	return (x + dx[d], y + dy[d])

def ok_xy(x, y, n):
	return 0 <= x < n and 0 <= y < 2

def solve():
	n = int(input())
	a = [0, 0]
	a[0] = list(map(int, input()))
	a[1] = list(map(int, input()))
	x = -1
	y = 0
	d = 1
	while True:
		(nx, ny) = next_xy(x, y, d)
		assert ok_xy(nx, ny, n)
		if a[ny][nx] in (1, 2):
			nd = d
		elif d in (0, 2):
			nd = 1
		elif ny == 0:
			nd = 2
		else:
			nd = 0
		(x, y, d) = (nx, ny, nd)
		if x == n - 1 and y == 1 and (d == 1):
			return

def main():
	q = int(input())
	for _ in range(q):
		try:
			solve()
		except AssertionError:
			print('NO')
		else:
			print('YES')
main()


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input()))
	l2 = list(map(int, input()))
	row = 1
	ent = 10
	ext = 10
	i = 0
	flag = 1
	while i < n and flag:
		if l1[i] in [1, 2] and row == 1 and (ent in [-1, 10]):
			ent = -1
			ext = 1
		elif l2[i] in [1, 2] and row == 0 and (ent in [-1, 10]):
			ent = -1
			ext = 1
		elif l1[i] in [3, 4, 5, 6] and ent in [-1, 10] and (row == 1):
			ent = 2
			ext = 0
			row = 0
		elif l2[i] in [3, 4, 5, 6] and row == 0 and (ent in [2, 10]):
			ent = -1
			ext = 1
			row = 0
		elif l2[i] in [3, 4, 5, 6] and ent in [-1, 10] and (row == 0):
			ent = 0
			ext = 2
			row = 1
		elif l1[i] in [3, 4, 5, 6] and row == 1 and (ent in [0, 10]):
			ent = -1
			ext = 1
		else:
			flag = 0
			break
		if ext == 1:
			i += 1
	if row == 0 and ext == 1 and flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for k in range(1, t + 1):
	n = int(input())
	upper = input()
	lower = input()
	i = 0
	j = 0
	while (i == 0 or i == 1) and (j >= 0 and j < n):
		if i == 0:
			if int(upper[j]) == 1 or int(upper[j]) == 2:
				j = j + 1
			elif int(lower[j]) == 1 or int(lower[j]) == 2:
				i = 3
			else:
				i = 1
				j = j + 1
		elif int(lower[j]) == 1 or int(lower[j]) == 2:
			j = j + 1
		elif int(upper[j]) == 1 or int(upper[j]) == 2:
			i = 3
		else:
			j = j + 1
			i = 0
	if i == 1 and j == n:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	matrix = []
	matrix.append(list(input()))
	matrix.append(list(input()))
	(pi, pj) = (0, -1)
	(i, j) = (0, 0)
	visited = [[0 for i in range(n)] for i in range(2)]
	while i < 2 and j < n:
		if visited[i][j] == 1:
			break
		visited[i][j] = 1
		if matrix[i][j] == '1' or matrix[i][j] == '2':
			if pi == i:
				j += 1
				pj += 1
			else:
				break
		elif pi == i:
			(pi, pj) = (i, j)
			if j < pj:
				break
			if i == 0:
				i = 1
			else:
				i = 0
		else:
			(pi, pj) = (i, j)
			j += 1
	if i == 1 and j == n:
		print('YES')
	else:
		print('NO')


def trub(path: list, n):
	F = [[0] * n for z in range(2)]
	i = j = corner = 0
	while j < n:
		if 1 <= int(path[i][j]) <= 2:
			j += 1
		elif 3 <= int(path[i][j]) <= 6:
			if int(path[1 - i % 2][j]) < 3:
				return 'NO'
			else:
				j += 1
				i = 1 - i % 2
	return 'YES' if i > 0 else 'NO'
for k in range(int(input())):
	n = int(input())
	r0 = input()
	r1 = input()
	path = [r0, r1]
	print(trub(path, n))


from math import *
m = int(input())

def func(a):
	if a == '1' or a == '2':
		return 0
	else:
		return 1
for _ in range(m):
	tmp = 0
	n = int(input())
	t = []
	t.append(input())
	t.append(input())
	k = 0
	for i in range(n):
		if func(t[tmp][i]) == 1 and func(t[0][i]) == func(t[1][i]):
			tmp = 1 - tmp
		elif func(t[tmp][i]) != 0:
			break
		k += 1
	if tmp == 1 and k == n:
		print('YES')
	else:
		print('NO')


queries = []
nb_queries = int(input())
for i in range(nb_queries):
	query = dict()
	query['taille_pipe'] = int(input())
	query['firt_pipe'] = input()
	query['second_pipe'] = input()
	queries.append(query)
for query in queries:
	previous = True
	pipe_dict = {True: query['firt_pipe'], False: query['second_pipe']}
	for i in range(query['taille_pipe']):
		if pipe_dict[previous][i] <= str(2):
			continue
		elif int(query['firt_pipe'][i]) > 2 and int(query['second_pipe'][i]) > 2:
			previous = not previous
		else:
			previous = None
			break
	if previous == False:
		print('YES')
	else:
		print('NO')


import sys
from sys import stdin, stdout
from collections import defaultdict
from collections import deque
import math
import copy
T = int(input())
for i in range(T):
	N = int(input())
	s = input()
	s2 = input()
	s = [int(x) for x in list(s)]
	s2 = [int(x) for x in list(s2)]
	pipe = [s, s2]
	row = 0
	col = 0
	last = 1
	if pipe[row][col] <= 2:
		col += 1
		last = 3
	elif pipe[row][col] >= 3:
		row += 1
		last = 4
	while col < N:
		flag = 0
		if row == 0 and last == 3:
			if pipe[row][col] <= 2:
				col += 1
				last = 3
			else:
				row += 1
				last = 4
		elif row == 0 and last == 2:
			if pipe[row][col] >= 3:
				col += 1
				last = 3
			else:
				flag = 1
				break
		elif row == 1 and last == 3:
			if pipe[row][col] <= 2:
				col += 1
				last = 3
			else:
				row -= 1
				last = 2
		elif row == 1 and last == 4:
			if pipe[row][col] >= 3:
				col += 1
				last = 3
			else:
				flag = 1
				break
	if flag == 1:
		print('NO')
	elif row == 1 and col == N:
		print('YES')
	else:
		print('NO')


q = int(input())
n = [None] * q
p = [[]] * q
for i in range(q):
	n[i] = int(input())
	p1 = list(map(int, [i for i in input()]))
	p2 = list(map(int, [i for i in input()]))
	p1 = [0] + p1
	p2 = [0] + p2
	p[i] = (p1, p2)
(ver, hor) = (0, 1)
a = (1, 2)
b = (3, 4, 5, 6)

def next_pos(cur, d, pipe):
	(x, y) = cur
	if d == hor and pipe in a:
		return ((x, y + 1), hor)
	elif d == hor and pipe in b:
		if x == 1:
			return ((x + 1, y), ver)
		if x == 2:
			return ((x - 1, y), ver)
	elif d == ver and pipe in b:
		return ((x, y + 1), hor)
	else:
		return ((-1, -1), -1)
for i in range(q):
	s = (1, 1)
	e = (2, n[i] + 1)
	d = hor
	pipe = p[i][0][1]
	while True:
		(s, d) = next_pos(s, d, pipe)
		if s == e:
			print('YES')
			break
		if d == -1 or (s[0] == 1 and s[1] == n[i] + 1):
			print('NO')
			break
		pipe = p[i][s[0] - 1][s[1]]


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	z = 0
	ans = 0
	for i in range(n):
		if z == 0:
			if a[i] == '1' or a[i] == '2':
				continue
			elif a[i] in '3456' and b[i] in '3546':
				z = 1
			else:
				ans = 1
		elif b[i] == '1' or b[i] == '2':
			continue
		elif a[i] in '3456' and b[i] in '4356':
			z = 0
		else:
			ans = 1
		if ans == 1:
			break
	if ans == 0 and z == 1:
		print('YES')
	else:
		print('NO')


def checkPipeSystem(pipeSystem, flowIn):
	if len(pipeSystem) == 1:
		if flowIn == 'Up':
			if pipeSystem[0][0] > 2 and pipeSystem[0][1] > 2:
				return 'YES'
			return 'NO'
		if flowIn == 'Down':
			if pipeSystem[0][0] < 3:
				return 'YES'
			return 'NO'
	if flowIn == 'Up':
		if pipeSystem[0][0] > 2 and pipeSystem[0][1] > 2:
			return checkPipeSystem(pipeSystem[1:], 'Down')
		if pipeSystem[0][0] < 3:
			return checkPipeSystem(pipeSystem[1:], 'Up')
		return 'NO'
	if flowIn == 'Down':
		if pipeSystem[0][0] > 2 and pipeSystem[0][1] > 2:
			return checkPipeSystem(pipeSystem[1:], 'Up')
		if pipeSystem[0][1] < 3:
			return checkPipeSystem(pipeSystem[1:], 'Down')
		return 'NO'
queries = int(input())
result = ''
type1 = ['1', '2']
type2 = ['3', '4', '5', '6']
for i in range(queries):
	n = int(input())
	a = input()
	b = input()
	flowIn = 'Up'
	check = 'YES'
	for j in range(n - 1):
		if flowIn == 'Up':
			if a[j] in type2 and b[j] in type2:
				flowIn = 'Down'
			if a[j] in type2 and b[j] in type1:
				check = 'NO'
				break
		else:
			if a[j] in type2 and b[j] in type2:
				flowIn = 'Up'
			if a[j] in type1 and b[j] in type2:
				check = 'NO'
				break
	if check == 'YES':
		if flowIn == 'Up':
			if a[n - 1] in type1 or b[n - 1] in type1:
				check = 'NO'
		elif b[n - 1] in type2:
			check = 'NO'
	result = result + check + '\n'
print(result, end='')


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(input())
	l2 = list(input())
	s = 0
	for j in range(n):
		if (l1[j] == '4' or l1[j] == '3' or l1[j] == '5' or (l1[j] == '6')) and s == 0:
			s = 1
			if l2[j] == '1' or l2[j] == '2':
				print('NO')
				s = 4
				break
		elif (l2[j] == '4' or l2[j] == '3' or l2[j] == '5' or (l2[j] == '6')) and s == 1:
			s = 0
			if l1[j] == '1' or l1[j] == '2':
				print('NO')
				s = 4
				break
	if s == 1:
		print('YES')
	elif s == 0:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	x = False
	t = False
	chet = 0
	while chet != n:
		if not x:
			if s1[chet] in '3456':
				if t:
					t = False
					chet += 1
				else:
					t = True
					x = True
			elif t:
				x = False
				break
			else:
				chet += 1
		if x:
			if s2[chet] in '3456':
				if t:
					t = False
					chet += 1
				else:
					t = True
					x = False
			elif t:
				x = False
				break
			else:
				chet += 1
	if x:
		print('YES')
	else:
		print('NO')


import array
import math
import os
import sys

def main():
	Q = read_int()
	for _ in range(Q):
		N = read_int()
		A = inp()
		B = inp()
		print('YES' if solve(N, A, B) else 'NO')

def solve(N, A, B):
	w = 0
	for i in range(N):
		a = 1 if A[i] in ('1', '2') else 2
		b = 1 if B[i] in ('1', '2') else 2
		if w == 0:
			if a == 2 and b == 1:
				return False
			if a == 2:
				w = 1
		else:
			if b == 2 and a == 1:
				return False
			if b == 2:
				w = 0
	return w == 1
DEBUG = 'DEBUG' in os.environ

def inp():
	return sys.stdin.readline().rstrip()

def read_int():
	return int(inp())

def read_ints():
	return [int(e) for e in inp().split()]

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)
main()


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
d = defaultdict(int)
t = I()
for _ in range(t):
	n = I()
	s = input().strip()
	p = input().strip()
	p = list(p)
	s = list(s)
	for i in range(n):
		if s[i] == '2':
			s[i] = '1'
		if s[i] == '3' or s[i] == '4' or s[i] == '5' or (s[i] == '6'):
			s[i] = '2'
		if p[i] == '2':
			p[i] = '1'
		if p[i] == '3' or p[i] == '4' or p[i] == '5' or (p[i] == '6'):
			p[i] = '2'
	done = 0
	f = 0
	for i in range(n - 1):
		if f == 0 and s[i] != '1':
			if s[i] == p[i] and p[i] == '2':
				f = 1
			else:
				print('NO')
				done = 1
				break
		elif f == 1 and p[i] != '1':
			if s[i] == p[i] and p[i] == '2':
				f = 0
			else:
				print('NO')
				done = 1
				break
	if not done:
		if f == 0:
			if s[n - 1] == p[n - 1] and p[n - 1] == '2':
				print('YES')
			else:
				print('NO')
		if f == 1:
			if p[n - 1] == '1':
				print('YES')
			else:
				print('NO')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		s = [S() for _ in range(2)]
		t = [[int(c) for c in l] for l in s]
		ok = 1
		k = 0
		for i in range(n):
			if t[k][i] < 3:
				continue
			k ^= 1
			if t[k][i] < 3:
				ok = 0
				break
		rr.append(YES(ok and k == 1))
	return JA(rr, '\n')
print(main())


import os, sys
from io import BytesIO, IOBase
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil
mod = 10 ** 9 + 7
for _ in range(1):
	for q in range(int(input())):
		n = int(input())
		matrix = []
		matrix.append(input())
		matrix.append(input())
		i = 0
		j = 0
		at = 1
		first_time_1 = 0
		first_time_2 = 0
		found = 0
		while i <= 1 and j <= n - 1:
			if at == 1:
				if int(matrix[i][j]) <= 2:
					if first_time_1:
						break
					else:
						j += 1
				else:
					if first_time_1:
						j += 1
						first_time_1 = 0
					else:
						i += 1
						first_time_2 = 1
						at = 2
					if i == 1 and j == n - 1 and (int(matrix[i][j]) > 2):
						found = 1
						break
			elif int(matrix[i][j]) <= 2:
				if first_time_2:
					break
				else:
					if i == 1 and j == n - 1 and (int(matrix[i][j]) <= 2):
						found = 1
						break
					j += 1
					if i == 1 and j == n - 1 and (int(matrix[i][j]) <= 2):
						found = 1
						break
			elif first_time_2:
				first_time_2 = 0
				j += 1
			else:
				first_time_1 = 1
				i -= 1
				at = 1
		if found:
			print('YES')
		else:
			print('NO')


from typing import List
TOP = 0
BOTTOM = 1
STRAIGHT = 0
CURVED = 1

def pipes(n: int, pipes_system: List[List[int]]) -> bool:
	switch = []
	for i in range(n):
		if determine_pipe(pipes_system[TOP][i]) == CURVED and determine_pipe(pipes_system[BOTTOM][i]) == CURVED:
			switch.append(i)
	if len(switch) % 2 != 1:
		return False
	cur_row = TOP
	switch = set(switch)
	for i in range(n):
		if i in switch:
			cur_row = BOTTOM if cur_row == TOP else TOP
		elif determine_pipe(pipes_system[cur_row][i]) != STRAIGHT:
			return False
	return True

def determine_pipe(type: int) -> int:
	if 1 <= type <= 2:
		return STRAIGHT
	return CURVED

def test():
	assert pipes(7, [[2, 3, 2, 3, 2, 1, 6], [1, 6, 1, 5, 1, 2, 4]])
	assert pipes(1, [[3], [4]])
	assert pipes(2, [[1, 3], [2, 4]])
	assert not pipes(2, [[1, 2], [3, 4]])
	assert pipes(3, [[5, 3, 6], [3, 4, 5]])
	assert not pipes(2, [[4, 6], [5, 4]])
q = int(input())
for _ in range(q):
	n = int(input())
	first_row = [int(c) for c in input()]
	second_row = [int(c) for c in input()]
	result = pipes(n, [first_row, second_row])
	if result:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
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 os
import sys
from io import BytesIO, IOBase

def main():
	pass
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for xyz in range(0, int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	t1 = ['1', '2']
	t2 = ['3', '4', '5', '6']
	s = [s1, s2]
	cr = 0
	f = True
	for i in range(0, n + 1):
		if i == n:
			if cr == 1:
				print('YES')
			else:
				print('NO')
		elif s[cr][i] in t2:
			if s[cr ^ 1][i] in t2:
				cr ^= 1
			else:
				print('NO')
				break


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, sys.stdin.readline().split()))

def num():
	return map(int, sys.stdin.readline().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		n = nu()
		a = [0] * 2
		for i in range(2):
			op = input()
			a[i] = [0] * n
			for j in range(len(op)):
				a[i][j] = int(op[j])
		i = 0
		row = 0
		last = 0
		fl = True
		while i < n:
			op = a[row][i]
			if row == 0 and last == 0:
				if a[row][i] == 1 or a[row][i] == 2:
					i += 1
					continue
				if op == 4 or op == 5 or op == 3 or (op == 6):
					row = 1
					continue
				fl = False
				break
			if row == 1 and last == 0:
				if op == 4 or op == 5 or op == 3 or (op == 6):
					i += 1
					last = 1
					continue
				fl = False
				break
			if row == 1 and last == 1:
				if op == 1 or op == 2:
					i += 1
					continue
				if op == 4 or op == 5 or op == 3 or (op == 6):
					row = 0
					continue
				fl = False
				break
			if row == 0 and last == 1:
				if op == 4 or op == 5 or op == 3 or (op == 6):
					last = 0
					i += 1
					continue
				fl = False
				break
		if fl:
			if row == 1 and last == 1:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
solve()


for i in range(int(input())):
	n = int(input())
	A = list(input())
	B = list(input())
	j = 0
	k = 1
	while True:
		if k == 1:
			if A[j] in ['1', '2']:
				j += 1
			elif B[j] in ['3', '4', '5', '6']:
				k = 2
				j += 1
			else:
				print('NO')
				break
		elif B[j] in ['1', '2']:
			j += 1
		elif A[j] in ['3', '4', '5', '6']:
			k = 1
			j += 1
		else:
			print('NO')
			break
		if j == n and k == 2:
			print('YES')
			break
		elif j == n and k == 1:
			print('NO')
			break


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	swap = [1, 0]
	arr = []
	t = 0
	for i in range(2):
		arr.append(input())
	ans = True
	for i in range(n):
		if arr[t][i] != '1' and arr[t][i] != '2':
			t = swap[t]
			if arr[t][i] == '1' or arr[t][i] == '2':
				ans = False
				break
	print('YES' if ans and t == 1 else 'NO')


for _ in range(int(input())):
	n = int(input())
	m = [list(map(int, input().strip())) for _ in range(2)]
	i = 0
	for j in range(n):
		if m[i][j] > 2:
			if m[i ^ 1][j] < 3:
				print('NO')
				break
			else:
				i ^= 1
	else:
		print('YES' if i == 1 else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	path = []
	for i in range(2):
		path.append([int(p) for p in list(input())])
	for i in range(2):
		for j in range(n):
			if path[i][j] <= 2:
				path[i][j] = 0
			else:
				path[i][j] = 1
	(i, j) = (0, 0)
	ok = False
	while True:
		if i == 1 and j == n:
			ok = True
			break
		elif i > 1 or i < 0 or j < 0 or (j >= n):
			ok = False
			break
		pipe = path[i][j]
		if pipe == 0:
			j += 1
		elif i == 0:
			if path[i + 1][j] == 1:
				i += 1
				j += 1
			else:
				break
		elif path[i - 1][j] == 1:
			i -= 1
			j += 1
		else:
			break
	if ok:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	a = []
	a.append(input())
	a.append(input())
	t = False
	x = 0
	y = 0
	while True:
		if x == n:
			if y == 1:
				print('YES')
			else:
				print('NO')
			break
		if not t:
			if int(a[y][x]) < 3:
				x += 1
				continue
			t = True
			if y == 0:
				y = 1
			else:
				y = 0
		else:
			if int(a[y][x]) < 3:
				print('NO')
				break
			t = False
			x += 1


def is_bent(i):
	straight = 0
	bent = 1
	if int(i) < 3:
		return straight
	else:
		return bent

def case():
	n = int(input())
	pipes = [input(), input()]
	row = 0
	for pos in range(n):
		if is_bent(pipes[row][pos]):
			row ^= 1
			if not is_bent(pipes[row][pos]):
				print('NO')
				break
	else:
		if row:
			print('YES')
		else:
			print('NO')
for i in range(int(input())):
	case()


def A():
	import math
	q = eval(input())
	temp = []
	for i in range(q):
		n = eval(input())
		arr = list(map(int, input().split()))
		print(math.ceil(sum(arr) / float(n)))

def B():
	from collections import deque
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	q = deque(maxlen=k)
	for i in arr:
		if i not in q:
			q.append(i)
	print(len(q))
	for i in range(len(q)):
		print(q[len(q) - i - 1], end=' ')

def C():
	q = eval(input())
	for i in range(q):
		n = eval(input())
		arr = []
		arr.append(list(input()))
		arr.append(list(input()))
		(r, c) = (0, 0)
		up = 0
		check = 0
		while (c, r) != (1, n - 1):
			try:
				if arr[c][r] in '12' and up == 0:
					r += 1
					up = 0
				elif arr[c][r] in '12' and up == 1:
					print('NO')
					check = 1
					break
				elif arr[c][r] in '3456' and up == 0:
					c = (c + 1) % 2
					up = 1
				elif arr[c][r] in '3456' and up == 1:
					r += 1
					up = 0
			except IndexError:
				print('NO')
				check = 1
				break
		if check == 0:
			if arr[1][n - 1] in '12' and up == 0:
				print('YES')
			elif arr[1][n - 1] in '3456' and up == 1:
				print('YES')
			else:
				print('NO')
C()


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

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

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
q = getInt()
for _ in range(q):
	n = getInt()
	a1 = getStr()
	a2 = getStr()
	b1 = a1
	b2 = a2
	pos = 1
	res = 'YES'
	for i in range(n):
		if b1[i] >= '3':
			if b2[i] < '3':
				res = 'NO'
				break
			if pos == 1:
				pos = 2
				b1 = a2
				b2 = a1
			else:
				pos = 1
				b1 = a1
				b2 = a2
	if pos == 1:
		res = 'NO'
	print(res)


query = int(input())
for i in range(query):
	n = int(input())
	rows = [list(input()), list(input())]
	rowi = 0
	ans = True
	for k in range(n):
		if rows[rowi][k] >= '3':
			if rows[rowi - 1][k] <= '2':
				ans = False
				break
			else:
				rowi = (rowi - 1) % 2
	if rowi == 0:
		print('NO')
	else:
		print('YES' if ans else 'NO')


for q in range(int(input())):
	n = int(input())
	a = [list(map(int, input())), list(map(int, input()))]
	i = 0
	j = 0
	pos = 0
	while i < n:
		if pos == 0 and j == 0:
			if a[j][i] in (1, 2):
				i += 1
			else:
				pos = 1
				j += 1
		elif pos == 0 and j == 1:
			if a[j][i] in (1, 2):
				i += 1
			else:
				pos = 2
				j -= 1
		elif pos == 1 and j == 0:
			print('NO')
			break
		elif pos == 1 and j == 1:
			if a[j][i] in (1, 2):
				print('NO')
				break
			else:
				pos = 0
				i += 1
		elif pos == 2 and j == 1:
			print('NO')
			break
		elif pos == 2 and j == 0:
			if a[j][i] in (1, 2):
				print('NO')
				break
			else:
				pos = 0
				i += 1
	else:
		if j == 1 and pos == 0:
			print('YES')
		else:
			print('NO')


query = int(input())
for q in range(query):
	n = int(input())
	r0 = input()
	r1 = input()
	r0 = r0 + 'N'
	r1 = r1 + 'G'
	pipes = [r0, r1]
	current = pipes[0][0]
	dir = 0
	i = 0
	j = 0
	while i < 2 and j < n:
		if dir == 0:
			if current == '1' or current == '2':
				j += 1
				current = pipes[i][j]
			else:
				if i == 0:
					i += 1
					current = pipes[i][j]
				else:
					i -= 1
					current = pipes[i][j]
				dir = 1
		elif current == '1' or current == '2':
			break
		else:
			j += 1
			current = pipes[i][j]
			dir = 0
	if current == 'G':
		print('YES')
	else:
		print('NO')


def main():
	Q = int(input())
	for query in range(Q):
		N = int(input())
		A = [input() for i in range(2)]
		(h, w) = (0, 0)
		pre = -1
		pre_h = 0
		pre_d = 'w'
		while h != 1 or w != N:
			cur = A[h][w]
			cur_h = h
			if cur == '1' or cur == '2':
				if pre_d != 'w':
					break
				w += 1
			elif h == 0:
				if 3 <= int(pre) <= 6 and pre_h != cur_h:
					w += 1
					pre_d = 'w'
				else:
					h += 1
					pre_d = 'h'
			elif 3 <= int(pre) <= 6 and pre_h != cur_h:
				w += 1
				pre_d = 'w'
			else:
				h -= 1
				pre_d = 'h'
			if h < 0 or 1 < h or w < 0 or (N - 1 < w):
				break
			pre = cur
			pre_h = cur_h
		if h == 1 and w == N:
			print('YES')
		else:
			print('NO')
main()


q = int(input())
ang = lambda x: True if x in ('3', '4', '5', '6') else False
stt = lambda x: True if x in ('1', '2') else False
r = []
for _ in range(q):
	n = int(input())
	a = []
	a.append(input())
	a.append(input())
	l = 0
	p = 0
	while p < len(a[0]):
		if stt(a[l][p]):
			p += 1
			continue
		if ang(a[l][p]):
			if ang(a[1 - l][p]):
				l = 1 - l
			else:
				l = 0
				break
		p += 1
	if l == 1:
		r.append('YES')
	else:
		r.append('NO')
print('\n'.join(r))


testes = int(input())
for t in range(testes):
	canos = int(input())
	linha1 = str(input())
	linha2 = str(input())
	atual = 1
	livre = True
	for k in range(canos):
		if atual == 1:
			chave = linha1[k]
			if int(chave) > 2:
				atual = 2
				if int(linha2[k]) <= 2:
					livre = False
					break
		else:
			chave = linha2[k]
			if int(chave) > 2:
				atual = 1
				if int(linha1[k]) <= 2:
					livre = False
					break
	if livre and atual == 2:
		print('YES')
	else:
		print('NO')


import sys
sys.setrecursionlimit(10000000)

def input():
	return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
import itertools
import math
INF = 10 ** 9
MOD = 10 ** 9 + 7
q = int(input())
for j in range(q):
	n = int(input())
	a = [input() for i in range(2)]
	(i, h, flg) = (0, 0, 1)
	while i < n:
		if int(a[h][i]) < 3:
			i += 1
		else:
			h ^= 1
			if int(a[h][i]) < 3:
				flg = 0
				break
			else:
				i += 1
	if flg and h == 1:
		print('YES')
	else:
		print('NO')


from sys import stdin

def solve(n, p):
	RIGHT = 1
	LEFT = 2
	DOWN = 3
	UP = 4
	c = RIGHT
	(i, j) = (0, 0)
	ans = 'YES'
	while True:
		if j == n:
			if i != 1:
				ans = 'NO'
			break
		h = p[i][j]
		if h == 1 or h == 2:
			if c == RIGHT:
				j += 1
				continue
			ans = 'NO'
			break
		elif c == DOWN or c == UP:
			c = RIGHT
			j += 1
		elif c == RIGHT:
			if i == 0:
				c = DOWN
				i += 1
			else:
				c = UP
				i -= 1
		else:
			ans = 'NO'
			break
	print(ans)

def main():
	inp = stdin.readline
	for i in range(int(inp())):
		n = int(inp())
		h1 = list(inp().strip())
		h2 = list(inp().strip())
		m = list(map(int, h1))
		k = list(map(int, h2))
		p = [m, k]
		solve(n, p)
main()


q = int(input())
for _ in range(q):
	n = int(input())
	a = list()
	temp = list(input())
	a.append(temp)
	temp = list(input())
	a.append(temp)
	cur = 0
	done = False
	for i in range(n):
		if a[cur][i] not in ['1', '2']:
			cur = (cur + 1) % 2
			if a[cur][i] in ['1', '2']:
				print('NO')
				done = True
				break
		if done:
			break
	if done:
		continue
	if cur == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	pipes = [input() for _ in range(2)]
	(row, pos) = (0, 0)
	for pow in range(n):
		if pipes[row][pos] > '2':
			row = 1 - row
			if pipes[row][pos] < '3':
				break
		pos += 1
	print('YES' if row == 1 and pos == n else 'NO')


q = int(input())
for i in range(q):
	j = int(input())
	s = []
	s.append(input())
	s.append(input())
	row = 0
	end = False
	for k in range(j):
		if s[row][k] >= '3':
			if s[row ^ 1][k] < '3':
				break
			row = row ^ 1
	else:
		end = True
	if end and row == 1:
		print('YES')
	else:
		print('NO')


Q = int(input())
for q in range(Q):
	n = int(input())
	arr1 = [int(i) for i in input()]
	arr2 = [int(i) for i in input()]
	error = False
	now_x = 0
	now_y = 0
	was_x = -1
	while now_x < n:
		if now_y == 0:
			now = arr1[now_x]
		else:
			now = arr2[now_x]
		if True:
			if now in {1, 2}:
				if was_x == now_x:
					error = True
					break
				else:
					(was_x, now_x) = (now_x, now_x + 1)
			elif was_x == now_x:
				was_x = now_x
				now_x += 1
			else:
				was_x = now_x
				now_y = (now_y + 1) % 2
	if now_y == 0:
		error = True
	if error:
		print('NO')
	else:
		print('YES')


def Pipes():
	for query in range(int(input())):
		n = int(input())
		(Row1, Row2) = (input(), input())
		(meRow1, objRow1, objCol, answer) = (True, True, 0, 'YES')
		straights = set(['1', '2'])
		while True:
			if meRow1:
				if objRow1:
					if Row1[objCol] in straights:
						objCol += 1
						if objCol == n:
							if objRow1:
								answer = 'NO'
							break
					else:
						objRow1 = False
				elif Row2[objCol] in straights:
					answer = 'NO'
					break
				else:
					meRow1 = False
					objCol += 1
					if objCol == n:
						if objRow1:
							answer = 'NO'
						break
			elif objRow1:
				if Row1[objCol] in straights:
					answer = 'NO'
					break
				else:
					meRow1 = True
					objCol += 1
					if objCol == n:
						if objRow1:
							answer = 'NO'
						break
			elif Row2[objCol] in straights:
				objCol += 1
				if objCol == n:
					if objRow1:
						answer = 'NO'
					break
			else:
				objRow1 = True
		print(answer)
Pipes()


for _ in range(int(input())):
	(n, m) = (int(input()), [input(), input()])
	x = 0
	for i in range(n):
		if int(m[x][i]) > 2:
			x ^= 1
			if int(m[x][i]) <= 2:
				x = 0
				break
	print('NO') if x == 0 else print('YES')


for _ in range(int(input())):
	n = int(input())
	pipes = [[int(i) for i in input().strip()] for i in range(2)]
	(currenti, currentj) = (0, 0)
	maxIters = 0
	while True:
		if pipes[currenti][currentj] in [1, 2]:
			currentj += 1
		elif pipes[currenti][currentj] in [3, 4, 5, 6, 7] and pipes[(currenti + 1) % 2][currentj] in [3, 4, 5, 6, 7]:
			currenti += 1
			currenti %= 2
			currentj += 1
		maxIters += 1
		if currentj == n or maxIters > 2 * n + 1:
			break
	if currenti == 1 and currentj == n:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	ans = 0
	n = int(input())
	a = []
	a.append(str(input()))
	a.append(str(input()))
	(i, rch, cr) = (0, 0, 0)
	while i < n:
		if a[cr][i] == '1' or a[cr][i] == '2':
			if rch == 0:
				i += 1
			else:
				break
		elif rch == 0:
			rch = 1
			if cr == 0:
				cr = 1
			else:
				cr = 0
		else:
			rch = 0
			i += 1
	if i == n and cr == 1:
		print('YES')
		ans = 1
	if ans == 0:
		print('NO')
	t -= 1


N = int(input())
for i in range(N):
	n = int(input())
	str1 = list(input())
	str2 = list(input())
	x = False
	t = False
	chet = 0
	while chet != n:
		if not x:
			if str1[chet] in '3456':
				if t:
					t = False
					chet += 1
				else:
					t = True
					x = True
			elif t:
				x = False
				break
			else:
				chet += 1
		if x:
			if str2[chet] in '3456':
				if t:
					t = False
					chet += 1
				else:
					t = True
					x = False
			elif t:
				x = False
				break
			else:
				chet += 1
	if x:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	input()
	s = zip(input(), input())
	p = ('3', '4', '5', '6')
	r = 0
	for x in s:
		if x[r] in ('1', '2'):
			continue
		elif x[0] in p and x[1] in p:
			r = 1 - r
		else:
			r -= 1
			break
	if r == 1:
		print('YES')
	else:
		print('NO')


def test():
	i = j = 0
	from_left = True
	while i < n:
		pipe = G[j][i]
		if from_left:
			if pipe < 3:
				i += 1
			else:
				j = 1 - j
				from_left = False
		elif pipe < 3:
			return False
		else:
			i += 1
			from_left = True
	return j == 1
for _ in range(int(input())):
	n = int(input())
	G = [list(map(int, input())) for _ in '**']
	print(['NO', 'YES'][test()])


Q = int(input())
for _ in range(Q):
	N = int(input())
	P = [None, None]
	(*P[0],) = map(int, input())
	(*P[1],) = map(int, input())
	ok = 1
	c = 0
	for i in range(N):
		if P[c][i] <= 2:
			continue
		if P[c ^ 1][i] <= 2:
			ok = 0
			break
		c ^= 1
	if c == 0:
		ok = 0
	print('YES' if ok else 'NO')


q = int(input())
for i in range(q):
	input()
	c = zip(input(), input())
	pos = 0
	for i in c:
		if i[pos] in ('1', '2'):
			continue
		elif i[0] in ('3', '4', '5', '6') and i[1] in ('3', '4', '5', '6'):
			pos = 1 - pos
		else:
			pos = -1
			break
	if pos == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	path = []
	num = list(input())
	path.append(list(map(int, num)))
	num = list(input())
	path.append(list(map(int, num)))
	p = 0
	level = 0
	for i in range(n):
		if path[level][i] == 1 or path[level][i] == 2:
			pass
		elif path[level ^ 1][i] == 1 or path[level ^ 1][i] == 2:
			p = 1
			break
		else:
			level ^= 1
	if p:
		print('NO')
	elif level:
		print('YES')
	else:
		print('NO')


cases = int(input())
for i in range(cases):
	size = int(input())
	val = []
	val = [[int(x) for x in list(input())], [int(x) for x in list(input())]]
	down = 0
	no = 0
	for i in range(size):
		if val[down][i] > 2 and val[down ^ 1][i] <= 2:
			no = 1
			break
		if val[down][i] > 2:
			down ^= 1
	print('NO' if no == 1 or down == 0 else 'YES')


q = int(input())
for i in range(q):
	n = int(input())
	s1 = input()
	s2 = input()
	x = 1
	x1 = 1
	y = 0
	while True:
		if y == n - 1:
			if x == 1:
				if (s1[y] == '3' or s1[y] == '4' or s1[y] == '5' or (s1[y] == '6')) and (s2[y] == '3' or s2[y] == '4' or s2[y] == '5' or (s2[y] == '6')):
					print('YES')
					break
				else:
					print('NO')
					break
			elif s2[y] == '1' or s2[y] == '2':
				print('YES')
				break
			else:
				print('NO')
				break
		if x == 1:
			if s1[y] == '1' or s1[y] == '2':
				if x1 == 1:
					y += 1
				else:
					print('NO')
					break
			elif x1 == 1:
				x = 2
			else:
				y += 1
				x1 = 1
		elif s2[y] == '1' or s2[y] == '2':
			if x1 == 2:
				y += 1
			else:
				print('NO')
				break
		elif x1 == 2:
			x = 1
		else:
			y += 1
			x1 = 2


x = int(input())
for _ in range(x):
	s = int(input())
	a0 = input()
	a1 = input()
	z = [a0, a1]
	curr = 0
	ok = True
	for i in range(s):
		if z[curr][i] in ['1', '2']:
			pass
		elif z[1 - curr][i] in ['3', '4', '5', '6']:
			curr = 1 - curr
		else:
			ok = False
			break
	if curr == 0:
		ok = False
	if ok:
		print('YES')
	else:
		print('NO')


def process(A, B):
	n = len(A)
	M = [[], []]
	for i in range(n):
		if A[i] <= '2':
			M[0].append(0)
		else:
			M[0].append(1)
		if B[i] <= '2':
			M[1].append(0)
		else:
			M[1].append(1)
	path = [[0, 0]]
	while True:
		(x, y) = path[-1]
		if len(path) > 1:
			(x0, y0) = path[-2]
		if M[x][y] == 0:
			if len(path) > 1 and x0 != x:
				return 'NO'
			(x2, y2) = (x, y + 1)
		elif x == 0 and y == 0:
			(x2, y2) = (x + 1, y)
		else:
			(x0, y0) = path[-2]
			if y0 + 1 == y:
				(x2, y2) = (1 - x, y)
			else:
				(x2, y2) = (x, y + 1)
		if (x2, y2) == (1, n):
			return 'YES'
		if not (0 <= x2 <= 1 and 0 <= y2 <= n - 1):
			return 'NO'
		(x, y) = (x2, y2)
		path.append([x, y])
q = int(input())
for i in range(q):
	n = int(input())
	A = input()
	B = input()
	print(process(A, B))


x = int(input())
for __ in range(x):
	n = int(input())
	a = input()
	b = input()
	z = 'a'
	f = 0
	for i in range(n):
		if z == 'a':
			if a[i] == '3' or a[i] == '4' or a[i] == '5' or (a[i] == '6'):
				if b[i] == '3' or b[i] == '4' or b[i] == '5' or (b[i] == '6'):
					z = 'b'
				else:
					f = 1
					break
		elif z == 'b':
			if b[i] == '3' or b[i] == '4' or b[i] == '5' or (b[i] == '6'):
				if a[i] == '3' or a[i] == '4' or a[i] == '5' or (a[i] == '6'):
					z = 'a'
				else:
					f = 1
					break
	if z == 'b' and f == 0:
		print('YES')
	else:
		print('NO')


import sys
import collections
q = int(sys.stdin.readline())

def bfs():
	dy = [0, 1, -1]
	dx = [1, 0, 0]
	_q = collections.deque()
	_q.append([0, 0, 1, 0])
	visited[0][0] = 1
	while _q:
		(y, x, prev, prev_y) = _q.popleft()
		if y == 1 and x == n:
			break
		for i in range(3):
			ay = y + dy[i]
			ax = x + dx[i]
			if ay >= 0 and ay < 2 and (ax >= 0) and (ax < n + 2):
				if arr[y][x] == 1:
					if ay == y and ax == x + 1 and (visited[ay][ax] == 0) and (arr[ay][ax] != 0):
						visited[ay][ax] = visited[y][x] + 1
						_q.append([ay, ax, 1, prev_y])
				elif arr[y][x] == 3:
					if prev == 1:
						if y == 0:
							if ay == y + 1 and ax == x and (visited[ay][ax] == 0) and (arr[ay][ax] != 0) and (arr[ay][ax] != 1):
								visited[ay][ax] = visited[y][x] + 1
								_q.append([ay, ax, 3, y])
						elif y == 1:
							if ay == y - 1 and ax == x and (visited[ay][ax] == 0) and (arr[ay][ax] != 0) and (arr[ay][ax] != 1):
								visited[ay][ax] = visited[y][x] + 1
								_q.append([ay, ax, 3, y])
					elif prev == 3:
						if y == prev_y:
							if y == 0:
								if ay == y + 1 and ax == x and (visited[ay][ax] == 0) and (arr[ay][ax] != 0) and (arr[ay][ax] != 1):
									visited[ay][ax] = visited[y][x] + 1
									_q.append([ay, ax, 3, y])
							elif y == 1:
								if ay == y - 1 and ax == x and (visited[ay][ax] == 0) and (arr[ay][ax] != 0) and (arr[ay][ax] != 1):
									visited[ay][ax] = visited[y][x] + 1
									_q.append([ay, ax, 3, y])
						elif y != prev_y:
							if ay == y and ax == x + 1 and (visited[ay][ax] == 0) and (arr[ay][ax] != 0):
								visited[ay][ax] = visited[y][x] + 1
								_q.append([ay, ax, 3, y])
for _ in range(q):
	n = int(sys.stdin.readline())
	arr = []
	temp1 = list(sys.stdin.readline().strip()) + [0]
	for i in range(n):
		if temp1[i] == '2' or temp1[i] == '1':
			temp1[i] = 1
		if temp1[i] == '3' or temp1[i] == '4' or temp1[i] == '5' or (temp1[i] == '6'):
			temp1[i] = 3
	arr.append(temp1)
	temp2 = list(sys.stdin.readline().strip()) + [1]
	for j in range(n):
		if temp2[j] == '2' or temp2[j] == '1':
			temp2[j] = 1
		if temp2[j] == '3' or temp2[j] == '4' or temp2[j] == '5' or (temp2[j] == '6'):
			temp2[j] = 3
	arr.append(temp2)
	visited = [[0] * (n + 1) for _ in range(2)]
	bfs()
	if visited[1][n] != 0:
		print('YES')
	else:
		print('NO')


def is_water_flow_possible(n, top_pipe, bottom_pipe):
	in_flow = [0 for i in range(n)]
	out_flow = [0 for i in range(n)]
	in_flow[0] = 1
	for i in range(n):
		out_flow[i] = 0
		is_dbl_curve = is_double_curve(top_pipe[i], bottom_pipe[i])
		if is_bottom_inflow(in_flow[i]) and is_dbl_curve or (is_top_inflow(in_flow[i]) and is_straight(top_pipe[i])):
			out_flow[i] += 1
		if is_top_inflow(in_flow[i]) and is_dbl_curve or (is_bottom_inflow(in_flow[i]) and is_straight(bottom_pipe[i])):
			out_flow[i] += 2
		if i < n - 1:
			in_flow[i + 1] = out_flow[i]
	return is_bottom_inflow(out_flow[n - 1])

def is_double_curve(flow1, flow2):
	return is_curve(flow1) and is_curve(flow2)

def is_curve(pipe_num):
	return pipe_num in ['3', '4', '5', '6']

def is_straight(pipe_num):
	return pipe_num in ['1', '2']

def is_top_inflow(flow):
	return flow in [1, 3]

def is_bottom_inflow(flow):
	return flow in [2, 3]

def solve():
	queries_number = int(input())
	for k in range(queries_number):
		n = int(input())
		row1 = input()
		row2 = input()
		print('YES' if is_water_flow_possible(n, str(row1), str(row2)) else 'NO')
solve()


def isValid(i, j, N):
	if i < 0 or i > 1 or j < 0 or (j > N - 1):
		return False
	return True
for _ in range(int(input())):
	N = int(input())
	Top = input()
	Bottom = input()
	I = 0
	J = 0
	if Top[0] <= '2':
		i = 0
		j = 1
	else:
		i = 1
		j = 0
	flag = 0
	while True:
		if i == 0 and j == N:
			flag = 1
			break
		if i == 1 and j == N:
			break
		if i == 0:
			if Top[j] <= '2':
				if I == 0:
					j += 1
					J += 1
				else:
					flag = 1
					break
			elif I == 0:
				i += 1
				J += 1
			else:
				j += 1
				I -= 1
		elif Bottom[j] <= '2':
			if I == 1:
				j += 1
				J += 1
			else:
				flag = 1
				break
		elif I == 1:
			i -= 1
			J += 1
		else:
			j += 1
			I += 1
	if flag:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	a = list(a)
	a = [int(j) for j in a]
	b = input()
	b = list(b)
	b = [int(j) for j in b]
	ans = 0
	ansno = 0
	for i in range(n):
		if ans % 2 == 0:
			if (a[i] == 3 or a[i] == 4 or a[i] == 5 or (a[i] == 6)) and (b[i] == 1 or b[i] == 2):
				ansno += 1
			elif (a[i] == 3 or a[i] == 4 or a[i] == 5 or (a[i] == 6)) and (b[i] == 3 or b[i] == 4 or b[i] == 5 or (b[i] == 6)):
				ans += 1
		elif (b[i] == 3 or b[i] == 4 or b[i] == 5 or (b[i] == 6)) and (a[i] == 1 or a[i] == 2):
			ansno += 1
		elif (b[i] == 3 or b[i] == 4 or b[i] == 5 or (b[i] == 6)) and (a[i] == 3 or a[i] == 4 or a[i] == 5 or (a[i] == 6)):
			ans += 1
	if ansno == 0 and ans % 2 == 1:
		print('YES')
	else:
		print('NO')


from math import *
t = int(input())
for y in range(t):
	n = int(input())
	l1 = list(input())
	l2 = list(input())
	s = 0
	for i in range(n):
		if s == 0:
			if l1[i] == '1' or l1[i] == '2':
				s = 0
			elif l2[i] == '3' or l2[i] == '4' or l2[i] == '5' or (l2[i] == '6'):
				s = 1
			else:
				s = 0
				break
		elif l2[i] == '1' or l2[i] == '2':
			s = 1
		elif l1[i] == '3' or l1[i] == '4' or l1[i] == '5' or (l1[i] == '6'):
			s = 0
		else:
			s = 0
			break
	if s == 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def solve(n, f, s):
	directions = [f, s]
	reach = [[False] * n for _ in range(2)]
	reach[0][0] = True
	(row, col) = (0, 0)
	for _ in range(n):
		if directions[row][col] in '12':
			col += 1
		elif directions[row][col] in '3456':
			if directions[(row + 1) % 2][col] in '3456':
				row += 1
				row %= 2
				col += 1
			else:
				return False
	return row == 1
q = int(input())
for _ in range(q):
	n = int(input())
	f = input().rstrip()
	s = input().rstrip()
	if solve(n, f, s):
		print('YES')
	else:
		print('NO')


entrada = int(input())
for k in range(entrada):
	n = int(input())
	string1 = input()
	string2 = input()
	flag = True
	i = 0
	flagstring = 1
	flagTroca = False
	while i < n:
		if flagstring == 1:
			if string1[i] == '1' or string1[i] == '2':
				i += 1
			elif string2[i] != '3' and string2[i] != '4' and (string2[i] != '5') and (string2[i] != '6'):
				flag = False
				break
			elif flagTroca:
				i += 1
				flagTroca = False
			else:
				flagstring = 2
				flagTroca = True
		elif string2[i] == '1' or string2[i] == '2':
			i += 1
		elif string1[i] != '3' and string1[i] != '4' and (string1[i] != '5') and (string1[i] != '6'):
			flag = False
			break
		elif flagTroca:
			i += 1
			flagTroca = False
		else:
			flagstring = 1
			flagTroca = True
	if not flag:
		print('NO')
	elif flagstring == 1:
		print('NO')
	else:
		print('YES')


import math
import sys
from collections import defaultdict, Counter, deque
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]
from itertools import accumulate, groupby
dp = []
for _ in range(int(input())):
	N = int(input())
	A = input()
	B = input()
	pos = 0
	f = 0
	for i in range(-1, N - 1):
		if pos == 0:
			if A[i + 1] == '1' or A[i + 1] == '2':
				pos = 0
			elif B[i + 1] != '1' and B[i + 1] != '2':
				pos = 1
			else:
				f = 1
				break
		elif B[i + 1] == '1' or B[i + 1] == '2':
			pos = 1
		elif A[i + 1] != '1' and A[i + 1] != '2':
			pos = 0
		else:
			f = 1
			break
	if f == 1 or pos == 0:
		print('NO')
	else:
		print('YES')


elem = int(input())
for x in range(elem):
	elem2 = int(input())
	one = input()
	two = input()
	curr = 0
	check = 0
	for y in range(elem2):
		if curr == 0:
			if one[y] == '1' or one[y] == '2':
				continue
			elif two[y] == '3' or two[y] == '4' or two[y] == '5' or (two[y] == '6'):
				curr = 1
			else:
				check = 1
				break
		elif two[y] == '1' or two[y] == '2':
			continue
		elif one[y] == '3' or one[y] == '4' or one[y] == '5' or (one[y] == '6'):
			curr = 0
		else:
			check = 1
			break
	if check == 1:
		print('NO')
	elif curr == 0:
		print('NO')
	else:
		print('YES')


a = int(input())
for i in range(a):
	s = int(input())
	a1 = input()
	a2 = input()
	k1 = []
	k2 = []
	for i in range(len(a1)):
		k1.append(str(a1[i]))
		k2.append(str(a2[i]))
	for i in range(len(a1)):
		if a1[i] == '1' or a1[i] == '2':
			k1[i] = 'L'
		else:
			k1[i] = 'LD'
		if a2[i] == '1' or a2[i] == '2':
			k2[i] = 'L'
		else:
			k2[i] = 'LU'
	cell = [0, 0]
	flow = 0
	flag = 0
	while cell[0] < s:
		r = cell[0]
		y = cell[1]
		if cell[1] == 0:
			if k1[r] == 'L' and flow == 0:
				cell[0] += 1
				continue
			elif flow == 1 and k1[r] == 'LD':
				cell[0] += 1
				flow = 0
				cell[1] = 0
				continue
			elif flow == 0 and k1[r] == 'LD':
				flow = 2
				cell[1] = 1
				continue
			else:
				flag = 1
				break
		if cell[1] == 1:
			if flow == 0 and k2[r] == 'L':
				cell[0] += 1
				continue
			elif flow == 0 and k2[r] == 'LU':
				cell[1] = 0
				flow = 1
				continue
			elif flow == 2 and k2[r] == 'LU':
				flow = 0
				cell[0] += 1
				cell[1] = 1
				continue
			else:
				flag = 1
				break
	if flow == 0 and cell[1] == 1 and (flag == 0):
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	s1 = '2'.join('2'.join('2'.join('2'.join('1'.join(input().split('2')).split('3')).split('4')).split('5')).split('6'))
	s2 = '2'.join('2'.join('2'.join('2'.join('1'.join(input().split('2')).split('3')).split('4')).split('5')).split('6'))
	a = 1
	for j in range(n):
		if a == 1:
			if s1[j] == s2[j] == '2':
				a = 2
			elif s1[j] == '2' and s2[j] == '1':
				a = 0
		elif s2[j] == s1[j] == '2':
			a = 1
		elif s2[j] == '2' and s1[j] == '1':
			a = 0
		if a == 0:
			break
	if a == 2:
		print('YES')
	else:
		print('NO')


import sys
q = int(sys.stdin.readline())
for i in range(q):
	n = sys.stdin.readline()
	l1 = sys.stdin.readline().strip()
	r1 = sys.stdin.readline().strip()
	up = True
	dir = 'r'
	idx = 0
	while True:
		if idx == len(l1):
			if not up:
				print('YES')
			else:
				print('NO')
			break
		cl = int(l1[idx])
		cr = int(r1[idx])
		if up:
			if dir == 'r':
				if cl <= 2:
					idx += 1
					continue
				dir = 'd'
				up = False
			else:
				assert dir == 'u'
				if cl <= 2:
					print('NO')
					break
				dir = 'r'
				idx += 1
		else:
			assert not up
			if dir == 'r':
				if cr <= 2:
					idx += 1
				else:
					dir = 'u'
					up = True
			else:
				assert dir == 'd'
				if cr <= 2:
					print('NO')
					break
				dir = 'r'
				idx += 1


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	l = [s1, s2]
	cur = 0
	flag = 1
	i = 0
	for _ in range(n):
		if l[cur][i] >= '3':
			if l[1 - cur][i] < '3':
				break
			else:
				cur = 1 - cur
		i += 1
	if i == n and cur == 1:
		print('Yes')
	else:
		print('No')


q = int(input())
ans = [True for i in range(q)]
for i in range(q):
	n = int(input())
	r = [0, 0]
	r[0] = input()
	r[1] = input()
	k = 0
	for j in range(n):
		if int(r[0][j]) > 2 and int(r[1][j]) > 2:
			k = 1 - k
		if int(r[k][j]) > 2 and int(r[1 - k][j]) < 3:
			ans[i] = False
	if k == 0:
		ans[i] = False
for i in range(q):
	if ans[i] == True:
		print('YES')
	else:
		print('NO')


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()
for _ in range(inp()):
	n = inp()
	s = [inpsl(n) for _ in range(2)]
	nx = 0
	for i in range(n):
		now = int(s[nx][i])
		if now > 2:
			nx = 1 - nx
			if int(s[nx][i]) <= 2:
				print('NO')
				break
	else:
		print('YES' if nx else 'NO')


dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
dreverse = {0: 2, 1: 3, 2: 0, 3: 1}
tile1_from_to = {3: 1}
r0_tile2_from_to = {3: 2, 2: 1}
r1_tile2_from_to = {0: 1, 3: 0}
from_to = {0: {1: tile1_from_to, 2: tile1_from_to, 3: r0_tile2_from_to, 4: r0_tile2_from_to, 5: r0_tile2_from_to, 6: r0_tile2_from_to}, 1: {1: tile1_from_to, 2: tile1_from_to, 3: r1_tile2_from_to, 4: r1_tile2_from_to, 5: r1_tile2_from_to, 6: r1_tile2_from_to}}
q = int(input())
for _ in range(q):
	n = int(input())
	r1 = list(map(int, list(input())))
	r2 = list(map(int, list(input())))
	a = [r1, r2]
	(px, py) = (0, -1)
	d_to = 1
	d_from = dreverse[d_to]
	solved = False
	while True:
		px += dx[d_to]
		py += dy[d_to]
		if px == 1 and py == n:
			solved = True
			break
		if px < 0 or px > 1 or py < 0 or (py >= n):
			break
		tile = a[px][py]
		if d_from in from_to[px][tile]:
			d_to = from_to[px][tile][d_from]
		else:
			break
		d_from = dreverse[d_to]
	print('YES' if solved else 'NO')


import sys, atexit
from io import BytesIO
inp = BytesIO(sys.stdin.buffer.read())
input = lambda : inp.readline().decode('ascii')
buf = BytesIO()
atexit.register(lambda : sys.__stdout__.buffer.write(buf.getvalue()))

def f(s):
	out = ''
	for i in s:
		if i == '1' or i == '2':
			out += '1'
		else:
			out += '3'
	return out
for i in range(int(input())):
	n = int(input())
	p = []
	x = input().strip()
	p.append(f(x))
	x = input().strip()
	p.append(f(x))
	r = c = 0
	t = True
	try:
		while not (r == 1 and c == n):
			if p[r][c] == '1':
				c += 1
			elif p[1 - r][c] == '3' and p[r][c] == '3':
				r = 1 - r
				c += 1
			else:
				t = False
				break
	except:
		print('NO')
		continue
	if t:
		print('YES')
	else:
		print('NO')


t = 1
t = int(input())
while t:
	t -= 1
	n = int(input())
	rows = []
	rows.append(input())
	rows.append(input())
	dp = [[0, 0] for _ in range(n + 1)]
	dp[0][0] = 1
	for i in range(1, n + 1):
		if rows[0][i - 1] in ('1', '2'):
			dp[i][0] = dp[i - 1][0]
		if rows[1][i - 1] in ('1', '2'):
			dp[i][1] = dp[i - 1][1]
		rot = ['3', '4', '5', '6']
		if rows[0][i - 1] in rot and rows[1][i - 1] in rot:
			dp[i][0] = dp[i - 1][1]
			dp[i][1] = dp[i - 1][0]
	print('YES' if dp[-1][1] else 'NO')


q = int(input())
for i in range(q):
	n = int(input())
	s1 = input()
	s2 = input()
	y = 1
	j = 0
	c = 0
	while j < n - 1 and c == 0:
		if 2 < int(s1[j]) < 7 and 2 < int(s2[j]) < 7:
			j += 1
			y = 1 - y
		elif y == 0 and 0 < int(s2[j]) < 3:
			j += 1
		elif y == 1 and 0 < int(s1[j]) < 3:
			j += 1
		else:
			c = 1
	if c == 0:
		if y == 0 and 0 < int(s2[n - 1]) < 3:
			c = 0
		elif y == 1 and 2 < int(s1[n - 1]) < 7 and (2 < int(s2[n - 1]) < 7):
			c = 0
		else:
			c = 1
	if c == 0:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	n = get_int()
	s = []
	s.append(input())
	s.append(input())
	check = 0
	for i in range(n):
		if s[check][i] >= '3':
			if s[check ^ 1][i] >= '3':
				check ^= 1
			else:
				return 'NO'
	if check == 1:
		return 'YES'
	else:
		return 'NO'

def main():
	print(solve())
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


t = int(input())
for k in range(t):
	ans = 0
	n = int(input())
	arr = []
	arr.append(str(input().strip()))
	arr.append(str(input().strip()))
	(i, rch, cr) = (0, 0, 0)
	while i < n:
		if arr[cr][i] == '1' or arr[cr][i] == '2':
			if rch == 0:
				i += 1
			else:
				break
		elif rch == 0:
			rch = 1
			if cr == 0:
				cr = 1
			else:
				cr = 0
		else:
			rch = 0
			i += 1
	if i == n and cr == 1:
		print('YES')
		ans = 1
	if ans == 0:
		print('NO')


import math
import bisect
from functools import reduce
from collections import defaultdict

def inn():
	return int(input())

def inl():
	return list(map(int, input().split()))
MOD = 10 ** 9 + 7
INF = inf = 10 ** 18 + 5
for t in range(inn()):
	n = inn()
	a1 = list(map(int, list(input())))
	a2 = list(map(int, list(input())))
	for i in range(n):
		if a1[i] == 1 or a1[i] == 2:
			a1[i] = 0
		else:
			a1[i] = 1
		if a2[i] == 1 or a2[i] == 2:
			a2[i] = 0
		else:
			a2[i] = 1
	f = 0
	for i in range(n):
		if a1[i] == 1 and a2[i] == 1:
			f = max(0, 1 - f)
		elif f == 0 and a1[i] or (f and a2[i]):
			f = 0
			break
	if f:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
from collections import deque

def ip():
	return [int(i) for i in stdin.readline().split()]

def sp():
	return [str(i) for i in stdin.readline().split()]

def pp(A):
	for i in A:
		print(i)

def solve():
	n = int(input())
	A = []
	r0 = list(str(input()))
	r1 = list(str(input()))
	A.append(r0)
	A.append(r1)
	(i, j) = (0, 0)
	t = False
	while j != n and i < 2:
		p = A[i][j]
		if i == 0:
			if p == '1' or p == '2':
				if t:
					return 'NO'
				j += 1
				t = False
			elif t:
				j += 1
				t = False
			else:
				i += 1
				t = True
		elif p == '1' or p == '2':
			if t:
				return 'NO'
			j += 1
			t = False
		elif t:
			j += 1
			t = False
		else:
			i -= 1
			t = True
	if i == 1 and j == n:
		return 'YES'
	else:
		return 'NO'
t = int(input())
for i in range(t):
	print(solve())


n = int(input())
for i in range(n):
	a = int(input())
	b = [[0] * a] * 2
	b[0] = list(input())
	b[1] = list(input())
	t = 0
	f = 0
	for j in range(a):
		if b[t][j] in '12':
			continue
		elif b[t][j] in '3456':
			if b[(t + 1) % 2][j] in '3456':
				t = (t + 1) % 2
			else:
				f = 1
				break
	if f == 1:
		print('No')
	elif t == 1:
		print('Yes')
	else:
		print('No')


q = int(input())
t1 = set({'1', '2'})
t2 = set({'3', '4', '5', '6'})
for i in range(q):
	c = int(input())
	a = [list(input())]
	a += [list(input())]
	row = 0
	exit = False
	for j in range(c):
		if a[row][j] in t2:
			if a[1 - row][j] in t2:
				row = 1 - row
			else:
				exit = True
				break
		if exit:
			break
	if exit or row == 0:
		print('NO')
	else:
		print('YES')


q = int(input())
for i in range(q):
	n = int(input())
	s1 = input()
	s2 = input()
	m1 = []
	m2 = []
	for j in range(n):
		m1.append(1 if int(s1[j]) < 3 else 2)
		m2.append(1 if int(s2[j]) < 3 else 2)
	m = [m1, m2]
	x = 0
	y = 0
	while 1:
		if m[y][x] == 1:
			x += 1
			if x == n:
				if y == 1:
					print('YES')
				else:
					print('NO')
				break
		else:
			y = (y + 1) % 2
			if m[y][x] == 2:
				x += 1
				if x == n:
					if y == 1:
						print('YES')
					else:
						print('NO')
					break
			else:
				print('NO')
				break


import os, sys
from io import BytesIO, IOBase

def solve(ls, n):
	curr = 1
	x = [0, 0]
	while x[0] <= 1 and x[1] < n:
		if ls[x[0]][x[1]] in '12':
			if curr == 1:
				x[1] += 1
			else:
				return 'NO'
		else:
			curr ^= 1
			if curr == 1:
				x[1] += 1
			else:
				x[0] ^= 1
	if x == [1, n]:
		return 'YES'
	return 'NO'

def main():
	for _ in range(int(input())):
		n = int(input())
		ls = [input().strip() for _ in range(2)]
		print(solve(ls, n))
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
import sys
q = int(input())
for _ in range(q):
	n = int(input())
	a = []
	for i in range(2):
		f = list(str(input()))
		for j in range(n):
			if f[j] == '1' or f[j] == '2':
				f[j] = 1
			else:
				f[j] = 0
		a.append(f)
	x = 0
	y = 0
	direction = 0
	vector = [[1, 0], [0, -1], [0, 1]]
	step = 0
	while True:
		if x == n or step > 2 * n or y not in [0, 1]:
			break
		step += 1
		if a[y][x] == 1:
			pass
		elif direction == 0:
			if y == 0:
				direction = 2
			else:
				direction = 1
		else:
			direction = 0
		x += vector[direction][0]
		y += vector[direction][1]
	if x == n and y == 1:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	a = list(input())
	b = list(input())
	k = True
	j = 0
	while True:
		if j == n:
			if k:
				print('NO')
				break
			else:
				print('YES')
				break
		if k:
			if int(a[j]) < 3:
				j += 1
			elif int(b[j]) > 2:
				j += 1
				k = False
			else:
				print('NO')
				break
		elif int(b[j]) < 3:
			j += 1
		elif int(a[j]) > 2:
			j += 1
			k = True
		else:
			print('NO')
			break


q = int(input())
for r in range(q):
	n = int(input())
	rows = [[0 if int(c) <= 2 else 1 for c in input()]]
	rows.append([0 if int(c) <= 2 else 1 for c in input()])
	switch = 0
	row = 0
	i = 0
	while i < n - 1:
		if rows[row][i]:
			if switch:
				switch = 0
				i += 1
			else:
				switch = 1
				row = 1 if row == 0 else 0
		elif switch:
			print('NO')
			break
		else:
			i += 1
	else:
		if row == 1 and (not rows[row][i]) or (row == 0 and rows[row][i] and rows[1][i]):
			print('YES')
		else:
			print('NO')


t = int(input())

def change(y):
	if y == 0:
		return 1
	return 0
for _ in range(t):
	n = int(input())
	p1 = list(map(int, input()))
	p2 = list(map(int, input()))
	pipes = [p1, p2]
	(x, y) = (0, 0)
	ans = True
	while x < n:
		if pipes[y][x] < 3:
			x += 1
		else:
			y = change(y)
			if pipes[y][x] < 3:
				break
			else:
				x += 1
	if x == n and y == 1:
		print('Yes')
	else:
		print('No')


q = int(input())
for i in range(q):
	n = int(input())
	s = [input() for i in range(2)]
	i = 0
	j = 0
	ans = ['YES', 'NO']
	while i < n:
		if s[j][i] != '1' and s[j][i] != '2':
			j ^= 1
			if s[j][i] == '1' or s[j][i] == '2':
				ans[0] = ans[1]
				break
		i += 1
	if i != n or j != 1:
		ans[0] = ans[1]
	print(ans[0])


for t in range(int(input())):
	n = int(input())
	tubes = [input(), input()]
	i = 0
	error = False
	for j in range(n):
		if tubes[i][j] >= '3':
			if tubes[i ^ 1][j] < '3':
				error = True
				break
			else:
				i ^= 1
	if not error and i == 1:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	a = [input(), input()]
	i = 0
	flag = True
	for k in range(n):
		if a[i][k] >= '3':
			if a[i - 1][k] <= '2':
				flag = False
				break
			else:
				i = (i - 1) % 2
	print('YES' if flag and i else 'NO')


q = int(input())
for _ in range(q):
	n = int(input())
	tube = [[int(c) for c in input()] for j in range(2)]
	cnt = 0
	b = False
	for i in range(n):
		if tube[0][i] <= 2 and cnt % 2 == 0:
			continue
		if tube[1][i] <= 2 and cnt % 2 == 1:
			continue
		if tube[0][i] > 2 and tube[1][i] > 2:
			cnt += 1
		else:
			b = True
			break
	if b or cnt % 2 == 0:
		print('NO')
	else:
		print('YES')


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

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

def si():
	return stdin.readline()
ans = ['YES', 'NO']
for _ in range(ii()):
	f = d = p = 0
	n = ii()
	a = list(si())
	b = list(si())
	a = list(zip(a, b))
	i = 0
	while i < n:
		x = int(a[i][p])
		if d and x < 3:
			f = 1
			break
		elif x > 2:
			d = 1 - d
			if d:
				i -= 1
				p = 1 - p
		i += 1
	if not p:
		f = 1
	print(ans[f])


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = stdin.readline()[:-1]
	b = stdin.readline()[:-1]
	(y, result) = (1, 'YES')
	for (i, x) in enumerate(a):
		if y == 2:
			x = b[i]
		if '2' < x < '7':
			if y == 1:
				if '2' < b[i] < '7':
					y = 2
				else:
					result = 'NO'
					break
			elif '2' < a[i] < '7':
				y = 1
			else:
				result = 'NO'
				break
	if y == 2:
		print(result)
	else:
		print('NO')


import sys
ntc = int(sys.stdin.readline().rstrip())
for _ in range(ntc):
	n = int(sys.stdin.readline().rstrip())
	board = list()
	board.append(list(map(int, list(sys.stdin.readline().rstrip()))))
	board.append(list(map(int, list(sys.stdin.readline().rstrip()))))
	if n == 1:
		if board[0][0] >= 3 and board[0][0] <= 6 and (board[1][0] >= 3) and (board[1][0] <= 6):
			print('YES')
		else:
			print('NO')
	else:
		x = 0
		y = 0
		priv_x = 0
		priv_y = 0
		if board[0][0] >= 1 and board[0][0] <= 2:
			y = 1
		else:
			x = 1
		while True:
			if x < 0 or y < 0 or x >= 2 or (y >= n):
				print('NO')
				break
			if x == 1 and y == n - 1:
				dx = x - priv_x
				dy = y - priv_y
				if dx == 0 and dy == 1:
					if board[x][y] >= 1 and board[x][y] <= 2:
						print('YES')
						break
					else:
						print('NO')
						break
				if dx == 1 and dy == 0:
					if board[x][y] >= 3 and board[x][y] <= 6:
						print('YES')
						break
					else:
						print('NO')
						break
			if board[x][y] >= 1 and board[x][y] <= 2:
				dx = x - priv_x
				dy = y - priv_y
				priv_x = x
				priv_y = y
				x += dx
				y += dy
			else:
				dx = x - priv_x
				dy = y - priv_y
				priv_x = x
				priv_y = y
				if dx == 1 and dy == 0:
					y += 1
				elif dx == 0 and dy == 1:
					if x == 0:
						x += 1
					else:
						x -= 1
				elif dx == -1 and dy == 0:
					y += 1


t = [[['h', 'v'], ['e', 'h']], [['h', 'v'], ['e', 'h']]]

def solve():
	a = []
	n = int(input())
	for i in range(2):
		a.append([0] * n)
	for i in range(2):
		string = input()
		for j in range(n):
			a[i][j] = int(string[j])
	r = 0
	c = 0
	p = 0
	m = 0
	answer = 'NO'
	for i in range(2 * n):
		p = a[r][c]
		if p >= 3:
			p = 1
		else:
			p = 0
		next_m = t[r][m][p]
		if next_m == 'h':
			c += 1
		elif next_m == 'v':
			r = (r + 1) % 2
		else:
			break
		if r == 1 and c == n:
			answer = 'YES'
			break
		if c == n:
			break
		if next_m == 'h':
			m = 0
		else:
			m = 1
	print(answer)
q = int(input())
for i in range(q):
	solve()


q = int(input())
for _ in range(q):
	n = int(input())
	lin1 = input()
	lin2 = input()
	tub = [[], []]
	for c in lin1:
		if c == '1' or c == '2':
			tub[0].append(0)
		else:
			tub[0].append(1)
	for c in lin2:
		if c == '1' or c == '2':
			tub[1].append(0)
		else:
			tub[1].append(1)
	if tub[0][0] == 0:
		posx = 1
		posy = 0
	elif tub[1][0] == 0:
		posx = 0
		posy = 2
	else:
		posx = 1
		posy = 1
	for i in range(2 * n):
		if posx == n and posy == 1:
			print('YES')
			break
		if posx == n and posy != 1:
			print('NO')
			break
		if posy > 1 or posy < 0:
			print('NO')
			break
		if tub[posy][posx] == 0:
			posx += 1
		elif tub[posy][posx] == 1:
			if posy == 0:
				if tub[1][posx] == 1:
					posx += 1
					posy = 1
				else:
					print('NO')
					break
			elif posy == 1:
				if tub[0][posx] == 1:
					posx += 1
					posy = 0
				else:
					print('NO')
					break


import math
testcase = int(input())
for case in range(testcase):
	a = int(input())
	m = []
	for _ in range(2):
		m.append(list(input()))
	p = 0
	q = 0
	state = 'p'
	while True:
		if m[q][p] == '1' or m[q][p] == '2':
			if state == 'p':
				p += 1
			else:
				q = 999
				break
		elif state == 'p':
			if q == 1:
				q -= 1
				state = 'q'
			else:
				q += 1
				state = 'q'
		else:
			p += 1
			state = 'p'
		if p >= a:
			break
	if q == 1:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	arr1 = list(map(int, input()))
	arr2 = list(map(int, input()))
	p = 0
	q = 0
	r = 0
	arr = [arr1, arr2]
	i = 0
	while i < n:
		if p == 0 and arr[q][i] in [3, 4, 5, 6]:
			q = int(not q)
			p = 1
		elif p == 0 and arr[q][i] in [1, 2]:
			p = 0
			i += 1
		elif arr[q][i] in [1, 2]:
			r = 1
			print('NO')
			break
		else:
			p = 0
			i += 1
	i = i - 1
	if i == n - 1 and q == 0:
		print('NO')
	elif r == 0:
		print('YES')


import math
from decimal import Decimal
import heapq
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def Factor(n):
	Ans = []
	d = 2
	while d * d <= n:
		if n % d == 0:
			Ans.append(d)
			n //= d
		else:
			d += 1
	if n > 1:
		Ans.append(n)
	return Ans
q = int(input())
for _ in range(q):
	n = int(input())
	a = []
	s1 = input()
	s2 = input()
	a = [s1, s2]
	j = 0
	tc = 'YES'
	for i in range(n):
		if a[j][i] in '12':
			continue
		elif a[j ^ 1][i] not in '12':
			j ^= 1
		else:
			tc = 'NO'
			break
	if j == 0:
		tc = 'NO'
	print(tc)


def solve(row1, row2, ans):
	n = len(row1)
	row = 1
	for i in range(n):
		if row == 1:
			if row1[i] not in ['1', '2']:
				if row2[i] not in ['1', '2']:
					row = 2
				else:
					ans.append('NO')
					return
		elif row2[i] not in ['1', '2']:
			if row1[i] not in ['1', '2']:
				row = 1
			else:
				ans.append('NO')
				return
	if row == 2:
		ans.append('YES')
		return
	ans.append('NO')

def main():
	ans = []
	q = int(input())
	for i in range(q):
		n = int(input())
		row1 = input()
		row2 = input()
		solve(row1, row2, ans)
	for i in ans:
		print(i)
main()


q = int(input())
D = {'1': 0, '2': 0, '3': 1, '4': 1, '5': 1, '6': 1}
for _ in range(q):
	n = int(input())
	A = [[True] + [False] * n, [False] + [False] * n]
	B = [[D[x] for x in input()], [D[x] for x in input()]]
	for i in range(1, n + 1):
		for j in [0, 1]:
			A[j][i] = A[1 - j][i - 1] and B[0][i - 1] and B[1][i - 1] or (A[j][i - 1] and (not B[j][i - 1]))
	print('YES' if A[1][n] else 'NO')


def preprocess(string: str) -> str:
	for r in ('1', '2'):
		string = string.replace(r, '1')
	for r in ('3', '4', '5', '6'):
		string = string.replace(r, '2')
	return string
for _ in range(int(input())):
	input()
	s1 = preprocess(input())
	s2 = preprocess(input())
	line = 0
	exit_flag = False
	for c in zip(s1, s2):
		current_tube = c[line]
		if current_tube == '1':
			pass
		elif current_tube == '2':
			if c[1 - line] == '2':
				line = 1 - line
			else:
				print('NO')
				exit_flag = True
		if exit_flag:
			break
	if not exit_flag:
		if line == 1:
			print('YES')
		else:
			print('NO')


import sys

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		n = int(sys.stdin.readline())
		a = list(sys.stdin.readline())
		b = list(sys.stdin.readline())
		chk = False
		for i in range(n):
			if chk is False:
				if int(a[i]) > 2:
					if int(b[i]) <= 2:
						chk = False
						break
					chk = not chk
			elif int(b[i]) > 2:
				if int(a[i]) <= 2:
					chk = False
					break
				chk = not chk
		print('YES') if chk is True else print('NO')
main()


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	l = [input(), input()]
	c = [0, 0]
	k = 0
	for i in range(2 * n):
		x = l[c[0]][c[1]]
		if x == '1' or x == '2':
			if k:
				c = [0, 0]
				break
			c[1] += 1
			k = 0
		elif x in '3456':
			k += 1
			if k == 2:
				c[1] += 1
				k = 0
			else:
				c[0] = (c[0] + 1) % 2
		if c == [1, n]:
			break
	print('YNEOS'[c != [1, n]::2])


def switch(x, y):
	x = int(x)
	y = int(y)
	return x in range(3, 7) and y in range(3, 7)

def parse(top, bottom):
	t = True
	x = 0
	i = 0
	while i < len(top):
		if t:
			if top[i] not in ('1', '2'):
				if switch(top[i], bottom[i]):
					t = False
					x += 1
				else:
					return False
		elif bottom[i] not in ('1', '2'):
			if switch(top[i], bottom[i]):
				t = True
				x += 1
			else:
				return False
		i += 1
	return not t and x % 2 == 1
n = int(input())
for _ in range(n):
	input()
	top = input()
	bottom = input()
	print('YES' if parse(top, bottom) else 'NO')


for case in range(int(input())):
	n = int(input())
	r = [[], [], []]
	for i in range(1, 3):
		r[i] = [-1] + list(map(int, list(input())))
		for j in range(1, n + 1):
			if 1 <= r[i][j] and r[i][j] <= 2:
				r[i][j] = 0
			elif 3 <= r[i][j] and r[i][j] <= 6:
				r[i][j] = 1
	q = [('L', 1, 1)]
	flag = False
	while len(q):
		j = q.pop(0)
		if j[1] == 2 and j[2] == n + 1:
			flag = True
			break
		if j[2] > n:
			continue
		if j[0] == 'L':
			if r[j[1]][j[2]] == 0:
				q.append(('L', j[1], j[2] + 1))
			elif r[j[1]][j[2]] == 1:
				if j[1] == 1:
					q.append(('U', 2, j[2]))
				elif j[1] == 2:
					q.append(('D', 1, j[2]))
		elif j[0] == 'U' or j[0] == 'D':
			if r[j[1]][j[2]] == 1:
				q.append(('L', j[1], j[2] + 1))
	print('YES' if flag else 'NO')


q = int(input())
for i in range(q):
	n = int(input())
	l1 = input()
	l2 = input()
	s1 = {'1', '2'}
	s2 = {'3', '4', '5', '6'}
	p = 0
	m = 0
	for z in range(n):
		if m % 2 == 1 and l2[z] in s2 and (l1[z] in s1):
			print('NO')
			p += 1
			break
		elif m % 2 == 0 and l1[z] in s2 and (l2[z] in s1):
			print('NO')
			p += 1
			break
		elif l1[z] in s2 and l2[z] in s2:
			m += 1
	if m % 2 != 0 and p != 1:
		print('YES')
	elif p != 1:
		print('NO')


queries = int(input())
d = {'1': 1, '2': 1, '3': 2, '4': 2, '5': 2, '6': 2}
for q in range(queries):
	n = int(input())
	r = [[d[i] for i in input()], [d[i] for i in input()]]
	j = n - 1
	i = 1
	prev = -1
	while True:
		if r[i][j] == 1:
			j -= 1
			prev = 1
		elif prev == 2:
			j -= 1
			prev = 1
		else:
			i = i ^ 1
			prev = 2
			if r[i][j] == 1:
				print('NO')
				break
		if j == -1:
			if i == 0:
				print('YES')
			else:
				print('NO')
			break


q = int(input())
for i in range(q):
	n = int(input())
	layer_1 = list(map(int, input()))
	layer_2 = list(map(int, input()))
	x = 0
	y = 0
	dir = 0
	while True:
		if y == 0:
			if layer_1[x] in [1, 2]:
				if dir == 1:
					print('NO')
					break
				elif x == n - 1:
					print('NO')
					break
				else:
					x = x + 1
			elif dir == 0:
				dir = 1
				y = 1
			else:
				dir = 0
				if x == n - 1:
					print('NO')
					break
				else:
					x = x + 1
		elif layer_2[x] in [1, 2]:
			if dir == 1:
				print('NO')
				break
			elif x == n - 1:
				print('YES')
				break
			else:
				x = x + 1
		elif dir == 0:
			dir = 1
			y = 0
		else:
			dir = 0
			if x == n - 1:
				print('YES')
				break
			else:
				x = x + 1


q = int(input())

def solve():
	n = int(input())
	a = input()
	b = input()
	x = 0
	y = 0
	fromX = True
	while (y == 0 or y == 1) and x < n:
		if y == 0:
			if not fromX and a[x] in ['1', '2']:
				return 'NO'
			elif fromX and a[x] in ['1', '2']:
				x += 1
			elif fromX:
				y += 1
				fromX = False
			else:
				x += 1
				fromX = True
		elif not fromX and b[x] in ['1', '2']:
			return 'NO'
		elif fromX and b[x] in ['1', '2']:
			x += 1
		elif fromX:
			y -= 1
			fromX = False
		else:
			x += 1
			fromX = True
	if x == n and y == 1:
		return 'YES'
	else:
		return 'NO'
for _ in range(q):
	print(solve())


import sys
input = sys.stdin.readline
q = int(input())
for testcases in range(q):
	n = int(input())
	MAP = [list(map(int, list(input().strip()))) for i in range(2)]
	X = 0
	Y = 0
	fr = 0
	while True:
		if X == n and Y == 1:
			print('YES')
			break
		if X == n:
			print('NO')
			break
		if MAP[Y][X] <= 2:
			if fr == 0:
				fr = 0
				X += 1
			else:
				print('NO')
				break
		elif fr == 0:
			fr = 1
			Y += 1
			Y %= 2
		else:
			X += 1
			fr = 0