Monocarp is playing a computer game. Now he wants to complete the first level of this game.

A level is a rectangular grid of $2$ rows and $n$ columns. Monocarp controls a character, which starts in cell $(1, 1)$ — at the intersection of the $1$-st row and the $1$-st column.

Monocarp's character can move from one cell to another in one step if the cells are adjacent by side and/or corner. Formally, it is possible to move from cell $(x_1, y_1)$ to cell $(x_2, y_2)$ in one step if $|x_1 - x_2| \le 1$ and $|y_1 - y_2| \le 1$. Obviously, it is prohibited to go outside the grid.

There are traps in some cells. If Monocarp's character finds himself in such a cell, he dies, and the game ends.

To complete a level, Monocarp's character should reach cell $(2, n)$ — at the intersection of row $2$ and column $n$.

Help Monocarp determine if it is possible to complete the level.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. Then the test cases follow. Each test case consists of three lines.

The first line contains a single integer $n$ ($3 \le n \le 100$) — the number of columns.

The next two lines describe the level. The $i$-th of these lines describes the $i$-th line of the level — the line consists of the characters '0' and '1'. The character '0' corresponds to a safe cell, the character '1' corresponds to a trap cell.

Additional constraint on the input: cells $(1, 1)$ and $(2, n)$ are safe.


-----Output-----

For each test case, output YES if it is possible to complete the level, and NO otherwise.


-----Examples-----

Input
4
3
000
000
4
0011
1100
4
0111
1110
6
010101
101010
Output
YES
YES
NO
YES


-----Note-----

Consider the example from the statement.

In the first test case, one of the possible paths is $(1, 1) \rightarrow (2, 2) \rightarrow (2, 3)$.

In the second test case, one of the possible paths is $(1, 1) \rightarrow (1, 2) \rightarrow (2, 3) \rightarrow (2, 4)$.

In the fourth test case, one of the possible paths is $(1, 1) \rightarrow (2, 2) \rightarrow (1, 3) \rightarrow (2, 4) \rightarrow (1, 5) \rightarrow (2, 6)$.

Difficulty: EASY
Tags: Dynamic programming

Graph traversal

Implementation

Complete search
Skill types: Dynamic programming

Complete search

Starter code:

Solutions:
t = int(input())
n = []
str1 = []
str2 = []
for i in range(t):
	n.append(int(input()))
	str1.append(list(input()))
	str2.append(list(input()))
for i in range(t):
	possibility = 'NO'
	for j in range(n[i] - 2):
		if str2[i][j + 1] == '1' and str1[i][j + 1] == '1':
			possibility = 'NO'
			break
		else:
			possibility = 'YES'
	print(possibility)


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	t = str(input())
	fl = True
	for i in range(n):
		if int(s[i]) * int(t[i]) == 1:
			fl = False
			break
	if fl:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	s1 = str(input())
	s2 = str(input())
	flag = True
	for x in range(n - 1):
		if s1[x + 1] == '1' and s2[x + 1] == '1':
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


N = int(input())
for i in range(N):
	n = int(input())
	a1 = str(input())
	a2 = str(input())
	k = 0
	for j in range(n):
		if a1[j] == '1' and a2[j] == '1':
			print('NO')
			k = 1
			break
	if k == 0:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	row1 = list(map(int, list(input())))
	row2 = list(map(int, list(input())))
	safe = True
	for i in range(n):
		if row1[i] and row2[i]:
			safe = False
			break
	if safe:
		print('YES')
	else:
		print('NO')


from __future__ import division, print_function
from collections import defaultdict, deque
import heapq
import os
import copy
import sys
from io import BytesIO, IOBase
from typing import Counter, DefaultDict, Deque, OrderedDict
import bisect, math, time
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
from math import ceil, log2
MOD = 1000000007

def power(x, y):
	if y == 0:
		return 1
	if x == 0:
		return 0
	temp = power(x, y // 2)
	if y % 2 == 0:
		return temp * temp % MOD
	else:
		return x * temp * temp % MOD

def solve(i, j, grid, visit):
	n = len(grid[0])
	if i > 1 or i < 0 or j > n - 1 or (j < 0) or (grid[i][j] == '1') or ((i, j) in visit):
		return False
	if i == 1 and j == n - 1:
		return True
	visit.add((i, j))
	return solve(i + 1, j, grid, visit) or solve(i, j + 1, grid, visit) or solve(i + 1, j + 1, grid, visit) or solve(i - 1, j + 1, grid, visit)

def main():
	t = int(input())
	while t:
		n = int(input())
		r1 = str(input())
		r2 = str(input())
		grid = []
		grid.append(r1)
		grid.append(r2)
		visit = set()
		if solve(0, 0, grid, visit):
			print('YES')
		else:
			print('NO')
		t -= 1
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	(n, s) = (int(input()), 'YES')
	for (i, j) in zip(input(), input()):
		if i == j == '1':
			s = 'NO'
			break
	print(s)


t = int(input())
while t != 0:
	n = int(input())
	s1 = input()
	s2 = input()
	flag = 0
	for i in range(n):
		if s1[i] == '1' and s2[i] == '1':
			flag = 1
	if flag == 1:
		print('NO')
	else:
		print('YES')
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	r1 = input()
	r1 = list(r1)
	r2 = input()
	r2 = list(r2)
	flag = 0
	for i in range(n):
		if r1[i] == '1' and r2[i] == '1':
			flag = 1
	if flag == 0:
		print('YES')
	else:
		print('NO')


import sys

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

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

def input():
	return sys.stdin.readline().strip()
MOD = 1000000007
for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	f = 1
	for i in range(n):
		if a[i] == b[i] and a[i] == '1':
			print('NO')
			f = 0
			break
	if f:
		print('YES')
	else:
		continue


z = int(input())
for _ in range(z):
	n = int(input())
	s = zip(input(), input())
	if ('1', '1') in s:
		print('NO')
	else:
		print('YES')


import math
for i in range(int(input())):
	n = int(input())
	r1 = input()
	r2 = input()
	d = 0
	if set(r1) == {'0'} and set(r2) == {'0'}:
		print('YES')
	else:
		for k in range(1, n):
			if r1[k] == '1' and r2[k] == '1':
				print('NO')
				d = 1
				break
		if d == 0:
			print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = [[], []]
	a[0] = input()
	a[1] = input()
	ans = 'YES'
	for i in range(1, n):
		if a[0][i] == a[1][i] == '1':
			ans = 'NO'
			break
	print(ans)


for i in range(int(input())):
	n = int(input())
	t = True
	a = input()
	b = input()
	for i in range(n):
		if a[i] != '0' and b[i] != '0':
			t = False
			break
	if t == False:
		print('NO')
	else:
		print('YES')


import sys, os.path
if os.path.exists('inp.txt'):
	sys.stdin = open('inp.txt', 'r')
	sys.stdout = open('out.txt', 'w')

def solve(n, first, second):
	for i in range(n):
		if first[i] == second[i] == '1':
			return 'NO'
	return 'YES'
t = int(input())
for i in range(t):
	n = int(input())
	first = input()
	second = input()
	print(solve(n, first, second))


t = int(input())
otv = []
for j in range(t):
	n = int(input())
	l = True
	a1 = str(input())
	a2 = str(input())
	for i in range(n):
		if a1[i] == a2[i] and a1[i] == '1':
			l = False
			break
	if l == True:
		otv.append('YES')
	else:
		otv.append('NO')
for i in range(t):
	print(otv[i])


I = input
exec(int(I()) * "I();print('YNEOS'[int(I(),2)&int(I(),2)>0::2]);")


a = int(input())
for i in range(a):
	L = []
	b = int(input())
	for j in range(2):
		c = input()
		L.append(c)
	for i in range(len(L[0])):
		if L[0][i] == '1' and L[1][i] == '1':
			print('NO')
			break
	else:
		print('YES')


t = int(input())
from collections import deque
for caseNr in range(1, t + 1):
	n = int(input())
	row1 = input()
	row2 = input()
	matrix = [[] for _ in range(2)]
	matrix[0] = [int(row1[i]) for i in range(len(row1))]
	matrix[1] = [int(row2[i]) for i in range(len(row2))]
	queue = deque([(0, 0)])
	visited = set()
	dirs = [[1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [-1, 1], [1, -1], [-1, -1]]

	def find_neighbours(cur):
		res = []
		for dir1 in dirs:
			if 0 <= cur[0] + dir1[0] <= 1 and 0 <= cur[1] + dir1[1] <= len(matrix[0]) - 1 and (matrix[cur[0] + dir1[0]][cur[1] + dir1[1]] != 1):
				res.append([cur[0] + dir1[0], cur[1] + dir1[1]])
		return res
	ans = 'NO'
	while queue:
		cur = queue.popleft()
		if cur[0] == 1 and cur[1] == len(matrix[1]) - 1:
			ans = 'YES'
			break
		for neighbour in find_neighbours(cur):
			if tuple(neighbour) not in visited:
				visited.add(tuple(neighbour))
				queue.append(tuple(neighbour))
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	mat = []
	for j in range(2):
		row = str(input())
		mat.append(list(row))
	suc = 1
	for j in range(n):
		if mat[0][j] == '1' and mat[1][j] == '1':
			print('NO')
			suc = 0
			break
	if suc == 1:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	arr = [[], []]
	a = list(input())
	tmp = list(input())
	arr[0] = list(a.copy())
	arr[1] = list(tmp.copy())
	flag = True
	for i in range(2):
		for j in range(n - 1):
			if arr[i][j] != '1':
				if i == 0:
					if arr[i][j + 1] == '1' and arr[i + 1][j + 1] == '1':
						flag = False
						break
				elif arr[i][j + 1] == '1' and arr[i - 1][j + 1] == '1':
					flag = False
					break
	if flag == True:
		print('YES')
	else:
		print('NO')


tc = int(input())
for i in range(tc):
	n = int(input())
	f = input()
	s = input()
	i = 0
	play = True
	start = f
	temp = s
	while i < n and play:
		if start[i] == '0':
			i += 1
		else:
			p = start
			start = temp
			if start[i] != '0':
				print('NO')
				play = False
			temp = p
	if play:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	r1 = input()
	r2 = input()
	ans = 'YES'
	for i in range(n):
		if r1[i] == '1' == r2[i]:
			ans = 'NO'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	first = input()
	second = input()
	for i in range(n):
		if first[i] == second[i] == '1':
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	z = False
	for x in range(n):
		if a[x] == '1' and b[x] == '1':
			print('NO')
			z = True
			break
	if z:
		continue
	print('YES')


t = int(input())
columns = []
x = []
y = []
for i in range(t):
	columns.append(int(input()))
	x.append(input())
	y.append(input())
for i in range(t):
	acc = True
	for j in range(columns[i]):
		if x[i][j] == '1' and x[i][j] == y[i][j]:
			acc = False
	if acc:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = []
	for x in range(2):
		arr.append(input())
	flag = 0
	for i in range(len(arr[0])):
		if int(arr[0][i]) + int(arr[1][i]) == 2:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


def dfsSimilar():
	N = 100 + 10
	t = int(input())
	(dx, dy) = ((0, 1, 0, -1, -1, 1, -1, 1), (1, 0, -1, 0, 1, 1, -1, -1))

	def dfs(x, y):
		vs[x][y] = True
		for d in range(8):
			(nx, ny) = (x + dx[d], y + dy[d])
			if 0 <= nx < 2 and 0 <= ny < c and (grid[nx][ny] == '0') and (not vs[nx][ny]):
				dfs(nx, ny)
	for _ in range(t):
		c = int(input())
		(grid, vs) = ([], [[False] * c for _ in range(2)])
		for __ in range(2):
			grid.append(list(input()))
		dfs(0, 0)
		print('YES' if vs[1][c - 1] else 'NO')

def smart():
	t = int(input())
	for _ in range(t):
		g = []
		col = int(input())
		for __ in range(2):
			g.append(list(input()))
		flag = True
		for check_c in range(col):
			if g[0][check_c] == '1' and g[1][check_c] == '1':
				flag = False
				break
		print('YES' if flag else 'NO')
smart()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	t = input()
	good = True
	for x in range(n):
		for y in [x]:
			if 0 <= y < n:
				if s[x] == '1' and t[y] == '1':
					good = False
					break
	if good:
		print('YES')
	else:
		print('NO')


a = int(input())
for _ in range(a):
	b = int(input())
	x = input()
	y = input()
	c = 0
	for i in range(b - 1):
		if x[i] == x[i + 1] == '0' or y[i] == y[i + 1] == '0' or x[i] == y[i + 1] == '0' or (y[i] == x[i + 1] == '0'):
			c += 1
		else:
			break
	if c == b - 1:
		print('YES')
	else:
		print('NO')


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = stdin.readline().strip()
	b = stdin.readline().strip()
	res = 'YES'
	for i in range(n):
		if a[i] == b[i] == '1':
			res = 'NO'
			break
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	for j in range(n):
		if a[j] == '1' and b[j] == '1':
			print('NO')
			break
	else:
		print('YES')


testcases = input()
testcases = int(testcases)
for caseNr in range(1, testcases + 1):
	n = int(input())
	line1 = input()
	line2 = input()
	check = True
	for i in range(n - 1):
		if line1[i] == line2[i] and line1[i] == '1':
			check = False
	if check == False:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	n = int(input())
	l = str(input())
	m = str(input())
	k = []
	for j in range(n):
		if l[j] == '0' and m[j] == '1':
			k.append(0)
		elif l[j] == '1' and m[j] == '0':
			k.append(0)
		elif l[j] == '0' and m[j] == '0':
			k.append(0)
		else:
			k.append(1)
	if all((ele == 0 for ele in k)):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	column = int(input())
	row1 = input()
	row2 = input()
	count = 0
	for i in range(column):
		if row1[i] == row2[i] and row1[i] == '1':
			count += 1
			print('NO')
			break
	if count == 0:
		print('YES')


for i in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	for i in range(1, n - 1):
		if s1[i] == s2[i] == '1':
			print('NO')
			break
	else:
		print('YES')


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]
INF = 10 ** 10
YES = 'YES'
NO = 'NO'

def solve(N, A):
	for i in range(N):
		if A[0][i] == '1' and A[1][i] == '1':
			return 'NO'
	if A[1][N - 1] == '1':
		return 'NO'
	return 'YES'
T0 = int(input())
for _ in range(T0):
	N = int(input())
	A = [input() for _ in range(2)]
	print(solve(N, A))


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	res = []
	cnt = 0
	(res1, res2) = ([], [])
	for i in range(len(s1)):
		res1.append(s1[i])
	for i in range(len(s2)):
		res2.append(s2[i])
	res.append(res1)
	res.append(res2)
	for i in range(n):
		if res[0][i] == '0' or res[1][i] == '0':
			cnt += 1
	if cnt == n:
		print('YES')
	else:
		print('NO')


def main():
	alpha = 'abcdefghijklmnopqrstuvwxyz'
	ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	inf = 1e+17
	mod = 10 ** 9 + 7

	def factorial(n):
		f = 1
		for i in range(1, n + 1):
			f = f * i % mod
		return f

	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 isthere(s, ind, c):
		for i in range(ind, len(s), ind + 1):
			if s[i] != c:
				return False
		return True

	def solve(n, r1, r2):
		for i in range(n):
			if r1[i] == r2[i] == '1':
				return 'NO'
		return 'YES'
	t = int(input())
	ans = []
	for _ in range(t):
		n = int(input())
		r1 = list(input()[:-1])
		r2 = list(input()[:-1])
		ans.append(solve(n, r1, r2))
	p = 1
	for answer in ans:
		print(answer)
		p += 1
import sys, threading
import bisect
import math
import itertools
from sys import stdout
import heapq
from queue import PriorityQueue
from collections import deque
input = sys.stdin.readline
thread = threading.Thread(target=main)
thread.start()
thread.join()


t = int(input())
for i in range(t):
	n = int(input())
	array1 = list(map(int, list(input())))
	array2 = list(map(int, list(input())))
	flag = True
	for i in range(n - 1):
		if array1[i] + array2[i] == 2:
			print('NO')
			flag = False
			break
	if flag:
		print('YES')


for _ in range(int(input())):
	s = 0
	a = int(input())
	b = input()
	c = input()
	for i in range(a):
		if b[i] == '0':
			continue
		elif c[i] == '0':
			continue
		else:
			s += 1
			break
	if s == 0:
		print('YES')
	else:
		print('NO')


def solve(arr, n):
	for i in range(n):
		if arr[i] == (1, 1):
			return 'NO'
	return 'YES'
for i in range(int(input())):
	n = int(input())
	arr = []
	p1 = [int(x) for x in input()]
	p2 = [int(x) for x in input()]
	arr = list(zip(p1, p2))
	print(solve(arr, n))


import math

def compute_f():
	t = int(input())
	columns = []
	fst = []
	snd = []
	for i in range(t):
		column = int(input())
		columns.append(column)
		f = str(input())
		fst.append(f)
		s = str(input())
		snd.append(s)
	for i in range(t):
		possible = True
		for j in range(columns[i]):
			if (fst[i][j] == '1') & (fst[i][j] == snd[i][j]):
				possible = False
		if possible:
			print('YES')
		else:
			print('NO')
compute_f()


N = int(input())
for _ in range(N):
	C = int(input())
	L = list()
	L.append(input())
	L.append(input())
	flag = 0
	for i in range(C - 1):
		if L[0][i + 1] == '1' and L[1][i + 1] == '1':
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	if int(s1, 2) & int(s2, 2):
		print('No')
	else:
		print('YES')


t = int(input())
while t != 0:
	n = int(input())
	l = []
	for i in range(2):
		a = input()
		l1 = [str(i) for i in a]
		l.append(l1)
	flag = 'NO'
	for i in range(1, n):
		if l[0][i] == '0' or l[1][i] == '0':
			flag = 'YES'
		else:
			flag = 'NO'
			break
	print(flag)
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	ok = True
	for i in range(n):
		if a[i] == '1' and b[i] == '1':
			ok = False
			break
	if ok:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	a = int(input())
	b = input()
	c = input()
	try:
		for i in range(a + 1):
			if '1' == b[i] == c[i]:
				print('NO')
				break
	except:
		print('YES')


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	s = input()
	s = str(s)
	p = input()
	p = str(p)
	f = 0
	for j in range(0, n):
		if s[j] == '1' and p[j] == '1':
			f = 1
			print('NO')
			break
	if f == 0:
		print('YES')


from sys import stdin, stdout, setrecursionlimit
from io import BytesIO, IOBase
setrecursionlimit(10000)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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
		self.BUFSIZE = 8192

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

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

	def flush(self):
		if self.writable:
			self.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')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
input = lambda : stdin.readline().rstrip('\r\n')
inp = lambda : int(input())
st = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
int_arr = lambda : list(map(int, input().strip().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().strip().split())
get_int = lambda : map(int, input().strip().split())
get_float = lambda : map(float, input().strip().split())
mod = 1000000007
for _ in range(inp()):
	n = inp()
	a = st()
	b = st()
	f = 0
	for i in range(n):
		if a[i] == '1' and b[i] == '1':
			print('NO')
			f = 1
			break
	if f == 0:
		print('YES')


import math
for i in range(int(input())):
	t = int(input())
	s1 = input()
	s2 = input()
	d = False
	for i in range(t):
		d |= s1[i] == '1' and s2[i] == '1'
	if d:
		print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	answer = 'YES'
	n = int(input())
	first = input()
	second = input()
	for j in range(1, n - 1):
		if first[j] == '1' and second[j] == '1':
			answer = 'NO'
			break
	print(answer)


k = int(input())
while k > 0:
	n = int(input())
	sus = input()
	jos = input()
	x = 0
	y = 0
	raspuns = 0
	posibil = 1
	while posibil == 1 and x + 1 < n and (raspuns == 0):
		if sus[x + 1] == '1' and jos[x + 1] == '1':
			posibil = 0
		elif jos[x + 1] == '0':
			x = x + 1
		elif sus[x + 1] == '0':
			x = x + 1
		if x == n - 1 and jos[x] == '0':
			raspuns = 1
	if raspuns == 1:
		print('YES')
	else:
		print('NO')
	k = k - 1


def main():
	for _ in range(int(input())):
		n = int(input())
		s1 = input()
		s2 = input()
		ans = True
		for l in range(n):
			if s1[l] == '1' and s2[l] == '1':
				ans = False
		print('YES') if ans else print('NO')
main()


def main():
	n = int(input(''))
	arr = []
	for i in range(2):
		arr.append(list(input()))
	for i in range(n):
		if arr[0][i] == '1' and arr[1][i] == '1':
			print('NO')
			return
	print('YES')
t = int(input(''))
for i in range(t):
	main()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	s = st()
	s1 = st()
	fl = 0
	cur = 0
	s2 = 'YES'
	for i in range(len(s)):
		if s[i] == '1' and s1[i] == '1':
			fl = 1
			s2 = 'NO'
	print(s2)


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(2):
		x = input()
		b = []
		for j in x:
			b.append(j)
		a.append(b)
	t = True
	for i in range(n):
		da = False
		for j in range(2):
			if a[j][i] == '0':
				da = True
		if da == False:
			print('NO')
			t = False
			break
	if t:
		print('YES')


rond = eval(input())
for ru in range(rond):
	a = eval(input())
	p = 'YES'
	s = input()
	t = input()
	m = []
	n = []
	for i in s:
		m.append(i)
	for i in t:
		n.append(i)
	for i in range(0, a - 1):
		if m[i] == '0' and m[i + 1] == '1' and (n[i + 1] == '1'):
			p = 'NO'
		if n[i] == '0' and n[i + 1] == '1' and (m[i + 1] == '1'):
			p = 'NO'
	print(p)


import sys
input = sys.stdin.readline
for _ in range(int(input().strip())):
	n = int(input().strip())
	s = input().strip()
	s1 = input().strip()
	for (i, j) in zip(s, s1):
		if i == j == '1':
			print('NO')
			break
	else:
		print('YES')


import math
t = int(input())
while t:
	n = int(input())
	s1 = input()
	s2 = input()
	a = []
	b = []
	flag = 0
	for i in range(n):
		if s1[i] == '1' and s2[i] == '1':
			flag = 1
	if flag:
		print('NO')
	else:
		print('YES')
	t -= 1


t = int(input())
while t != 0:
	ans = False
	n = int(input())
	s1 = input()
	s2 = input()
	for i in range(n):
		if s1[i] != '1' or s2[i] != '1':
			continue
		ans = True
		break
	if ans:
		print('NO', '\n')
	else:
		print('YES', '\n')
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = [list(map(int, input().replace('', ' ').split())) for i in range(2)]
	fl = True
	for i in range(n):
		if a[0][i] == 1 and a[1][i] == 1:
			fl = False
			break
	if fl:
		print('YES')
	else:
		print('NO')


def solve(n, a, b):
	return 'YES' if all((not a[i] or not b[i] for i in range(n))) else 'NO'
t = int(input())
for i_t in range(t):
	n = int(input())
	a = list(map(int, input()))
	b = list(map(int, input()))
	print(solve(n, a, b))


def solve():
	n = int(input())
	s1 = input()
	s2 = input()
	for (c1, c2) in zip(s1, s2):
		if c1 == c2 == '1':
			print('NO')
			return
	print('YES')
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	r1 = input()
	r2 = input()
	if r2[n - 1] == '0':
		for i in range(n):
			if r2[i] == r1[i] == '1':
				print('NO')
				break
			elif i == n - 1:
				print('YES')
	else:
		print('NO')


t = int(input())
for q in range(0, t):
	n = int(input())
	a = input()
	b = input()
	check = True
	for i in range(0, n):
		if i == 0:
			if b[i] == '0':
				if i + 1 < n:
					if b[i + 1] == '0':
						check = True
					elif a[i + 1] == '0':
						check = True
					else:
						check = False
						break
			elif i + 1 < n and a[i + 1] == '0':
				check = True
			elif i + 1 < n and b[i + 1] == '0':
				check = True
			else:
				check = False
				break
		elif i + 1 < n:
			if a[i + 1] == '0' or b[i + 1] == '0':
				check = True
			else:
				check = False
				break
	if check:
		print('YES')
	else:
		print('NO')


test_cases = int(input())
for i in range(test_cases):
	columns = int(input())
	row1 = list(map(int, [char for char in input()]))
	row2 = list(map(int, [char for char in input()]))
	isPossible = True
	for c in range(columns):
		if row1[c] == row2[c] == 1:
			isPossible = False
			break
	if isPossible:
		print('YES')
	else:
		print('NO')


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


from __future__ import division, print_function
import os
import sys
from fileinput import input
from io import BytesIO, IOBase
import math
mod = 1000000007
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():

	def solve():
		n = int(input())
		s1 = input()
		s2 = input()
		ans = 0
		for i in range(n):
			ans += int(s1[i]) & int(s2[i])
		if not ans:
			return 'YES'
		return 'NO'
	t = int(input())
	for i in range(t):
		print(solve())
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
while n > 0:
	n1 = int(input())
	s = str(input())
	s1 = str(input())
	d = []
	d1 = []
	for i in s:
		d += [i]
	for j in s1:
		d1 += [j]
	ans = 'YES'
	for i in range(n1):
		if int(d[i]) == 1 and int(d1[i]) == 1:
			ans = 'NO'
			break
	if d1[n1 - 1] == '1':
		ans = 'NO'
	print(ans)
	n -= 1


for _ in range(int(input())):
	columnLength = int(input())
	row1 = input()
	row2 = input()
	status = 'YES'
	for index in range(columnLength):
		if row1[index] == row2[index] == '1':
			status = 'NO'
			break
	print(status)


def solution():
	for t in range(int(input())):
		n = int(input())
		cell = [input(), input()]
		ans = 'YES'
		for i in range(n):
			if cell[0][i] == '1' and cell[1][i] == '1':
				ans = 'NO'
				break
		print(ans)
	return
solution()


t = int(input())
for i in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	ans = 'YES'
	for i in range(n):
		if s1[i] == '1' and s2[i] == '1':
			ans = 'NO'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	ch1 = input()
	ch2 = input()
	for i in range(n):
		if ch1[i] == '1':
			if ch2[i] == '1':
				print('No')
				break
	else:
		if ch2[n - 1] == '1':
			print('NO')
		else:
			print('YES')


t = int(input())
for inh in range(0, t):
	n = int(input())
	a = input()
	b = input()
	(ans, i) = (True, 0)
	while i < n:
		if a[i] == '1' and b[i] == '1':
			ans = False
			break
		i += 1
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	flag = False
	for i in range(n):
		if s1[i] == '1' and s2[i] == '1':
			print('NO')
			flag = True
			break
	if flag == False:
		print('YES')


a = [*open(0)][1:]
for _ in range(len(a) // 3):
	print((int(a[3 * _ + 1], 2) & int(a[3 * _ + 2], 2) == 0) * 'YES' or 'NO')


for _ in range(int(input())):
	q = int(input())
	a = input()
	b = input()
	f = 'YES'
	for i in range(q):
		if a[i] == b[i] and a[i] == '1':
			f = 'NO'
			break
	print(f)


for _ in range(int(input())):
	n = int(input())
	a = [[0, 0] for i in range(n)]
	used = [[0, 0] for i in range(n)]
	b = list(map(int, ' '.join(input().split())))
	for i in range(n):
		a[i][0] = b[i]
	b = list(map(int, ' '.join(input().split())))
	for i in range(n):
		a[i][1] = b[i]
	if a[0][1] == 1:
		used[0][1] = 1
	for i in range(1, n):
		if not used[i - 1][0] or not used[i - 1][1]:
			if a[i][0] and a[i][1]:
				used[i] = [1, 1]
			elif a[i][0] and (not a[i][1]):
				used[i] = [1, 0]
			elif not a[i][0] and a[i][1]:
				used[i] = [0, 1]
			else:
				used[i] = [0, 0]
		else:
			used[i] = [1, 1]
	if not used[n - 1][1]:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	flag = 'YES'
	for i in range(n):
		if a[i] == '1' and b[i] == '1':
			flag = 'NO'
			break
	print(flag)


t = int(input())
for _ in range(t):
	n = int(input())
	mat = [0, 0]
	a = list(input())
	b = list(input())
	if b[-1] == '1' or a[0] == '1':
		print('NO')
		continue
	ans = 'YES'
	for i in range(n - 1):
		if a[i + 1] == '1' and b[i + 1] == '1':
			ans = 'NO'
	for i in range(n - 1):
		if b[i + 1] == '1' and a[i + 1] == '1':
			ans = 'NO'
	print(ans)


a = int(input())
for _ in range(a):
	b = int(input())
	li = [list(map(int, input())) for _ in range(2)]
	dp = [[1] * b for _ in range(2)]
	dp[0][0] = li[0][0]
	dp[1][0] = li[1][0]
	for j in range(1, b):
		for i in range(2):
			if li[i][j] == 0:
				dp[i][j] = min(dp[0][j - 1], dp[1][j - 1])
	if dp[1][-1] == 0:
		print('YES')
	else:
		print('NO')


import sys
import io, os
from io import BytesIO, IOBase
from os import path
from collections import Counter
import math
import random
import bisect
from functools import reduce
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod = 1000000007
a = inp()

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

def gcdofList(A):
	res = A[0]
	for c in A[1:]:
		res = gcd(res, c)
		if res == 1:
			return res
			break
	return res
	pass

def solve(t, z):
	t = list(t)
	z = list(z)
	t_con = Counter(t)
	z_con = Counter(z)
	if '1' not in t_con or '1' not in z_con:
		return 'YES'
	for i in range(1, len(t) - 1):
		if t[i] == '1' and z[i] == '1':
			return 'NO'
	return 'YES'
for i in range(a):
	b = inp()
	t = strng()
	z = strng()
	print(solve(t, z))


def solve():
	n = int(input())
	a = input()
	b = input()
	bad = False
	for i in range(n):
		bad |= a[i] == '1' and b[i] == '1'
	if bad:
		print('NO')
	else:
		print('YES')
t = int(input())
for i in range(t):
	solve()


n = int(input())
l = 0
for i in range(n):
	m = int(input())
	l1 = list(input())
	l2 = list(input())
	l = 0
	for j in range(m):
		if l1[j] == '1' and l2[j] == '1':
			l = 1
	if l == 1:
		print('NO')
	else:
		print('YES')


def test(mat, n):
	if mat[1][n - 1] == 1:
		return 'NO'
	elif len(set(mat[0])) == 1 and mat[0][0] == 1:
		return 'NO'
	elif len(set(mat[0])) == 1 and mat[0][0] == 0:
		return 'YES'
	else:
		for k in range(n):
			if mat[0][k] == 1 and mat[1][k] == 1:
				return 'NO'
		return 'YES'
t = int(input())
for i in range(t):
	n = int(input())
	mat = []
	for j in range(2):
		mat.append(list(map(int, list(input()))))
	print(test(mat, n))


def neighbours(coord):
	(r, c) = coord
	return [(r + 1, c), (r, c + 1), (r, c - 1), (r - 1, c)] + [(r + 1, c - 1), (r - 1, c + 1), (r + 1, c + 1), (r - 1, c - 1)]
for _ in range(int(input())):
	n = int(input())
	grid = []
	for _ in range(2):
		l = []
		for i in input():
			l.append(i)
		grid.append(l)
	start = (0, 0)
	while start != (1, n - 1):
		for pos in neighbours(start):
			if pos[0] < 0 or pos[1] < 0:
				continue
			try:
				if grid[pos[0]][pos[1]] == '0':
					grid[start[0]][start[1]] = '1'
					start = pos
					break
			except IndexError:
				continue
		else:
			print('NO')
			break
		if start == (1, n - 1):
			print('YES')


for t in range(int(input())):
	int(input())
	print('NO' if any(map(all, zip(map(int, input()), map(int, input())))) else 'YES')


def fun(n, r1, r2, x, y, c):
	if x == n - 1 and y == 1:
		return 1
	elif x < n:
		if x < n - 1 and r1[x + 1] == '0' and (y == 0):
			return fun(n, r1, r2, x + 1, y, 1)
		if x < n - 1 and r2[x + 1] == '0' and (y == 1):
			return fun(n, r1, r2, x + 1, y, 1)
		elif r2[x] == '0' and y == 0 and (c != 0):
			return fun(n, r1, r2, x, y + 1, 0)
		elif r1[x] == '0' and y == 1 and (c != 0):
			return fun(n, r1, r2, x, y - 1, 0)
		elif x < n - 1 and r2[x + 1] == '0' and (y == 0):
			return fun(n, r1, r2, x + 1, y + 1, 1)
		elif x < n - 1 and r1[x + 1] == '0' and (y == 1):
			return fun(n, r1, r2, x + 1, y - 1, 1)
		else:
			return 0
	else:
		return 0
trials = int(input())
for trial in range(trials):
	n = int(input())
	r1 = list(input())
	r2 = list(input())
	if fun(n, r1, r2, 0, 0, 0) == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	first = str(input())
	second = str(input())
	if any((first[i] == '1' and second[i] == '1' for i in range(1, n - 1))):
		print('NO')
	else:
		print('YES')


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

def split(word):
	return [char for char in word]

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 main():
	for i in range(int(input())):
		n = int(input())
		s = []
		for j in range(2):
			x = input()
			s.append(x)
		g = [1]
		for j in range(1, n):
			if s[0][j] == '0' or s[1][j] == '0':
				g.append(g[j - 1])
			else:
				g.append(0)
		if g[n - 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()


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	ans = 'YES'
	for j in range(n):
		if a[j] == '1' and b[j] == '1':
			ans = 'NO'
	print(ans)


t = int(input())
list = []
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	lisd = []
	for j in range(n):
		if a[j] == '1' and b[j] == '1':
			lisd.append('NO')
		else:
			lisd.append('YES')
	if 'NO' in lisd:
		list.append('NO')
	else:
		list.append('YES')
for i in list:
	print(i)


for _ in range(int(input())):
	n = int(input())
	(a, b) = (input(), input())
	print(['YES', 'NO'][any((a[i] == b[i] == '1' for i in range(n)))])


for iteration in range(int(input())):
	n = int(input())
	r1 = input()
	r2 = input()
	found = False
	for index in range(n):
		if r1[index] == '1' and r2[index] == '1':
			found = True
			break
	print('NO') if found else print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	r1 = input()
	r2 = input()
	good = False
	for i in range(n):
		if r1[i] == '1' and r2[i] == '1':
			good = True
			break
	if good:
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	n = int(input())
	s = input()
	s1 = input()
	f = True
	for i in range(0, len(s)):
		if s[i] == '1' and s1[i] == '1':
			print('NO')
			f = False
			break
	if f == True:
		print('YES')
	t -= 1


ans = []
for i in range(int(input())):
	a = int(input())
	s1 = input()
	s2 = input()
	for i in range(1, a - 1):
		if s1[i] == s2[i] == '1':
			ans.append('NO')
			break
	else:
		ans.append('YES')
for i in ans:
	print(i)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	a = input().strip()
	b = input().strip()
	an = 'YES'
	for i in range(n):
		if a[i] + b[i] == '11':
			an = 'NO'
			break
	print(an)


t = int(input())
while t > 0:
	n = int(input())
	s = str(input())
	s1 = str(input())
	f = 0
	i = 0
	while n > 0:
		x = int(s[i])
		y = int(s1[i])
		if x + y <= 1:
			i += 1
			n -= 1
		else:
			f = 1
			break
		x = 0
		y = 0
	if f:
		print('NO')
	else:
		print('YES')
	t -= 1


t = int(input())
final = []
for j in range(0, t):
	n = int(input())
	rows = []
	for i in range(0, 2):
		num = input()
		v = list(map(int, str(num)))
		rows.append(v)
	pos_y = 0
	pos_x = 0
	ans = ''
	while pos_x < n - 1:
		x = True
		if pos_y == 0 and rows[1][pos_x + 1] == 0:
			pos_x = pos_x + 1
			pos_y = 1
		elif pos_y == 1 and rows[0][pos_x + 1] == 0:
			pos_x = pos_x + 1
			pos_y = 0
		elif rows[pos_y][pos_x + 1] == 0:
			pos_x = pos_x + 1
		else:
			x = False
			ans = 'NO'
			break
	if x == True:
		if pos_y == 1:
			ans = 'YES'
		elif pos_y == 0 and rows[1][n - 1] == 0:
			ans = 'YES'
		else:
			ans = 'NO'
	final.append(ans)
for i in range(0, t):
	print(final[i])


t = int(input())
for i in range(t):
	tt = input()
	s = list(input())
	ss = list(input())
	ok = True
	for j in range(len(s)):
		ok = ok and int(s[j]) * int(ss[j]) == 0
	if ok:
		print('YES')
	else:
		print('NO')


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


mod = 10 ** 9 + 7
eps = 10 ** (-9)

def solve(t):
	n = int(input())
	s = input()
	t = input()
	ok = True
	for i in range(n - 1):
		if s[i + 1] == t[i + 1] == '1':
			ok = False
	print('YES' if ok else 'NO')
t = 1
t = int(input())
for i in range(t):
	solve(i + 1)


for _ in range(int(input())):
	n = int(input())
	arr = []
	for _ in range(2):
		arr.append(input())
	for i in range(n):
		if arr[0][i] == '1' and arr[1][i] == '1':
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	row = []
	for _ in range(2):
		row.append(input())
	ok = True
	for i in range(1, n, 1):
		if ok and (row[0][i] != '1' or row[1][i] != '1'):
			ok = True
		else:
			ok = False
	if ok:
		print('YES')
	else:
		print('NO')


t = int(input())
for kp in range(t):
	n = int(input())
	r1 = input()
	r2 = input()
	l1 = []
	l2 = []
	myr = 0
	for kp1 in str(r1):
		l1.append(int(kp1))
	for kp2 in str(r2):
		l2.append(int(kp2))
	for kp3 in range(n):
		if l1[kp3] == 1 and l2[kp3] == 1:
			myr = 1
	if myr == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	b = True
	for i in range(len(s1)):
		if s1[i] == '1' and s2[i] == '1':
			print('NO')
			b = False
			break
	if b == True:
		print('YES')


def process_request(m, string_one, string_two):
	i = 0
	change = True
	two = True
	one = False
	while i < m:
		if two:
			if string_two[i + 1] == '0':
				i += 1
				change = True
				if i == m - 1:
					return 'YES'
			elif change:
				two = False
				one = True
				change = False
			else:
				return 'NO'
		if one:
			if string_one[i + 1] == '0':
				i += 1
				change = True
				if i == m - 1:
					return 'YES'
			elif change:
				two = True
				one = False
				change = False
			else:
				return 'NO'

def main():
	n = int(input())
	requests = []
	for _ in range(n):
		m = int(input())
		string_one = input()
		string_two = input()
		requests.append([m, string_one, string_two])
	for request in requests:
		(m, string_one, string_two) = request
		print(process_request(m, string_one, string_two))
main()


from sys import stdin
input = stdin.readline

def solve(i, j):
	if i >= 2 or j >= n:
		return 0
	if s[i][j] == '1':
		return 0
	if i == 1 and j == n - 1:
		return 1
	if dp[i][j] != -1:
		return dp[i][j]
	ans = 0
	if i == 0 and s[i + 1][j] == '0':
		ans = max(ans, solve(i + 1, j))
	if j < n - 1 and s[i][j + 1] == '0':
		ans = max(ans, solve(i, j + 1))
	if i == 0 and j < n - 1 and (s[i + 1][j + 1] == '0'):
		ans = max(ans, solve(i + 1, j + 1))
	if i == 1 and j < n - 1 and (s[i - 1][j + 1] == '0'):
		ans = max(ans, solve(i - 1, j + 1))
	dp[i][j] = ans
	return ans
for T in range(int(input())):
	n = int(input())
	s = [input().strip() for i in range(2)]
	dp = [[-1 for i in range(n + 1)] for j in range(4)]
	ans = solve(0, 0)
	if ans == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	arr = [input() for i in range(2)]
	f = True
	for j in range(n):
		if int(arr[0][j]) + int(arr[1][j]) == 2:
			f = False
			break
	print('YES' if f is True else 'NO')


mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	s = input().strip('\n')
	p = input().strip('\n')
	f = 0
	for i in range(n):
		if s[i] == p[i] and p[i] == '1':
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
flag = True
for _ in range(t):
	grid = []
	n = int(input())
	for _ in range(2):
		grid.append(input())
	for i in range(n):
		if grid[0][i] == grid[1][i] == '1':
			print('NO')
			flag = False
			break
	if flag:
		print('YES')
	flag = True
	grid = []


for i in range(int(input())):
	n = input()
	a = input()
	b = input()
	ansN = False
	for j in range(int(n)):
		if int(a[j]) + int(b[j]) == 2:
			ansN = True
			break
	if not ansN:
		print('YES')
	else:
		print('NO')


for test_case in range(int(input())):
	n = int(input())
	c1 = int(input(), 2)
	c2 = int(input(), 2)
	if c1 & c2:
		print('NO')
	else:
		print('YES')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = input().rstrip()
	b = input().rstrip()
	flag = 'YES'
	for x in range(1, n - 1):
		if a[x] == b[x] == '1':
			flag = 'NO'
			break
	print(flag)


def solve():
	n = int(input())
	s1 = input()
	s2 = input()
	bad = False
	for i in range(n):
		bad |= s1[i] == '1' and s2[i] == '1'
	if bad:
		print('NO')
	else:
		print('YES')
t = int(input())
for i in range(t):
	solve()


(DX, DY) = ([1, -1, 0, 0, 1, -1, 1, -1], [0, 0, 1, -1, 1, -1, -1, 1])

class DisjointSet:

	def __init__(self, n):
		self.parent = [-1 for _ in range(n + 1)]

	def find(self, x):
		if self.parent[x] < 0:
			return x
		self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def size(self, x):
		return -self.parent[self.find(x)]

	def unite(self, x, y):
		rx = self.find(x)
		ry = self.find(y)
		if rx == ry:
			return False
		if self.parent[rx] > self.parent[ry]:
			(rx, ry) = (ry, rx)
		self.parent[rx] += self.parent[ry]
		self.parent[ry] = rx
		return True
for _ in range(int(input())):
	N = int(input())
	S = [input() for _ in range(2)]
	ds = DisjointSet(N * 2)
	for i in range(2):
		for j in range(N):
			if S[i][j] == '1':
				continue
			for (dx, dy) in zip(DX, DY):
				(ni, nj) = (i + dx, j + dy)
				if ni < 0 or ni >= 2 or nj < 0 or (nj >= N):
					continue
				if S[ni][nj] == '1':
					continue
				ds.unite(i * N + j, ni * N + nj)
	if ds.same(0, 2 * N - 1):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	matrix1 = input()
	matrix2 = input()
	for i in range(n):
		if matrix1[i] == '1' and matrix2[i] == '1':
			print('NO')
			break
	else:
		print('YES')


t = int(input())
l = []
while t:
	n = int(input())
	x = list(input())
	y = list(input())
	flag = True
	for i in range(n):
		if x[i] == y[i] == '1':
			l.append('NO')
			flag = False
			break
	if flag:
		l.append('YES')
	t -= 1
for ans in l:
	print(ans)


import os, sys
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
test_cases = int(input())
while test_cases:
	n = int(input())
	s = [input() for i in range(2)]
	result = False
	for i in range(n):
		if s[0][i] == '1' and s[1][i] == '1':
			result = False
			break
		result = True
	if result:
		print('YES')
	else:
		print('NO')
	test_cases = test_cases - 1


t = int(input())
for p in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	for i in range(1, n):
		if s1[i] == '0':
			if s2[i - 1] == '0':
				continue
		elif s2[i] == '0':
			if s1[i - 1] == '0':
				continue
		else:
			print('NO')
			break
	if i == n - 1 and s2[n - 1] == '0':
		print('YES')


import sys
input = sys.stdin.readline

def get():
	return input().strip()
for _ in range(int(input())):
	n = int(get())
	s1 = get()
	s2 = get()
	f = 0
	for i in range(n - 1):
		if s1[i] == '1' and s2[i] == '1':
			f = 1
			break
	if f == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for x in range(t):
	check = 1
	ms = []
	n = int(input())
	for i in range(2):
		ms.append(list(str(input())))
	for j in range(n - 1):
		if ms[0][j + 1] == '1' and ms[1][j + 1] == '1':
			check = 0
	if check == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for o in range(t):
	n = int(input())
	screen = [[], []]
	screen[0] = [int(x) for x in input()]
	screen[1] = [int(x) for x in input()]
	ret = True
	for x in range(1, n):
		if screen[0][x] == 1 and screen[1][x] == 1:
			ret = False
			break
	if ret:
		print('YES')
	else:
		print('NO')


test_cases = int(input())
for x in range(test_cases):
	columns = int(input())
	string1 = list(map(int, list(input())))
	string2 = list(map(int, list(input())))
	for y in range(columns - 1):
		if string1[y + 1] and string2[y + 1]:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for test_iteration in range(t):
	res = 'YES'
	n = int(input())
	first_line = input()
	second_line = input()
	first_line = [int(char) for char in first_line]
	second_line = [int(char) for char in second_line]
	for _ in zip(first_line, second_line):
		if _ == (1, 1):
			res = 'NO'
			break
		else:
			continue
	print(res)


for i in range(int(input())):
	int(input())
	a = input()
	b = input()
	flag = 0
	if b[-1] == '1':
		print('NO')
		continue
	if a[0] == '1':
		print('NO')
		continue
	for i in range(len(a)):
		if a[i] == '1' and a[i] == b[i]:
			flag = 1
	if flag == 1:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	s1 = input().strip()
	s2 = input().strip()
	for i in range(n):
		if s1[i] == s2[i] == '1':
			print('no')
			return
	print('yes')
tt = int(input())
for test in range(tt):
	solve()


t = int(input())
for tc in range(t):
	n = int(input())
	r1 = input()
	r2 = input()
	i = 0
	j = 0
	while i != 1 or j != n - 1:
		if j == n - 2:
			print('YES')
			break
		if i == 0:
			if r2[j + 1] != '1':
				i += 1
				j += 1
			elif r1[j + 1] != '1':
				j += 1
			else:
				print('NO')
				break
		elif r2[j + 1] != '1':
			j += 1
		elif r1[j + 1] != '1':
			i -= 1
			j += 1
		else:
			print('NO')
			break
	else:
		print('YES')


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))
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
for _ in range(ii1()):
	n = ii1()
	a = is1()
	b = is1()
	flag = True
	for i in range(1, n - 1):
		if a[i] == '0' or b[i] == '0':
			flag = True
		else:
			flag = False
			break
	if flag:
		if a[0] == '0' and b[-1] == '0':
			print('YES')
			continue
	print('NO')


def move(i, j, arr, vis):
	if [i, j] in vis:
		return False
	vis.append([i, j])
	if arr[i][j] == '1':
		return False
	if i == 1 and j == len(arr[0]) - 1:
		return True
	res = False
	for i1 in [0, 1]:
		for j1 in [j - 1, j, j + 1]:
			if [i1, j1] not in vis and j1 >= 0 and (j1 < len(arr[0])):
				res = res or move(i1, j1, arr, vis)
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	arr.append(list(input()))
	arr.append(list(input()))
	if move(0, 0, arr, []):
		print('YES')
	else:
		print('NO')


t = int(input())
noerrors = 'OK'
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	for j in range(len(a)):
		if a[j] == '1' and b[j] == '0' or (a[j] == '0' and b[j] == '1') or (a[j] == '0' and b[j] == '0'):
			noerrors = 'OK'
		else:
			noerrors = 'BAD'
			break
	if noerrors == 'OK':
		print('YES')
	else:
		print('NO')


T = int(input())
for x in range(T):
	n = int(input())
	r1 = input()
	r2 = input()
	happened = False
	for y in range(len(r1)):
		if r1[y:y + 1] == r2[y:y + 1] == '1':
			happened = True
	if happened == False:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	row1 = input()
	row2 = input()
	for i in range(n):
		if row1[i] == '1' and row2[i] == '1':
			print('NO')
			break
	else:
		print('YES')


import os
import sys
from io import BytesIO, IOBase
_str = str
str = lambda x=b'': x if type(x) is bytes else _str(x).encode()
BUFSIZE = 8192

def main():
	mod = 10 ** 9 + 7
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input()))
		b = list(map(int, input()))
		for i in range(n):
			if a[i] == b[i] == 1:
				print('NO')
				break
		else:
			print('YES')
main()

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')


t = int(input())
for i in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	check = 1
	for i in range(len(s1)):
		if int(s1[i]) + int(s2[i]) == 2:
			check = 0
			break
	if check == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for j in range(t):
	n = int(input())
	row_1 = input()
	row_2 = input()
	for i in range(n):
		check = 0
		if row_1[i] == '1' and row_2[i] == '1':
			check = 1
			break
	if check == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l1 = list(input())
	l2 = list(input())
	if '11' in [l1[i] + l2[i] for i in range(n)]:
		print('NO')
	else:
		print('YES')


from collections import deque

def BFS(i, j):
	q = deque()
	q.append((i, j))
	cur = [i, j]
	while len(q) > 0:
		(cr, cc) = q.popleft()
		matrix[cr][cc] = '1'
		cur[0] = cr
		cur[1] = cc
		if cur == [1, cols - 1]:
			return cur
		for (dr, dc) in [(0, 1), (0, -1), (1, 0), (1, -1), (1, 1), (-1, 1), (-1, 0), (-1, -1)]:
			nr = cr + dr
			nc = cc + dc
			if 0 <= nr < 2 and 0 <= nc < cols and (matrix[nr][nc] == '0'):
				matrix[nr][nc] = '1'
				q.append((nr, nc))
	return cur
for _ in range(int(input())):
	cols = int(input())
	matrix = []
	for _ in range(2):
		matrix.append(list(input()))
	if BFS(0, 0) == [1, cols - 1]:
		print('YES')
	else:
		print('NO')


def func():
	for i in range(n - 1):
		if x[i][0] == x[i][1] == '1' or x[-1][1] == '1':
			print('NO')
			return
	print('YES')
for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	x = list(zip(a, b))
	func()


def solve():
	n = int(input())
	s1 = input()
	s2 = input()
	for i in range(n):
		if s1[i] == '1' and s2[i] == '1':
			return 0
	return 1
import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
ans = ['NO', 'YES']
for i in range(t):
	print(ans[solve()])


from os import path
from sys import stdin, stdout
if path.exists('tc.txt'):
	stdin = open('tc.txt', 'r')

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

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

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

def gart():
	return tuple(map(int, stdin.readline().strip().split()))

def gars():
	return list(map(str, stdin.readline().strip().split()))

def gs():
	return stdin.readline().strip()

def gls():
	return list(stdin.readline().strip())

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

def solve():
	(n, ar, br) = (gi(), gls(), gls())
	for i in range(n):
		if ar[i] == br[i] == '1':
			return 'NO'
	return 'YES' if br[n - 1] == '0' else 'NO'
tc = gi()
while tc:
	tc -= 1
	print(solve())


for _ in range(int(input())):
	n = int(input())
	d = []
	for i in range(2):
		s = input()
		d.append(s)
	for j in range(n):
		if d[0][j] == d[1][j] == '1':
			print('NO')
			break
	else:
		print('YES')


import os
import sys
from collections import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase
from typing import overload

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = int(1000000000.0 + 7)
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = []
	ans = 'YES'
	for i in range(2):
		a.append(input())
	for i in range(n):
		if a[0][i] == '1' and a[0][i] == a[1][i]:
			ans = 'NO'
	print(ans)


for _ in range(int(input())):
	c = int(input())
	l = []
	for i in range(2):
		s = input()
		l1 = []
		for i in s:
			l1.append(int(i))
		l.append(l1)

	def func():
		if l[0][0] == 1 or l[-1][-1]:
			return 'NO'
		for i in range(c):
			if l[0][i] == l[1][i] == 1:
				return 'NO'
		return 'YES'
	print(func())


for i in range(int(input())):
	n = int(input())
	maze = []
	for j in range(2):
		maze.append(input())
	if maze[0][0] == '1' or maze[1][n - 1] == '1':
		print('NO')
		continue
	flag = 0
	for j in range(n - 1):
		cnt = 0
		if maze[0][j + 1] == '1':
			cnt += 1
		if maze[1][j + 1] == '1':
			cnt += 1
		if cnt == 2:
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')


t = int(input())
for x in range(0, t):
	n = int(input())
	s1 = input()
	s2 = input()
	k = 1
	for i in range(0, n):
		if s1[i] == '1' and s2[i] == '1':
			k = 0
			break
	if k == 1:
		print('YES')
	else:
		print('NO')


def solve(s, s1, i, j):
	if i > 1 or j > n - 1 or i < 0:
		return False
	if i == 0:
		if s[j] == '1':
			return False
	if i == 1:
		if s1[j] == '1':
			return False
	if i == 1 and j == n - 1:
		return True
	if arr[i][j] == 1:
		return True
	if arr[i][j] == 0:
		return False
	ans = solve(s, s1, i + 1, j) or solve(s, s1, i, j + 1) or solve(s, s1, i + 1, j + 1) or solve(s, s1, i - 1, j + 1)
	if ans:
		arr[i][j] = 1
	else:
		arr[i][j] = 0
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	s1 = input()
	arr = [[-1 for k in range(n)] for j in range(2)]
	if solve(s, s1, 0, 0):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s = []
	for _ in range(2):
		s.append([z for z in input()])
	f = True
	(i, j) = (0, 0)
	x = [0, 0]
	while f:
		if i != n - 1:
			if s[abs(j - 1)][i + 1] == '0' and [abs(j - 1), i + 1] != x:
				x = [j, i]
				(j, i) = (abs(j - 1), i + 1)
			elif s[j][i + 1] == '0' and [j, i + 1] != x:
				x = [j, i]
				(j, i) = (j, i + 1)
			elif s[abs(j - 1)][i] == '0' and [abs(j - 1), i] != x:
				x = [j, i]
				(j, i) = (abs(j - 1), i)
			else:
				print('No')
				f = False
		else:
			print('Yes')
			f = False


t = int(input())
for x in range(t):
	n = int(input())
	ch0 = input()
	ch1 = input()
	l = [[int(i) for i in ch0], [int(i) for i in ch1]]
	nb = 0
	for i in range(1, n - 1):
		if l[0][i] == 1 and l[1][i] == 1:
			nb += 1
	if nb > 0:
		print('NO')
	else:
		print('YES')


t = int(input())
for j in range(0, t):
	n = int(input())
	r = input()
	s = input()
	o = 'YES'
	for i in range(0, n):
		if r[i] == s[i] and r[i] == '1':
			o = 'NO'
			break
	print(o)


t = int(input())
for _ in range(t):
	n = int(input())
	grids = []
	up = input()
	down = input()
	possible = True
	for i in range(n):
		if up[i] == down[i] == '1':
			possible = False
			break
	if possible:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	s = input()
	ss = input()
	flag = False
	for i in range(n):
		if s[i] == ss[i] == '1':
			print('NO')
			flag = True
			break
	if not flag:
		print('YES')


t = int(input())
for zz in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	i = 0
	c = 0
	if s1[0] == '0' or s2[0] == '0':
		while True:
			if i == n - 1:
				break
			if s1[i + 1] == '0' or s2[i + 1] == '0':
				i += 1
			elif s1[i + 1] == '1' and s2[i + 1] == '1':
				c = 1
				break
		if c == 1:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	if a[0] == '1' or b[n - 1] == '1':
		print('NO')
		continue
	pas = True
	for i in range(n):
		if a[i] == '1' and b[i] == '1':
			pas = False
			break
	print('YES' if pas else 'NO')


def f():
	n = int(input())
	a = int(input(), 2)
	b = int(input(), 2)
	return 'YES' if a & b == 0 else 'NO'
for _ in range(int(input())):
	print(f())


t = int(input())
for i in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	bad = False
	for j in range(1, n):
		if s1[j] == '1' and s2[j] == '1':
			print('NO')
			bad = True
			break
	if bad != True:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	a = int(input(), 2)
	b = int(input(), 2)
	if not a & b:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	a = int(input())
	l1 = input()
	l2 = input()
	x = True
	for j in range(a - 1):
		if l1[j + 1] == '1' and l2[j + 1] == '1':
			x = False
			print('NO')
			break
	if x == True:
		print('YES')


from sys import stdin, stdout
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	r = False
	for i in range(n):
		r |= a[i] == '1' and b[i] == '1'
	if r:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	grid = []
	col = int(input())
	r1 = list(input())
	r2 = list(input())
	a = 0
	while col > 0:
		if r1[0] == '0' and r2[0] == '0' or (r1[0] == '0' and r2[0] == '1') or (r1[0] == '1' and r2[0] == '0'):
			r1.remove(r1[0])
			r2.remove(r2[0])
			col -= 1
		elif r1[0] == '1' and r2[0] == '1':
			r1.remove(r1[0])
			r2.remove(r2[0])
			col -= 1
			a += 1
	if a == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	lis = input()
	lis1 = input()
	for i in range(n):
		if lis[i] == '1' and lis1[i] == '1':
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for i in range(t):
	y = 1
	n = int(input())
	x1 = input()
	x2 = input()
	for j in range(n):
		if x1[j] == '1' and x2[j] == '1':
			print('NO')
			y = 0
			break
	if y == 1:
		print('YES')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	x = input()
	y = input()
	kt = True
	for i in range(n):
		if x[i] == '1' and y[i] == '1':
			kt = False
			break
	print('YES' if kt else 'NO')


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


test_count = int(input())

def can_move(grid: list):
	first_row = grid[0][1:-1]
	second_row = grid[1][1:-1]
	for col_index in range(len(first_row)):
		if first_row[col_index] == 1 and second_row[col_index] == 1:
			return 'NO'
	else:
		return 'YES'
results = []
for test_round in range(test_count):
	col_count = int(input())
	first_row_rule = input()
	second_row_rule = input()
	current_round_grid = [[int(i) for i in first_row_rule], [int(i) for i in second_row_rule]]
	results.append(can_move(grid=current_round_grid))
for result in results:
	print(result)


tests = int(input())
for _ in range(tests):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	if any((s1[i] == '1' and s2[i] == '1' for i in range(n))):
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	cols = int(input())
	s = not not int(input(), 2) & int(input(), 2)
	print('NO' * s + 'YES' * (not s))


mod = 10 ** 9 + 7

def main():
	n = int(input())
	s1 = input()
	s2 = input()
	if s2[-1] == '1' or s1[0] == '1':
		print('NO')
		return
	for i in range(n):
		if s1[i] == '1' and s2[i] == '1':
			print('NO')
			return
	print('YES')
t = 1
t = int(input())
for ii in range(t):
	main()


for _ in [0] * int(input()):
	input()
	print('YNEOS'[int(input(), 2) & int(input(), 2) > 0::2])


n = int(input())
for i in range(n):
	n1 = int(input())
	(first, second) = (input(), input())
	a = True
	for g in range(n1):
		if first[g] == '1' and first[g] == second[g]:
			print('NO')
			a = False
			break
	if a:
		print('YES')


for _ in range(int(input())):
	c = int(input())
	arr = list(input())
	brr = list(input())
	flag = -1
	for i in range(c):
		if int(arr[i]) == 1 and int(brr[i]) == 1:
			flag = 0
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')


for i in range(int(input())):
	a = int(input())
	lis = input()
	lis2 = input()
	ans = 0
	c = 1
	for i in range(a):
		if lis[i] == '1' and lis2[i] == '1':
			ans = 1
			break
	if ans:
		print('NO')
	else:
		print('YES')


def game(n):
	n = n - 1
	mtx = []
	a = str(input())
	mtx.append(a)
	b = str(input())
	mtx.append(b)
	stk = []
	stk.append([0, 0])
	visit = [[], []]
	for i in range(2):
		for j in range(n + 1):
			visit[i].append(False)
	visit[0][0] == True
	while len(stk) != 0:
		x = stk.pop()
		if x[0] > 1 or x[0] < 0 or x[1] > n or (x[1] < 0):
			continue
		if x[0] == 0:
			if mtx[0][x[1]] == '0':
				if visit[1][x[1]] == False:
					stk.append([1, x[1]])
					visit[1][x[1]] = True
		if x[0] == 1:
			if mtx[1][x[1]] == '0':
				if visit[0][x[1]] == False:
					stk.append([0, x[1]])
					visit[0][x[1]] = True
		if x[1] < n:
			if mtx[x[0]][x[1] + 1] == '0':
				if visit[x[0]][x[1] + 1] == False:
					stk.append([x[0], x[1] + 1])
					visit[x[0]][x[1] + 1] = True
		if x[1] > 0:
			if mtx[x[0]][x[1] - 1] == '0':
				if visit[x[0]][x[1] - 1] == False:
					stk.append([x[0], x[1] - 1])
					visit[x[0]][x[1] - 1] = True
	return visit[1][n]
for _ in range(int(input())):
	flg = game(int(input()))
	if flg:
		print('YES')
	else:
		print('NO')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, functools, copy
inf = float('inf')
mod = 10 ** 9 + 7

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

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

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

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

def S():
	return input()

def LS():
	return input().split()

def endl():
	return print('\n')

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

def grayCode(n):
	return n ^ n >> 1
sys.setrecursionlimit(200000)
graph = collections.defaultdict(list)
grid = []
visited = set()
ways = ['D', 'U', 'R', 'L']
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

def initGraph(m):
	for _ in range(m):
		(u, v) = LI()
		graph[u - 1].append(v - 1)
		graph[v - 1].append(u - 1)

def initGraphW(m):
	for _ in range(m):
		(a, b, c) = LI()
		graph[a - 1].append((b - 1, c))
		graph[b - 1].append((a - 1, c))

def initGrid(h, w):
	for i in range(h):
		grid.append(list(S()))
for _ in range(I()):
	n = I()
	s1 = S()
	s2 = S()
	booly = True
	for i in range(n):
		if s1[i] == '1' and s2[i] == '1':
			booly = False
			break
	if not booly:
		print('NO')
	else:
		print('YES')


def fun(f, s, n):
	yes = '0'
	no = '1'
	dp = [[False for i in range(100)] for i in range(2)]
	for i in range(n - 1, -1, -1):
		if i == n - 1:
			if s[i] == no:
				dp[1][i] = False
				dp[0][i] = False
			else:
				dp[1][i] = True
				if f[i] == yes:
					dp[0][i] = True
				else:
					dp[0][i] = False
		else:
			if s[i] == yes:
				dp[1][i] = dp[1][i + 1] or dp[0][i + 1] or dp[0][i]
			if f[i] == yes:
				dp[0][i] = dp[0][i + 1] or dp[1][i + 1] or dp[1][i]
	if dp[0][0] == True:
		print('YES')
	else:
		print('NO')
T = int(input())
for i in range(T):
	n = int(input())
	f = input()
	s = input()
	fun(f, s, n)


T = int(input())
for t in range(T):
	n = int(input())
	arr = [list(input()) for i in range(2)]
	for i in range(1, n):
		if arr[0][i] == arr[1][i] == '1':
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for nums in range(t):
	n = int(input())
	row_1 = input()
	row_2 = input()
	for i in range(n - 1):
		if row_1[i] == '1' and row_2[i] == '1':
			print('NO')
			break
		elif i == n - 2 and row_2[i + 1] == '0':
			print('YES')
		else:
			pass


def main():
	n = int(input())
	for i in range(n):
		answer = 'YES'
		c = int(input())
		r1 = [int(i) for i in input()]
		r2 = [int(i) for i in input()]
		if r1[0] == 1:
			answer = 'NO'
			break
		else:
			for j in range(1, c):
				if r1[j] == 1 and r2[j] == 1:
					answer = 'NO'
					break
		if r2[c - 1] == 0 and answer == 'YES':
			print('YES')
		else:
			print('NO')
main()


def f(lst1, lst2, length):
	for i in range(length - 1):
		if lst1[i] == 1 and lst2[i] == 1 and (i == 0):
			return False
		if lst1[i + 1] == 1 and lst2[i + 1] == 1:
			return False
	return True
attempts = int(input())
while attempts:
	length = int(input())
	row1 = list(map(int, list(input())))
	row2 = list(map(int, list(input())))
	print('Yes' if f(row1, row2, length) else 'No')
	attempts -= 1


for _ in range(int(input())):
	n = int(input())
	l0 = input()
	l1 = input()
	assert len(l0) == len(l1) == n
	for i in range(n):
		if l0[i] == l1[i] == '1':
			print('NO')
			break
	else:
		print('YES')


for i in range(int(input())):
	n = int(input())
	l = input()
	m = input()
	z = 0
	for k in range(n):
		if l[k] == '1' and m[k] == '1':
			z = 1
			print('NO')
			break
	if z == 0:
		print('YES')


for _ in range(0, int(input())):
	input()
	c = any((x == '1' and y == '1' for (x, y) in zip(input(), input())))
	print(['YES', 'NO'][c])


t = int(input())
for _ in range(t):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	res = True
	for (c1, c2) in zip(s1, s2):
		if c1 == '1' and c2 == '1':
			res = False
			break
	print('YES' if res else 'NO')


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from collections import *
from bisect import *
from string import *
from itertools import *
from statistics import *
from math import *
from re import *
from queue import *
mod = int(1000000000.0 + 7)
mod1 = 998244353
imax = float('inf')
imin = float('-inf')
true = True
false = False
N = 10 ** 5
none = None
inp = lambda : input()
I = lambda : int(inp())
M = lambda : map(int, inp().split())
MS = lambda : map(str, inp().split())
S = lambda : list(MS())
L = lambda : list(M())
test_case_run__ = false

def case():
	global test_case_run__
	test_case_run__ = true
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
case()

def main():
	n = I()
	s = inp()
	t = inp()

	def find():
		for i in range(n):
			if s[i] == '1' and t[i] == '1':
				return false
		return true
	a = find()
	print('YES' if a else '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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = true
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = false
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', false):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class maths:

	def power(self, a, b, m):
		a %= m
		res = 1
		while b > 0:
			if b & 1:
				res = res * a % m
			a = a * a % m
			b >>= 1
		return res

def IO():
	try:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('uttar.txt', 'w')
	except:
		pass
maths = maths()
IO()
if test_case_run__:
	for i in range(I()):
		main()
else:
	main()


def solve():
	t = int(input().strip())
	for _ in range(t):
		n = int(input().strip())
		game = []
		game.append(input().strip())
		game.append(input().strip())
		possible = True
		for i in range(n):
			if game[0][i] == '1' and game[1][i] == '1':
				possible = False
				break
		if possible:
			print('YES')
		else:
			print('NO')
solve()


n = int(input())
for _ in range(n):
	c = int(input())
	r1 = input()
	r2 = input()
	for i in range(c):
		if r1[i] == '1' and r2[i] == '1':
			print('NO')
			break
		elif i == c - 1:
			print('YES')


from collections import Counter
mxn = 10 ** 10
for _ in range(int(input())):
	n = int(input())
	grid = []
	for i in range(2):
		grid.append(input())
	case = 0
	for j in range(1, n):
		if grid[0][j] == '1' and grid[1][j] == '1':
			case = 1
			break
	if not case:
		print('YES')
	else:
		print('NO')


import sys
from collections import deque
import heapq
import bisect
import copy
MOD = 1000000007
NO = lambda : print('NO')
YES = lambda : print('YES')
_1 = lambda : print(-1)
ari = lambda : [int(_) for _ in input().split()]
cin = lambda : int(input())
cis = lambda : input()
show = lambda x: print(x)
test_case = 1
test_case = int(input())
sys.setrecursionlimit(10 ** 6)

def ans():
	n = cin()
	fist = list(cis())
	second = list(cis())
	mat = []
	mat.append(fist + ['0'])
	mat += [second + ['0']]
	track = True
	x = 0
	y = 0
	for i in range(n):
		if mat[x][i] == '1':
			if x == 0 and mat[x + 1][i] == '0':
				x = 1
			elif x == 1 and mat[x - 1][i] == '0':
				x = 0
			else:
				track = False
				break
	if track:
		YES()
	else:
		NO()
	return
for _ in range(test_case):
	ans()


t = int(input())
for i in range(t):
	n = int(input())
	s0 = input()
	s1 = input()
	x = [0, 0]
	for j in range(n - 1):
		if s1[j + 1] == '0':
			x[1] += 1
			if x[0] == 0:
				x[0] += 1
		elif s0[j + 1] == '0' and s1[j + 1] == '1':
			x[1] += 1
			if x[0] == 1:
				x[0] == 0
	if x == [1, n - 1]:
		print('YES')
	else:
		print('NO')


t = int(input())

def solve():
	n = int(input())
	arr = []
	for _ in range(2):
		arr.append([x == '0' for x in input()] + [False])
	if not arr[1][n - 1]:
		print('NO')
		return
	for i in range(n):
		if i == n - 1:
			print('YES')
			return
		if arr[0][i + 1]:
			continue
		if arr[1][i + 1]:
			continue
		print('NO')
		return
for _ in range(t):
	solve()


import sys

def is_possible(row1, row2):
	for x in range(len(row1)):
		if row1[x] == '1' and row2[x] == '1':
			return 'NO\n'
	return 'YES\n'
infile = []
for line in sys.stdin:
	if '' == line.rstrip():
		break
	infile.append(line.rstrip())
rows = []
for x in range(1, len(infile), 3):
	rows.append(infile[x + 1])
	rows.append(infile[x + 2])
for y in range(0, len(rows), 2):
	sys.stdout.write(is_possible(rows[y], rows[y + 1]))


testCases = int(input())
for _ in range(testCases):
	column = int(input())
	row1 = input()
	row2 = input()
	for i in range(column - 1):
		if not (row1[i] == '0' or row2[i] == '0'):
			print('NO')
			break
		if i == column - 2:
			print('YES')


for _ in range(int(input())):
	n = int(input())
	arr = [[], []]
	a = input()
	for x in a:
		arr[0].append(int(x))
	a = input()
	for x in a:
		arr[1].append(int(x))
	f = [[0] * n, [0] * n]
	f[0][0] = 1
	for j in range(n - 1):
		if f[0][j]:
			f[0][j + 1] = 1 - arr[0][j + 1]
			f[1][j + 1] = 1 - arr[1][j + 1]
			f[1][j] = 1 - arr[1][j]
		if f[1][j]:
			f[0][j + 1] = 1 - arr[0][j + 1]
			f[1][j + 1] = 1 - arr[1][j + 1]
			f[0][j] = 1 - arr[0][j]
	if f[1][n - 1]:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	x = input()
	y = input()
	z = 'YES'
	for j in range(n):
		if x[j] == '1' and y[j] == '1':
			z = 'NO'
			break
	print(z)


for i in range(int(input())):
	a = int(input())
	b = input()
	c = input()
	for i in range(a):
		if b[i] == c[i] == '1':
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for _ in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	check = False
	for i in range(n):
		check |= s1[i] == '1' and s2[i] == '1'
	if check:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def input_string():
	s = input()
	return list(s[:len(s) - 1])

def input_int_gen():
	return map(int, input().split())
tests = inp()
for _ in range(tests):
	n = inp()
	a1 = input_string()
	a2 = input_string()
	for (s1, s2) in zip(a1, a2):
		if s1 == s2 == '1':
			print('NO')
			break
	else:
		print('YES')


cases = int(input())
all = [input() for i in range(cases * 3)]
final = [all[i:i + 3] for i in range(0, len(all), 3)]

def survival(final):
	for i in final:
		top = i[1]
		bottom = i[2]
		top_traps = [i for i in range(len(top)) if top[i] == '1']
		bottom_traps = [i for i in range(len(bottom)) if bottom[i] == '1']
		checker = []
		for i in top_traps:
			if i in bottom_traps:
				checker.append(8)
		if len(checker) == 0:
			print('YES')
		else:
			print('NO')
survival(final)


t = int(input())
for p in range(t):
	n = int(input())
	s1 = str(input())
	s2 = str(input())
	flag = 1
	for i in range(n):
		if s1[i] == '1' and s2[i] == '1':
			flag = 0
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')


k = int(input())
for i in range(k):
	x = int(input())
	string = input()
	string1 = input()
	f = 0
	for i in range(x):
		if string[i] == '1' and string1[i] == '1':
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


t = int(input())
g = []
f = [0, 0, 0]
for i in range(t):
	for j in range(3):
		f[j] = input()
	g.append(f)
	f = [0, 0, 0]
for i in range(t):
	n = int(g[i][0])
	c = 1
	for j in range(n):
		if g[i][1][j] == '1' and g[i][2][j] == '1':
			c = 0
			break
	if c:
		print('YES')
	else:
		print('NO')


import math
from collections import defaultdict, Counter
for t in range(int(input())):
	n = int(input())
	l = []
	for i in range(2):
		l.append(input())
	if l[1][-1] == '1':
		print('NO')
		continue
	f = True
	for i in range(n):
		if l[0][i] == '1' and l[1][i] == '1':
			f = False
	if f:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = int(input())
	x = int(input())
	y = int(input())
	c = str(x + y)
	if '2' in c:
		print('NO')
	else:
		print('YES')