C. Pipes

problem_index: C

time_limit: 2 seconds

memory_limit: 256 megabytes

solutions: ["def pipetype(i):\n\tif i == '1' or i == '2':\n\t\treturn 1\n\telse:\n\t\treturn 2\n\ndef find_way2(arr, n):\n\tcount = 0\n\trow = 0\n\tcol = 0\n\tprev_row = 0\n\tprev_col = -1\n\tprev_state = 1\n\twhile col <= n:\n\t\tcount += 1\n\t\tprev_i = row\n\t\tprev_j = col\n\t\tif col == n and row == 0:\n\t\t\treturn 'NO'\n\t\telif col == n and row == 1:\n\t\t\treturn 'YES'\n\t\tif pipetype(arr[row][col]) == 1:\n\t\t\tif row == prev_row:\n\t\t\t\tcol += 1\n\t\t\telse:\n\t\t\t\treturn 'NO'\n\t\telif pipetype(arr[row][col]) == 2:\n\t\t\tif row == 0 and prev_row == 0:\n\t\t\t\trow += 1\n\t\t\telif row == 0 and prev_row == 1:\n\t\t\t\tcol += 1\n\t\t\telif row == 1 and prev_row == 0:\n\t\t\t\tcol += 1\n\t\t\telif row == 1 and prev_row == 1:\n\t\t\t\trow -= 1\n\t\tprev_row = prev_i\n\t\tprev_col = prev_j\n\treturn 'YES'\nfor i in range(int(input())):\n\tn = int(input())\n\tarr = [input()]\n\tarr.append(input())\n\tprint(find_way2(arr, n))\n", "import sys\nimport os\nfrom io import IOBase, BytesIO\n\ndef main():\n\tfor tc in range(int(input())):\n\t\tn = int(input())\n\t\ts1 = list(input())\n\t\ts2 = list(input())\n\t\t(s, f) = (1, 0)\n\t\tfor i in range(n):\n\t\t\tif s == 1:\n\t\t\t\tif s1[i] == '1' or s1[i] == '2':\n\t\t\t\t\tcontinue\n\t\t\t\telif s2[i] == '1' or s2[i] == '2':\n\t\t\t\t\tf = 1\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\ts = 0\n\t\t\telif s2[i] == '1' or s2[i] == '2':\n\t\t\t\tcontinue\n\t\t\telif s1[i] == '1' or s1[i] == '2':\n\t\t\t\tf = 1\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ts = 1\n\t\t\tif f == 1:\n\t\t\t\tbreak\n\t\tif s == 0 and f == 0:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\nBUFSIZE = 8192\n\nclass FastIO(BytesIO):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._file = file\n\t\tself._fd = file.fileno()\n\t\tself.writable = 'x' in file.mode or 'w' in file.mode\n\t\tself.write = super(FastIO, self).write if self.writable else None\n\n\tdef _fill(self):\n\t\ts = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\tself.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])\n\t\treturn s\n\n\tdef read(self):\n\t\twhile self._fill():\n\t\t\tpass\n\t\treturn super(FastIO, self).read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\ts = self._fill()\n\t\t\tself.newlines = s.count(b'\\n') + (not s)\n\t\tself.newlines -= 1\n\t\treturn super(FastIO, self).readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.getvalue())\n\t\t\t(self.truncate(0), self.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tpy2 = round(0.5)\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tif py2 == 1:\n\t\t\tself.write = self.buffer.write\n\t\t\tself.read = self.buffer.read\n\t\t\tself.readline = self.buffer.readline\n\t\telse:\n\t\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\n\ndef get_array():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef get_ints():\n\treturn map(int, sys.stdin.readline().split())\n\ndef input():\n\treturn sys.stdin.readline().strip()\nmain()\n", "import sys\nfrom heapq import heappop\nfrom heapq import heappush\nfrom heapq import heapify\nfrom bisect import insort\nfrom bisect import bisect_right\nfrom bisect import bisect_left\nfrom sys import stdin, stdout\nfrom collections import defaultdict\ninp = lambda : int(stdin.readline())\nsip = lambda : input()\nmulip = lambda : map(int, input().split())\nlst = lambda : list(map(int, stdin.readline().split()))\nslst = lambda : list(sip())\narr2d = lambda x: [[int(j) for j in input().split()] for i in range(x)]\nodds = lambda l: len(list(filter(lambda x: x % 2 != 0, l)))\nevens = lambda l: len(list(filter(lambda x: x % 2 == 0, l)))\nmod = pow(10, 9) + 7\nfor _ in range(inp()):\n\tn = inp()\n\ts1 = list(input())\n\ts2 = list(input())\n\tl = []\n\tl.append(s1)\n\tl.append(s2)\n\tr = 0\n\ti = 0\n\twhile i < n:\n\t\tif int(l[r][i]) > 2:\n\t\t\tif int(l[r ^ 1][i]) < 3:\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tr = r ^ 1\n\t\ti += 1\n\tif r == 1 and i == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "st = ['1', '2']\ntera = ['3', '4', '5', '6']\nfor _ in range(int(input())):\n\tn = int(input())\n\tli = [input()]\n\tli.append(input())\n\tj = 0\n\ti = 0\n\tflag = 1\n\twhile i < n:\n\t\tif li[j][i] in st:\n\t\t\ti += 1\n\t\telif j == 0:\n\t\t\tif li[1][i] not in tera:\n\t\t\t\tflag = 0\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tj = 1\n\t\t\t\ti += 1\n\t\telif li[0][i] not in tera:\n\t\t\tflag = 0\n\t\t\tbreak\n\t\telse:\n\t\t\tj = 0\n\t\t\ti += 1\n\tif flag == 1 and j == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\ninput = sys.stdin.readline\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\t(lx, ly) = (0, -1)\n\t(x, y) = (0, 0)\n\ts = [['1'] + list(input().rstrip()) for _ in range(2)]\n\tvisit = [[0] * (n + 1) for _ in range(2)]\n\twhile 0 <= x < 2 and 0 <= y < n + 1:\n\t\tif visit[x][y]:\n\t\t\tbreak\n\t\tvisit[x][y] = 1\n\t\tif int(s[x][y]) <= 2:\n\t\t\t(nx, ny) = (2 * x - lx, 2 * y - ly)\n\t\telif abs(x - lx):\n\t\t\t(nx, ny) = (x, y + 1)\n\t\telse:\n\t\t\t(nx, ny) = (x ^ 1, y)\n\t\t(lx, ly) = (x, y)\n\t\t(x, y) = (nx, ny)\n\tans = 'YES' if x == 1 and y == n + 1 else 'NO'\n\tprint(ans)\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\ti = 0\n\tcurrent = 0\n\tflag = 0\n\twhile i < n - 1:\n\t\tif current == 0:\n\t\t\tif s1[i] == '3' or s1[i] == '4' or s1[i] == '5' or (s1[i] == '6'):\n\t\t\t\tcurrent = 1\n\t\t\t\tif s2[i] == '1' or s2[i] == '2':\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tflag = 1\n\t\t\t\t\tbreak\n\t\telif s2[i] == '3' or s2[i] == '4' or s2[i] == '5' or (s2[i] == '6'):\n\t\t\tcurrent = 0\n\t\t\tif s1[i] == '1' or s1[i] == '2':\n\t\t\t\tprint('NO')\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\t\ti += 1\n\tif flag == 1:\n\t\tcontinue\n\tif current == 0:\n\t\tif s1[i] == '3' or s1[i] == '4' or s1[i] == '5' or (s1[i] == '6'):\n\t\t\tif s2[i] == '3' or s2[i] == '4' or s2[i] == '5' or (s2[i] == '6'):\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\telse:\n\t\t\tprint('NO')\n\telif s2[i] == '1' or s2[i] == '2':\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\nT = int(sys.stdin.readline())\nfor _ in range(T):\n\tN = int(sys.stdin.readline())\n\tlist_map = [sys.stdin.readline().strip() for _ in range(2)]\n\tlist_memo = [[[0] * 5 for _ in range(N + 1)] for _ in range(2)]\n\tlist_memo[0][-1][0] = 1\n\tfor i in range(N):\n\t\tfor j in range(2):\n\t\t\tnow = list_map[j][i]\n\t\t\tif now == '2' or now == '1':\n\t\t\t\tlist_memo[j][i][0] = max(list_memo[j][i - 1][0], list_memo[j][i - 1][1], list_memo[j][i - 1][4])\n\t\t\telse:\n\t\t\t\tlist_memo[j][i][3] = max(list_memo[j][i - 1][0], list_memo[j][i - 1][4])\n\t\t\t\tlist_memo[j][i][2] = max(list_memo[j][i - 1][0], list_memo[j][i - 1][1])\n\t\t\t\tlist_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\n\t\t\t\tlist_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\n\tprint('YES' if max(list_memo[1][N - 1][0], list_memo[1][N - 1][4]) else 'NO')\n", "q = int(input())\npipe = {'1': 1, '2': 1, '3': 2, '4': 2, '5': 2, '6': 2}\nfor i in range(0, q):\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tflag = True\n\tif pipe[a[0]] == 2 and pipe[b[0]] == 1:\n\t\tprint('NO')\n\t\tcontinue\n\tdir = pipe[a[0]]\n\tflag = True\n\tfor j in range(1, len(a)):\n\t\tif dir == 1:\n\t\t\tif pipe[a[j]] == 1:\n\t\t\t\tcontinue\n\t\t\telif pipe[a[j]] != pipe[b[j]]:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tdir = 2\n\t\telif dir == 2:\n\t\t\tif pipe[b[j]] == 1:\n\t\t\t\tcontinue\n\t\t\telif pipe[a[j]] != pipe[b[j]]:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tdir = 1\n\tif flag and dir == 2:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "from collections import deque\nfrom sys import stdin, stdout\ninput = stdin.readline\nt = int(input())\nfor _ in range(t):\n\tn = int(input())\n\ta1 = input()\n\tb1 = input()\n\ta = []\n\tb = []\n\tfor i in range(n):\n\t\ta.append(int(a1[i]))\n\t\tb.append(int(b1[i]))\n\tx = 0\n\tans = 'YES'\n\tfor i in range(n):\n\t\tif i == n - 1:\n\t\t\tif x:\n\t\t\t\tif not (b[i] == 1 or b[i] == 2):\n\t\t\t\t\tans = 'NO'\n\t\t\telif a[i] == 1 or a[i] == 2 or b[i] == 1 or (b[i] == 2):\n\t\t\t\tans = 'NO'\n\t\tif not x:\n\t\t\tif a[i] == 1 or a[i] == 2:\n\t\t\t\tcontinue\n\t\t\telif b[i] == 1 or b[i] == 2:\n\t\t\t\tans = 'NO'\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tx ^= 1\n\t\telif b[i] == 1 or b[i] == 2:\n\t\t\tcontinue\n\t\telif a[i] == 1 or a[i] == 2:\n\t\t\tans = 'NO'\n\t\t\tbreak\n\t\telse:\n\t\t\tx ^= 1\n\tprint(ans)\n", "for case in range(int(input())):\n\tn = int(input())\n\tl1 = list(input())\n\tl2 = list(input())\n\tl1.insert(0, 0)\n\tl2.insert(0, 0)\n\tl = [0, l1, l2]\n\titr = (1, 1)\n\tdirt = 1\n\tfir = True\n\tfl = False\n\twhile True:\n\t\tif itr[1] > n:\n\t\t\tif itr == (2, n + 1):\n\t\t\t\tfl = True\n\t\t\t\tbreak\n\t\t\telif fir:\n\t\t\t\tdirt == -1\n\t\t\t\titr = (1, 1)\n\t\t\t\tfir = False\n\t\t\telse:\n\t\t\t\tbreak\n\t\tif l[itr[0]][itr[1]] == '1' or l[itr[0]][itr[1]] == '2':\n\t\t\tif dirt == 1:\n\t\t\t\titr = (itr[0], itr[1] + 1)\n\t\t\telse:\n\t\t\t\tbreak\n\t\telse:\n\t\t\tif itr[0] == 2 and dirt == 1:\n\t\t\t\titr = (1, itr[1])\n\t\t\telif itr[0] == 1 and dirt == 1:\n\t\t\t\titr = (2, itr[1])\n\t\t\telif dirt == -1:\n\t\t\t\titr = (itr[0], itr[1] + 1)\n\t\t\tdirt = -dirt\n\tprint('Yes' if fl else 'No')\n", "a = int(input())\nfor _ in range(a):\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tfg = 0\n\tfk = 1\n\tfor i in range(n):\n\t\tif int(a[i]) / 2 > 1 and int(b[i]) / 2 <= 1 or (int(a[i]) / 2 <= 1 and int(b[i]) / 2 > 1):\n\t\t\tif not (int(a[i]) / 2 <= 1 and fk == 1 or (int(b[i]) / 2 <= 1 and fk == 2)):\n\t\t\t\tprint('NO')\n\t\t\t\tfg = 1\n\t\t\t\tbreak\n\t\telif int(a[i]) / 2 > 1 and int(b[i]) / 2 > 1:\n\t\t\tfk = 3 - fk\n\tif fg == 0 and fk == 2:\n\t\tprint('YES')\n\telif fg == 0 and fk == 1:\n\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tpipes = [[], []]\n\tlength = int(input())\n\tcurrentX = 0\n\tcurrentY = 0\n\tpipes[0] = input()\n\tpipes[1] = input()\n\thrzn = True\n\twhile 1:\n\t\tif currentX == 1 and currentY == length - 1:\n\t\t\tif hrzn and pipes[currentX][currentY] in ('1', '2') or (not hrzn and pipes[currentX][currentY] not in ('1', '2')):\n\t\t\t\tprint('YES')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\telif currentY > length - 1:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif pipes[currentX][currentY] in ('1', '2'):\n\t\t\tif hrzn:\n\t\t\t\tcurrentY += 1\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\telse:\n\t\t\tif hrzn:\n\t\t\t\tcurrentX += 1\n\t\t\t\tcurrentX %= 2\n\t\t\telse:\n\t\t\t\tcurrentY += 1\n\t\t\thrzn = not hrzn\n", "t = int(input())\nfor _ in range(t):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\ts = [s1, s2]\n\t(tp1, tp2) = (['1', '2'], ['3', '4', '5', '6'])\n\tcur = 0\n\tfor i in range(n):\n\t\tif s[cur][i] in tp1:\n\t\t\tcontinue\n\t\telif s[1 - cur][i] in tp2:\n\t\t\tcur = 1 - cur\n\t\telse:\n\t\t\tprint('NO')\n\t\t\tbreak\n\telse:\n\t\tif cur == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "import re, math, decimal, bisect\n\ndef read():\n\treturn input().strip()\n\ndef iread():\n\treturn int(input().strip())\n\ndef viread():\n\treturn [int(_) for _ in input().strip().split()]\n\ndef round(n):\n\treturn int(n + 0.5)\nDEBUG = 1\nDEBUG = 0\n\ndef debug(*args, **kwargs):\n\tif DEBUG:\n\t\tprint(*args, **kwargs)\nq = iread()\nfor _ in range(q):\n\tn = iread()\n\trow = [read(), read()]\n\tnow = 0\n\tans = 'YES'\n\tfor i in range(n):\n\t\tif row[now][i] > '2' and row[now ^ 1][i] <= '2':\n\t\t\tans = 'NO'\n\t\t\tbreak\n\t\telif row[now][i] > '2':\n\t\t\tnow ^= 1\n\tif ans != 'NO' and now != 1:\n\t\tans = 'NO'\n\tprint(ans)\n", "t = int(input())\nfor i in range(t):\n\tl = int(input())\n\trow1 = list(input())\n\tfor i in range(l):\n\t\trow1[i] = int(row1[i])\n\trow2 = list(input())\n\tfor i in range(l):\n\t\trow2[i] = int(row2[i])\n\tcurr = 0\n\tpipes = [[0] * l for i in range(2)]\n\tflag = 0\n\tfor i in range(2):\n\t\tfor j in range(l):\n\t\t\tif i == 0:\n\t\t\t\tpipes[i][j] = row1[j]\n\t\t\telse:\n\t\t\t\tpipes[i][j] = row2[j]\n\ti = 0\n\twhile i < l - 1:\n\t\tif pipes[curr][i] == 1 or pipes[curr][i] == 2:\n\t\t\ti += 1\n\t\telse:\n\t\t\tcurr = 1 - curr\n\t\t\tif pipes[curr][i] == 1 or pipes[curr][i] == 2:\n\t\t\t\tprint('NO')\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ti += 1\n\tif flag == 1:\n\t\tcontinue\n\tdelta = 0\n\tif curr == 1:\n\t\tif pipes[curr][l - 1] == 1 or pipes[curr][l - 1] == 2:\n\t\t\tdelta = 1\n\telif curr == 0:\n\t\tif pipes[curr][l - 1] == 3 or pipes[curr][l - 1] == 4 or pipes[curr][l - 1] == 5 or (pipes[curr][l - 1] == 6):\n\t\t\tcurr = 1\n\t\t\tif pipes[curr][l - 1] == 3 or pipes[curr][l - 1] == 4 or pipes[curr][l - 1] == 5 or (pipes[curr][l - 1] == 6):\n\t\t\t\tdelta = 1\n\tif delta == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor hoho in range(q):\n\tn = int(input())\n\ta = [input(), input()]\n\tx = 0\n\ty = 0\n\tincome = 1\n\tflag = True\n\twhile x < 2 and y < n:\n\t\tif income == 1:\n\t\t\tif a[x][y] == '1' or a[x][y] == '2':\n\t\t\t\ty = y + 1\n\t\t\telif x == 0:\n\t\t\t\tx = 1\n\t\t\t\tincome = 2\n\t\t\telse:\n\t\t\t\tx = 0\n\t\t\t\tincome = 4\n\t\telif income == 2:\n\t\t\tif a[x][y] == '1' or a[x][y] == '2':\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telif x == 0:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ty += 1\n\t\t\t\tincome = 1\n\t\telif income == 4:\n\t\t\tif a[x][y] == '1' or a[x][y] == '2':\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telif x == 0:\n\t\t\t\ty += 1\n\t\t\t\tincome = 1\n\t\t\telse:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\tif x == 1 and y == n and flag:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tlines = (tuple(map(int, tuple(input()))), tuple(map(int, tuple(input()))))\n\tline = 0\n\ti = 0\n\tfl = False\n\tswitch = False\n\twhile i != n:\n\t\tif lines[line][i] < 3:\n\t\t\ti += 1\n\t\t\tswitch = False\n\t\telif lines[1 - line][i] > 2 and (not switch):\n\t\t\tline = 1 - line\n\t\t\tswitch = True\n\t\telif switch:\n\t\t\ti += 1\n\t\t\tswitch = False\n\t\telse:\n\t\t\tfl = True\n\t\t\tprint('NO')\n\t\t\tbreak\n\tif fl:\n\t\tcontinue\n\tif line == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "t = int(input())\nfor _ in range(t):\n\tn = int(input())\n\ts = [int(x) for x in input()]\n\tt = [int(x) for x in input()]\n\told = [1, 0]\n\tfor i in range(n):\n\t\tnew = [0, 0]\n\t\tif s[i] == 1:\n\t\t\tnew[0] = old[0]\n\t\tif s[i] == 2:\n\t\t\tnew[0] = old[0]\n\t\tif t[i] == 1:\n\t\t\tnew[1] = old[1]\n\t\tif t[i] == 2:\n\t\t\tnew[1] = old[1]\n\t\tif t[i] in (3, 4, 5, 6) and s[i] in (3, 4, 5, 6):\n\t\t\tnew[0] = old[1]\n\t\t\tnew[1] = old[0]\n\t\told = new\n\tprint('YES' if old[1] else 'NO')\n", "q = int(input())\nf = lambda : [*map(int, list(input()))]\nA = [1, 2]\nB = [3, 4, 5, 6]\nfor i in range(q):\n\tsize = int(input())\n\tpipes = [f(), f()]\n\tk = 0\n\tlevel = 0\n\tB_is_first_on_this_level = False\n\tmust_be_B = False\n\twhile k <= size:\n\t\tif k == size and level == 1:\n\t\t\tprint('YES')\n\t\t\tbreak\n\t\telif k == size:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\telse:\n\t\t\tif B_is_first_on_this_level:\n\t\t\t\tif pipes[level][k] not in B:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tB_is_first_on_this_level = False\n\t\t\t\t\tk += 1\n\t\t\t\t\tcontinue\n\t\t\tif pipes[level][k] in A:\n\t\t\t\tk += 1\n\t\t\t\tcontinue\n\t\t\tif pipes[level][k] in B:\n\t\t\t\tlevel ^= 1\n\t\t\t\tB_is_first_on_this_level = True\n\t\t\t\tcontinue\n", "def solve(n, T, B):\n\tX = [False for i in range(n)]\n\tY = [False for i in range(n)]\n\tS = ['1', '2']\n\tC = ['3', '4', '5', '6']\n\tif T[0] in S:\n\t\tX[0] = True\n\t\tY[0] = False\n\telif T[0] in C and B[0] in C:\n\t\tX[0] = False\n\t\tY[0] = True\n\telse:\n\t\tX[0] = False\n\t\tY[0] = False\n\tfor i in range(1, n):\n\t\tif X[i - 1] and T[i] in S or (Y[i - 1] and T[i] in C and (B[i] in C)):\n\t\t\tX[i] = True\n\t\telse:\n\t\t\tX[i] = False\n\t\tif Y[i - 1] and B[i] in S or (X[i - 1] and T[i] in C and (B[i] in C)):\n\t\t\tY[i] = True\n\t\telse:\n\t\t\tY[i] = False\n\tif Y[n - 1]:\n\t\treturn 'YES'\n\telse:\n\t\treturn 'NO'\nq = int(input())\nans = []\nfor j in range(q):\n\tn = int(input())\n\tT = input()\n\tB = input()\n\tans.append(solve(n, T, B))\nprint('\\n'.join(ans))\n", "from math import inf as inf\nimport sys\ninput = sys.stdin.readline\nq = int(input())\nfor i in range(q):\n\tn = int(input())\n\tbends = [0] * n\n\tcount = [0] * n\n\ttwo = 0\n\tl1 = [int(i) for i in input() if i != '\\n']\n\tl2 = [int(i) for i in input() if i != '\\n']\n\tfor i in range(len(l1)):\n\t\tif l1[i] > 2:\n\t\t\tbends[i] += 1\n\tfor i in range(len(l2)):\n\t\tif l2[i] > 2:\n\t\t\tbends[i] += 1\n\t\tif bends[i] == 2:\n\t\t\ttwo += 1\n\t\t\tcount[i] += two\n\tlast = 0\n\tif bends.count(2) % 2 == 1:\n\t\tfor i in range(n):\n\t\t\tif count[i] > 0:\n\t\t\t\tlast = count[i]\n\t\t\tif bends[i] == 1:\n\t\t\t\tif l1[i] > 2 and last % 2 == 0:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\t\telif l2[i] > 2 and last % 2 == 1:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\telse:\n\t\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import math\nimport copy\nt = int(input())\nfor _ in range(t):\n\tn = int(input())\n\tx = input()\n\ty = input()\n\tr = 0\n\tfor i in range(n):\n\t\tif r == 0:\n\t\t\tif x[i] == '1' or x[i] == '2':\n\t\t\t\tr = 0\n\t\t\telse:\n\t\t\t\tr = 1\n\t\t\t\tif y[i] == '1' or y[i] == '2':\n\t\t\t\t\tr = 0\n\t\t\t\t\tbreak\n\t\telif y[i] == '1' or y[i] == '2':\n\t\t\tr = 1\n\t\telse:\n\t\t\tif x[i] == '1' or x[i] == '2':\n\t\t\t\tr = 0\n\t\t\t\tbreak\n\t\t\tr = 0\n\tif r == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "Q = int(input())\nfor q in range(Q):\n\tn = int(input())\n\tc1 = input()\n\tc2 = input()\n\ta = [[None] * n, [None] * n]\n\tfor i in range(n):\n\t\tif c1[i] == '1' or c1[i] == '2':\n\t\t\ta[0][i] = 0\n\t\telse:\n\t\t\ta[0][i] = 1\n\t\tif c2[i] == '1' or c2[i] == '2':\n\t\t\ta[1][i] = 0\n\t\telse:\n\t\t\ta[1][i] = 1\n\tst = 0\n\tfg = 0\n\tfor i in range(n):\n\t\tif a[st][i] == 0:\n\t\t\tcontinue\n\t\telif a[(st + 1) % 2][i] != 1:\n\t\t\tprint('NO')\n\t\t\tfg = 1\n\t\t\tbreak\n\t\telse:\n\t\t\tst = (st + 1) % 2\n\tif fg != 1:\n\t\tif st == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "t = int(input())\nfor i in range(t):\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tq = ['1', '2']\n\tw = ['3', '4', '5', '6']\n\tqw = 1\n\tc = 0\n\ti = 0\n\twhile i < len(a):\n\t\tif a[i] in w:\n\t\t\tif b[i] in q:\n\t\t\t\tqw = 0\n\t\t\t\tbreak\n\t\t\t(a, b) = (b, a)\n\t\t\tc = c + 1\n\t\ti = i + 1\n\tif qw == 1 and c % 2 != 0:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import io, os\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\nii = lambda : int(input())\nkk = lambda : map(int, input().split())\nll = lambda : list(kk())\nfor _ in range(ii()):\n\tn = ii()\n\tloc = 0\n\trs = [input(), input()]\n\tc = 0\n\tdi = 1\n\twhile loc < n:\n\t\tif rs[c][loc] < 51:\n\t\t\tif not di:\n\t\t\t\tbreak\n\t\t\tloc += 1\n\t\telse:\n\t\t\tif not di:\n\t\t\t\tloc += 1\n\t\t\telse:\n\t\t\t\tc ^= 1\n\t\t\tdi ^= 1\n\tprint('YNEOS'[1 ^ (loc == n and c == di == 1)::2])\n", "n = int(input())\n\ndef check(a):\n\tif a in ('3', '4', '5', '6'):\n\t\treturn True\n\telse:\n\t\treturn False\nfor qwer in range(n):\n\tk = int(input())\n\ts1 = input()\n\ts2 = input()\n\ttemp = 1\n\tr = 0\n\tf = False\n\ti = 0\n\twhile i < k:\n\t\tif temp == 1:\n\t\t\tif f:\n\t\t\t\tif check(s1[i]):\n\t\t\t\t\tf = False\n\t\t\t\t\ti += 1\n\t\t\t\telse:\n\t\t\t\t\ttemp = 1\n\t\t\t\t\tbreak\n\t\t\telif check(s1[i]):\n\t\t\t\ttemp = 2\n\t\t\t\tf = True\n\t\t\telse:\n\t\t\t\ti += 1\n\t\t\t\tf = False\n\t\telif f:\n\t\t\tif check(s2[i]):\n\t\t\t\ti += 1\n\t\t\t\tf = False\n\t\t\telse:\n\t\t\t\ttemp = 1\n\t\t\t\tbreak\n\t\telif check(s2[i]):\n\t\t\ttemp = 1\n\t\t\tf = True\n\t\telse:\n\t\t\ti += 1\n\t\t\tf = False\n\tif temp == 2:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\n\nclass Pipes:\n\n\tdef __init__(self):\n\t\tself.upper_pipe = []\n\t\tself.lower_pipe = []\npipes = []\n\ndef pipe_type(x):\n\tif int(x) <= 2:\n\t\treturn 1\n\telse:\n\t\treturn 2\nfor i in range(q):\n\tpipe = Pipes()\n\tinput()\n\tpipe.upper_pipe = [pipe_type(x) for x in input()]\n\tpipe.lower_pipe = [pipe_type(x) for x in input()]\n\tpipes.append(pipe)\nfor pipe in pipes:\n\tin_upper = True\n\tresult = 'YES'\n\tfor i in range(len(pipe.lower_pipe)):\n\t\tif in_upper and pipe.upper_pipe[i] == 1 or (not in_upper and pipe.lower_pipe[i] == 1):\n\t\t\tpass\n\t\telif pipe.upper_pipe[i] == 2 and pipe.lower_pipe[i] == 2:\n\t\t\tin_upper = not in_upper\n\t\telse:\n\t\t\tresult = 'NO'\n\tif in_upper:\n\t\tresult = 'NO'\n\tprint(result)\n", "from sys import stdin, stdout\ncin = stdin.readline\ncout = stdout.write\nfor _ in range(int(cin())):\n\tn = int(cin())\n\tlst = [[None] * n for _ in range(2)]\n\tfor i in range(2):\n\t\tlst[i] = cin()[:-1]\n\t(i, y, u) = (0, 0, 2)\n\twhile i < n:\n\t\tif lst[y][i] < '3':\n\t\t\tif u == 2:\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tcout('NO\\n')\n\t\t\t\tbreak\n\t\telif not y:\n\t\t\tif u == 1:\n\t\t\t\tu = 2\n\t\t\t\ti += 1\n\t\t\telif u == 2:\n\t\t\t\ty += 1\n\t\t\t\tu = 0\n\t\t\telse:\n\t\t\t\tcout('NO\\n')\n\t\t\t\tbreak\n\t\telif y:\n\t\t\tif not u:\n\t\t\t\tu = 2\n\t\t\t\ti += 1\n\t\t\telif u == 2:\n\t\t\t\ty -= 1\n\t\t\t\tu = 1\n\t\t\telse:\n\t\t\t\tcout('NO\\n')\n\t\t\t\tbreak\n\t\telse:\n\t\t\tcout('NO\\n')\n\t\t\tbreak\n\telse:\n\t\tif y:\n\t\t\tcout('YES\\n')\n\t\telse:\n\t\t\tcout('NO\\n')\n", "from bisect import *\nfrom collections import *\nfrom itertools import *\nimport functools\nimport sys\nimport math\nfrom decimal import *\nfrom copy import *\nfrom heapq import *\ngetcontext().prec = 30\nMAX = sys.maxsize\nMAXN = 1000010\nMOD = 10 ** 9 + 7\nspf = [i for i in range(MAXN)]\n\ndef sieve():\n\tfor i in range(2, MAXN, 2):\n\t\tspf[i] = 2\n\tfor i in range(3, int(MAXN ** 0.5) + 1):\n\t\tif spf[i] == i:\n\t\t\tfor j in range(i * i, MAXN, i):\n\t\t\t\tif spf[j] == j:\n\t\t\t\t\tspf[j] = i\n\ndef fib(n, m):\n\tif n == 0:\n\t\treturn [0, 1]\n\telse:\n\t\t(a, b) = fib(n // 2)\n\t\tc = a % m * (b % m * 2 - a % m) % m\n\t\td = a % m * (a % m) % m + b % m * b % m % m\n\t\tif n % 2 == 0:\n\t\t\treturn [c, d]\n\t\telse:\n\t\t\treturn [d, c + d]\n\ndef charIN(x=' '):\n\treturn sys.stdin.readline().strip().split(x)\n\ndef arrIN(x=' '):\n\treturn list(map(int, sys.stdin.readline().strip().split(x)))\n\ndef ncr(n, r):\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % MOD\n\t\tden = den * (i + 1) % MOD\n\treturn num * pow(den, MOD - 2, MOD) % MOD\n\ndef flush():\n\treturn sys.stdout.flush()\nfor _ in range(int(input())):\n\tn = int(input())\n\ta = []\n\tfor i in range(2):\n\t\ta.append([int(i) for i in input()])\n\tif a[0][0] <= 2:\n\t\tcr = 0\n\t\tpr = 0\n\telse:\n\t\tcr = 1\n\t\tif a[1][0] <= 2:\n\t\t\tprint('NO')\n\t\t\tcontinue\n\t\tpr = 1\n\ti = 1\n\tf = 1\n\twhile i < n:\n\t\tif cr == 1:\n\t\t\tif pr == 1:\n\t\t\t\tif a[cr][i] <= 2:\n\t\t\t\t\ti += 1\n\t\t\t\telse:\n\t\t\t\t\tcr = 0\n\t\t\telse:\n\t\t\t\tif a[cr][i] <= 2:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tf = 0\n\t\t\t\t\tbreak\n\t\t\t\tpr = 1\n\t\t\t\ti += 1\n\t\telif pr == 0:\n\t\t\tif a[cr][i] <= 2:\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tcr = 1\n\t\telse:\n\t\t\tif a[cr][i] <= 2:\n\t\t\t\tprint('NO')\n\t\t\t\tf = 0\n\t\t\t\tbreak\n\t\t\tpr = 0\n\t\t\ti += 1\n\tif f:\n\t\tif pr == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "q = int(input())\nfor t in range(q):\n\tn = int(input())\n\ts = [[int(i) for i in list(input())] for j in range(2)]\n\trow = 0\n\tflag = 1\n\tfor i in range(n):\n\t\tif s[row][i] >= 3:\n\t\t\tif s[1 - row][i] < 3:\n\t\t\t\tflag = 0\n\t\t\telse:\n\t\t\t\trow = 1 - row\n\tif flag and row == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nwhile q:\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tflag = True\n\tf1 = True\n\tfor i in range(n):\n\t\tif f1:\n\t\t\tif a[i] in ['3', '4', '5', '6']:\n\t\t\t\tif b[i] in ['1', '2']:\n\t\t\t\t\tflag = False\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tf1 = False\n\t\telif b[i] in ['3', '4', '5', '6']:\n\t\t\tif a[i] in ['1', '2']:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tf1 = True\n\tif flag:\n\t\tif f1:\n\t\t\tprint('NO')\n\t\telse:\n\t\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n\tq -= 1\n", "q = int(input())\nfirst = {1, 2}\nsecond = {3, 4}\nfor _ in range(q):\n\tn = int(input())\n\trow1 = str(input())\n\trow2 = str(input())\n\tcurrent = 2\n\tis_possible = True\n\tfor i in range(n - 1):\n\t\tif current in first:\n\t\t\tif row1[i] in {'3', '4', '5', '6'}:\n\t\t\t\tcurrent += 1\n\t\t\t\tif row2[i] not in {'3', '4', '5', '6'}:\n\t\t\t\t\tis_possible = False\n\t\t\t\t\tbreak\n\t\t\t\tif current == 2:\n\t\t\t\t\tcurrent = 3\n\t\telif current in second:\n\t\t\tif row2[i] in {'3', '4', '5', '6'}:\n\t\t\t\tcurrent += 1\n\t\t\t\tif row1[i] not in {'3', '4', '5', '6'}:\n\t\t\t\t\tis_possible = False\n\t\t\t\t\tbreak\n\t\t\t\tif current == 4:\n\t\t\t\t\tcurrent = 1\n\tif current in first:\n\t\tif row1[n - 1] not in {'3', '4', '5', '6'} or row2[n - 1] not in {'3', '4', '5', '6'}:\n\t\t\tis_possible = False\n\telif current in second:\n\t\tif row2[n - 1] not in {'1', '2'}:\n\t\t\tis_possible = False\n\tif is_possible:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input(''))\nfor _ in range(q):\n\tn = int(input(''))\n\tm = []\n\ta = list(map(int, list(input(''))))\n\tm.append(a)\n\ta = list(map(int, list(input(''))))\n\tm.append(a)\n\tfor i in range(2):\n\t\tfor j in range(n):\n\t\t\tif m[i][j] == 1 or m[i][j] == 2:\n\t\t\t\tm[i][j] = 0\n\t\t\telse:\n\t\t\t\tm[i][j] = 1\n\tres = True\n\tf = 0\n\tfor i in range(n):\n\t\tif m[f][i] == 0:\n\t\t\tcontinue\n\t\telif m[f ^ 1][i] == 1:\n\t\t\tf = f ^ 1\n\t\t\tcontinue\n\t\telse:\n\t\t\tres = False\n\t\t\tbreak\n\tif res:\n\t\tif f == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\telse:\n\t\tprint('NO')\n", "from sys import stdin, stdout\nfrom math import gcd, sqrt, factorial, pi\nfrom collections import deque, defaultdict\ninput = stdin.readline\nR = lambda : map(int, input().split())\nI = lambda : int(input())\nS = lambda : input().rstrip('\\n')\nL = lambda : list(R())\nP = lambda x: stdout.write(x)\nlcm = lambda x, y: x * y // gcd(x, y)\nhg = lambda x, y: (y + x - 1) // x * x\npw = lambda x: 1 if x == 1 else 1 + pw(x // 2)\nchk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False\nsm = lambda x: (x ** 2 + x) // 2\nN = 10 ** 9 + 7\nfor _ in range(I()):\n\tn = I()\n\ta = [[int(i) for i in S()], [int(i) for i in S()]]\n\t(x, y) = (0, 0)\n\tfor i in range(n):\n\t\tif a[x][y] > 2:\n\t\t\tx = (x + 1) % 2\n\t\t\tif a[x][y] <= 2:\n\t\t\t\tbreak\n\t\t\ty += 1\n\t\telse:\n\t\t\ty += 1\n\tif x == 1 and y == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\tch1 = input()\n\tch2 = input()\n\ta = 0\n\tTest = True\n\tnb = 0\n\tfor j in range(n):\n\t\tif a == 0:\n\t\t\tif ch1[j] == '1':\n\t\t\t\ta2 = 0\n\t\t\telif ch1[j] == '2':\n\t\t\t\ta2 = 0\n\t\t\telse:\n\t\t\t\tif ch2[j] == '1' or ch2[j] == '2':\n\t\t\t\t\tTest = False\n\t\t\t\tnb += 1\n\t\t\t\ta2 = 1\n\t\telif a == 1:\n\t\t\tif ch2[j] == '1' or ch2[j] == '2':\n\t\t\t\ta2 = 1\n\t\t\telse:\n\t\t\t\tif ch1[j] == '1' or ch1[j] == '2':\n\t\t\t\t\tTest = False\n\t\t\t\ta2 = 0\n\t\t\t\tnb += 1\n\t\ta = a2\n\tif a == 1 and Test == True:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tcame_from_left = True\n\ttop_row = True\n\tpossible = True\n\tj = 0\n\twhile j < n:\n\t\tif top_row:\n\t\t\tcurrent = int(s1[j])\n\t\telse:\n\t\t\tcurrent = int(s2[j])\n\t\tif current <= 2:\n\t\t\tif not came_from_left:\n\t\t\t\tpossible = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tj += 1\n\t\telif came_from_left:\n\t\t\ttop_row = not top_row\n\t\t\tcame_from_left = False\n\t\telse:\n\t\t\tcame_from_left = True\n\t\t\tj += 1\n\tif possible:\n\t\tif top_row or not came_from_left:\n\t\t\tprint('NO')\n\t\telse:\n\t\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def fastio():\n\timport sys\n\tfrom io import StringIO\n\tfrom atexit import register\n\tglobal input\n\tsys.stdin = StringIO(sys.stdin.read())\n\tinput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\tsys.stdout = StringIO()\n\tregister(lambda : sys.__stdout__.write(sys.stdout.getvalue()))\nfastio()\nMOD = 10 ** 9 + 7\nI = lambda : list(map(int, input().split()))\n(t,) = I()\nwhile t:\n\tt -= 1\n\t(n,) = I()\n\ts = []\n\ts.append(input())\n\ts.append(input())\n\trow = 1\n\tcol = n - 1\n\tans = 'YES'\n\twhile col >= 0:\n\t\tk = int(s[row][col])\n\t\tif k >= 3 and int(s[1 - row][col]) >= 3:\n\t\t\tif row == 1:\n\t\t\t\trow = 0\n\t\t\telse:\n\t\t\t\trow = 1\n\t\telif k >= 3:\n\t\t\tans = 'NO'\n\t\tcol -= 1\n\tif row == 0 and ans == 'YES':\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\ntestcases = int(input())\nstraight = set(['1', '2'])\ncurved = set(['3', '4', '5', '6'])\nfor j in range(testcases):\n\tn = int(input())\n\trow1 = [k for k in input()]\n\trow2 = [k for k in input()]\n\tcur = [1, 1]\n\tprevious = 0\n\tbroke = False\n\ts = 0\n\twhile cur[1] != n + 1:\n\t\tif cur[0] == 1:\n\t\t\tif s == 0:\n\t\t\t\tif row1[cur[1] - 1] in curved:\n\t\t\t\t\tcur[0] = 2\n\t\t\t\t\tprevious = 1\n\t\t\t\telse:\n\t\t\t\t\tcur[1] += 1\n\t\t\t\t\tprevious = 0\n\t\t\telif previous == 0:\n\t\t\t\tif row1[cur[1] - 1] in curved:\n\t\t\t\t\tcur[0] = 2\n\t\t\t\t\tprevious = 1\n\t\t\t\telse:\n\t\t\t\t\tcur[1] += 1\n\t\t\t\t\tprevious = 0\n\t\t\telif row1[cur[1] - 1] in curved:\n\t\t\t\tcur[1] += 1\n\t\t\t\tprevious = 0\n\t\t\telse:\n\t\t\t\tbroke = True\n\t\t\t\tbreak\n\t\telif previous == 0:\n\t\t\tif row2[cur[1] - 1] in curved:\n\t\t\t\tcur[0] = 1\n\t\t\t\tprevious = 1\n\t\t\telse:\n\t\t\t\tcur[1] += 1\n\t\t\t\tprevious = 0\n\t\telif row2[cur[1] - 1] in curved:\n\t\t\tcur[1] += 1\n\t\t\tprevious = 0\n\t\telse:\n\t\t\tbroke = True\n\t\t\tbreak\n\t\ts += 1\n\tif broke == False:\n\t\tif cur[1] == n + 1 and cur[0] == 2:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tup = 1\n\tdown = 0\n\ti = 0\n\tc = 0\n\tn = int(input())\n\tList1 = list(input())\n\tList2 = list(input())\n\twhile i < n:\n\t\tif down == 1:\n\t\t\tif List2[i] > '2':\n\t\t\t\tif List1[i] <= '2':\n\t\t\t\t\tc += 1\n\t\t\t\t\tbreak\n\t\t\t\tdown = 0\n\t\t\t\tup = 1\n\t\telif up == 1:\n\t\t\tif List1[i] > '2':\n\t\t\t\tif List2[i] <= '2':\n\t\t\t\t\tc += 1\n\t\t\t\t\tbreak\n\t\t\t\tdown = 1\n\t\t\t\tup = 0\n\t\ti += 1\n\tif down == 1 and c == 0:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\ninput = sys.stdin.readline\nfor _ in range(int(input())):\n\tN = int(input())\n\tpipe = [list(map(int, input().rstrip())) for _ in range(2)]\n\tdp = [[False] * (N + 1) for _ in range(2)]\n\tdp[0][0] = True\n\tfor i in range(N):\n\t\tif pipe[0][i] <= 2 and dp[0][i]:\n\t\t\tdp[0][i + 1] = True\n\t\tif pipe[1][i] <= 2 and dp[1][i]:\n\t\t\tdp[1][i + 1] = True\n\t\tif pipe[0][i] > 2 and pipe[1][i] > 2:\n\t\t\tif dp[0][i]:\n\t\t\t\tdp[1][i + 1] = True\n\t\t\tif dp[1][i]:\n\t\t\t\tdp[0][i + 1] = True\n\tif dp[1][-1]:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def numberstotypes(pipes):\n\tfor i in range(2):\n\t\tfor j in range(len(pipes[i])):\n\t\t\tif pipes[i][j] in {'1', '2'}:\n\t\t\t\tpipes[i][j] = 'A'\n\t\t\telse:\n\t\t\t\tpipes[i][j] = 'B'\n\treturn pipes\n\ndef main():\n\tqueries = int(input())\n\tfor query in range(queries):\n\t\tn = int(input())\n\t\tpipes = [list(input()), list(input())]\n\t\tpipes = numberstotypes(pipes)\n\t\t(level, pos, ans) = (0, 0, True)\n\t\twhile pos < n:\n\t\t\tif pipes[level][pos] == 'A':\n\t\t\t\tpos += 1\n\t\t\telif pipes[1 - level][pos] == 'B':\n\t\t\t\tlevel = 1 - level\n\t\t\t\tpos += 1\n\t\t\telse:\n\t\t\t\tans = False\n\t\t\t\tbreak\n\t\tif ans == True and (level != 1 or pos != n):\n\t\t\tans = False\n\t\tif ans:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\nmain()\n", "for _ in range(int(input())):\n\tn = int(input())\n\tarr1 = list(input())\n\tarr2 = list(input())\n\tmatrix = [arr1, arr2]\n\tflag = 0\n\tfinal = 0\n\tfor i in range(len(arr1)):\n\t\tif int(matrix[flag][i]) <= 2:\n\t\t\tcontinue\n\t\telse:\n\t\t\tflag = flag ^ 1\n\t\t\tif int(matrix[flag][i]) > 2:\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tfinal = 1\n\t\t\t\tbreak\n\t\tprint('flag ', flag)\n\tif final == 0:\n\t\tif flag == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tS = [s1, s2]\n\td = [1, 0]\n\tit = 0\n\ti = 0\n\tflag = True\n\twhile i < n:\n\t\tif S[it % 2][i] != '1' and S[it % 2][i] != '2':\n\t\t\tif S[d[it]][i] == '1' or S[d[it]][i] == '2':\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tit = d[it]\n\t\ti += 1\n\tif it % 2 == 0 or not flag:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\trows = [None, None]\n\trows[0] = list(map(int, list(input())))\n\trows[1] = list(map(int, list(input())))\n\ty = 0\n\tx = 0\n\tresult = True\n\tlast = 0\n\twhile True:\n\t\tif rows[y][x] == 1 or rows[y][x] == 2:\n\t\t\tif last == 1:\n\t\t\t\tresult = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tx += 1\n\t\t\t\tlast = 0\n\t\telif last == 1:\n\t\t\tx += 1\n\t\t\tlast = 2\n\t\telse:\n\t\t\tif y == 0:\n\t\t\t\ty = 1\n\t\t\telse:\n\t\t\t\ty = 0\n\t\t\tlast = 1\n\t\tif x == n:\n\t\t\tresult = y == 1\n\t\t\tbreak\n\tif result:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\ninput = sys.stdin.readline\nt = 1\nt = int(input())\nfor _ in range(t):\n\tn = int(input())\n\ta = [input().split() for x in range(2)]\n\tcurr = 0\n\trow = 0\n\tflag = 0\n\twhile curr < n:\n\t\tif a[row][0][curr] == '1' or a[row][0][curr] == '2':\n\t\t\tcurr += 1\n\t\telse:\n\t\t\tif row == 0:\n\t\t\t\trow = 1\n\t\t\telse:\n\t\t\t\trow = 0\n\t\t\tif a[row][0][curr] == '1' or a[row][0][curr] == '2':\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tcurr += 1\n\tif row == 0 or flag == 1:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "q = int(input())\nfor _ in range(q):\n\ts = ['' for i in range(2)]\n\tn = int(input())\n\ts[0] = input()\n\ts[1] = input()\n\trow = 0\n\tpos = 0\n\tfor i in range(n):\n\t\tif s[row][i] >= '3':\n\t\t\tif s[row ^ 1][i] < '3':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\trow ^= 1\n\t\tpos += 1\n\tif row == 1 and pos == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for q in range(int(input())):\n\tn = int(input())\n\ta = list(input())\n\tb = list(input())\n\tflag = 1\n\tl = ['3', '4', '5', '6']\n\ti = 0\n\tj = 1\n\twhile i < n:\n\t\tif j == 1:\n\t\t\tif a[i] in ['1', '2']:\n\t\t\t\tpass\n\t\t\telif a[i] in l and b[i] in l:\n\t\t\t\tj = 2\n\t\t\telse:\n\t\t\t\tflag = 0\n\t\t\t\tbreak\n\t\telif j == 2:\n\t\t\tif b[i] in ['1', '2']:\n\t\t\t\tpass\n\t\t\telif b[i] in l and a[i] in l:\n\t\t\t\tj = 1\n\t\t\telse:\n\t\t\t\tflag = 0\n\t\t\t\tbreak\n\t\ti += 1\n\tif flag == 1 and j == 2:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys, re, math\nfrom collections import deque, defaultdict, Counter, OrderedDict\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\nfrom heapq import heappush, heappop, heapify, nlargest, nsmallest\n\ndef STR():\n\treturn list(input())\n\ndef INT():\n\treturn int(input())\n\ndef MAP():\n\treturn map(int, input().split())\n\ndef LIST():\n\treturn list(map(int, input().split()))\n\ndef list2d(a, b, c):\n\treturn [[c] * b for i in range(a)]\n\ndef sortListWithIndex(listOfTuples, idx):\n\treturn sorted(listOfTuples, key=lambda x: x[idx])\n\ndef sortDictWithVal(passedDic):\n\ttemp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]\n\ttoret = {}\n\tfor tup in temp:\n\t\ttoret[tup[0]] = tup[1]\n\treturn toret\n\ndef sortDictWithKey(passedDic):\n\treturn dict(OrderedDict(sorted(passedDic.items())))\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\nt = INT()\nwhile t != 0:\n\tn = INT()\n\tgrid = []\n\tgrid.append(list(input()))\n\tgrid.append(list(input()))\n\tcurRow = 0\n\tcurCol = 0\n\tprev = 0\n\tendAt = 1\n\twhile curCol < n:\n\t\tch = grid[curRow][curCol]\n\t\tif ch == '1' or ch == '2':\n\t\t\tif endAt == 1:\n\t\t\t\tcurCol += 1\n\t\t\t\tprev = 0\n\t\t\telse:\n\t\t\t\tbreak\n\t\telif prev == 1:\n\t\t\tcurCol += 1\n\t\t\tprev = 0\n\t\t\tendAt = 1\n\t\telse:\n\t\t\tcurRow ^= 1\n\t\t\tprev = 1\n\t\t\tendAt = 0\n\tif curRow == 1 and curCol == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n\tt -= 1\n", "for _ in range(int(input())):\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tx = [[i for i in a]] + [[j for j in b]]\n\td = 1\n\ti = 0\n\tj = 0\n\twhile True:\n\t\tif x[i][j] == '1' or x[i][j] == '2':\n\t\t\tif d == 1:\n\t\t\t\tif j == n - 1 and i == 1:\n\t\t\t\t\tprint('YES')\n\t\t\t\t\tbreak\n\t\t\t\telif j == n - 1:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tj += 1\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\telif x[i][j] in '3456':\n\t\t\tif d == 1:\n\t\t\t\tif i == 0:\n\t\t\t\t\ti = 1\n\t\t\t\t\td = 2\n\t\t\t\telif i == 1:\n\t\t\t\t\ti = 0\n\t\t\t\t\td = -2\n\t\t\telif d == 2 or d == -2:\n\t\t\t\tif j == n - 1:\n\t\t\t\t\tif i == 0:\n\t\t\t\t\t\tprint('NO')\n\t\t\t\t\telse:\n\t\t\t\t\t\tprint('YES')\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\td = 1\n\t\t\t\t\tj += 1\n", "def my_func(n, A, B):\n\tr = 0\n\tbul = True\n\ts = 0\n\tfor i in range(n):\n\t\tif int(A[i]) > 2 and int(B[i]) > 2:\n\t\t\ts += 1\n\t\t\tr = (r + 1) % 2\n\t\telif 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)):\n\t\t\tbul = False\n\t\t\tbreak\n\treturn bul and s % 2 == 1\nq = int(input())\nfor j in range(q):\n\tn = int(input())\n\tA = input()\n\tB = input()\n\tif my_func(n, A, B):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor qi in range(q):\n\tn = int(input())\n\tgrid = [[0 for i in range(2)] for j in range(n)]\n\trow1 = input()\n\trow2 = input()\n\tfor i in range(n):\n\t\tif row1[i] == '1' or row1[i] == '2':\n\t\t\tgrid[i][0] = 1\n\t\tif row2[i] == '1' or row2[i] == '2':\n\t\t\tgrid[i][1] = 1\n\t(inversions, y) = (0, 0)\n\tpossible = 'YES'\n\tfor i in range(n):\n\t\tif grid[i][0] + grid[i][1] == 0:\n\t\t\tinversions += 1\n\t\t\ty += 1\n\t\t\ty %= 2\n\t\telif grid[i][y] != 1:\n\t\t\tpossible = 'NO'\n\tif possible == 'NO' or inversions % 2 == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "import os, sys, math\nimport collections\nif os.path.exists('testing'):\n\tname = os.path.basename(__file__)\n\tif name.endswith('.py'):\n\t\tname = name[:-3]\n\tsrc = open(name + '.in.txt', encoding='utf8')\n\tinput = src.readline\n\ndef solve(row1, row2):\n\tmp = {'1': 1, '2': 1, '3': 2, '4': 2, '5': 2, '6': 2}\n\trow1 = [mp[q] for q in row1]\n\trow2 = [mp[q] for q in row2]\n\tcurrent_row = 0\n\tcurrent_col = 0\n\trows = [row1, row2]\n\tlength = len(row1)\n\twhile True:\n\t\tif current_col == length:\n\t\t\treturn current_row == 1\n\t\tp = rows[current_row][current_col]\n\t\tif p != 1:\n\t\t\tnew_row = 1 - current_row\n\t\t\tnew_p = rows[new_row][current_col]\n\t\t\tif new_p != 2:\n\t\t\t\treturn False\n\t\t\tcurrent_row = new_row\n\t\tcurrent_col += 1\nq = int(input().strip())\nfor _ in range(q):\n\tn = int(input().strip())\n\trow1 = input().strip()\n\trow2 = input().strip()\n\tr = solve(row1, row2)\n\tprint('YES' if r else 'NO')\n", "q = int(input())\nwhile q:\n\tq += -1\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tt = s1\n\tch = 'YES'\n\tfor i in range(n):\n\t\tif t[i] == '1' or t[i] == '2':\n\t\t\tcontinue\n\t\telif t == s1:\n\t\t\tif s2[i] == '1' or s2[i] == '2':\n\t\t\t\tch = 'NO'\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tt = s2\n\t\telif t == s2:\n\t\t\tif s1[i] == '1' or s1[i] == '2':\n\t\t\t\tch = 'NO'\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tt = s1\n\tif t == s1:\n\t\tprint('NO')\n\telse:\n\t\tprint(ch)\n", "from collections import defaultdict as dc\nfrom collections import deque as dq\nimport sys\nimport math\nmod = 10 ** 9 + 7\n\ndef inp():\n\tp = sys.stdin.readline()\n\treturn p\nq = int(inp())\nfor _ in range(q):\n\tn = int(inp())\n\ta = str(input())\n\tb = str(input())\n\tp = []\n\tq = []\n\t(z1, z2) = (0, 0)\n\tfor i in range(n):\n\t\tif a[i] == '1' or a[i] == '2':\n\t\t\tp.append(0)\n\t\telse:\n\t\t\tz1 += 1\n\t\t\tp.append(1)\n\t\tif b[i] == '1' or b[i] == '2':\n\t\t\tq.append(0)\n\t\telse:\n\t\t\tz2 += 1\n\t\t\tq.append(1)\n\tif z1 == 0 or z2 == 0:\n\t\tprint('NO')\n\telse:\n\t\tif p[0] == 0:\n\t\t\tx = 0\n\t\t\tans = 0\n\t\t\tfor i in range(1, n):\n\t\t\t\tif x == 0:\n\t\t\t\t\tif p[i] == 0:\n\t\t\t\t\t\tx = 0\n\t\t\t\t\telif q[i] == 0:\n\t\t\t\t\t\tans = 1\n\t\t\t\t\t\tbreak\n\t\t\t\t\telse:\n\t\t\t\t\t\tx = 1\n\t\t\t\telif x == 1:\n\t\t\t\t\tif q[i] == 0:\n\t\t\t\t\t\tx = 1\n\t\t\t\t\telif p[i] == 0:\n\t\t\t\t\t\tans = 1\n\t\t\t\t\t\tbreak\n\t\t\t\t\telse:\n\t\t\t\t\t\tx = 0\n\t\telse:\n\t\t\tx = 1\n\t\t\tif q[0] == 0:\n\t\t\t\tans = 1\n\t\t\telse:\n\t\t\t\tans = 0\n\t\t\t\tfor i in range(1, n):\n\t\t\t\t\tif x == 0:\n\t\t\t\t\t\tif p[i] == 0:\n\t\t\t\t\t\t\tx = 0\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\telif q[i] == 0:\n\t\t\t\t\t\t\tans = 1\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\telse:\n\t\t\t\t\t\t\tx = 1\n\t\t\t\t\telif x == 1:\n\t\t\t\t\t\tif q[i] == 0:\n\t\t\t\t\t\t\tx = 1\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\telif p[i] == 0:\n\t\t\t\t\t\t\tans = 1\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\telse:\n\t\t\t\t\t\t\tx = 0\n\t\tif x == 0 or ans == 1:\n\t\t\tprint('NO')\n\t\telse:\n\t\t\tprint('YES')\n", "def solve(n, line1, line2):\n\tway = 'h'\n\tlevel = 0\n\ti = 0\n\twhile i < n:\n\t\tp = line1[i] if level == 0 else line2[i]\n\t\tif way == 'v':\n\t\t\tif p in ['1', '2']:\n\t\t\t\treturn 'NO'\n\t\t\telse:\n\t\t\t\tway = 'h'\n\t\t\t\ti += 1\n\t\telif p in ['1', '2']:\n\t\t\ti += 1\n\t\telse:\n\t\t\tway = 'v'\n\t\t\tlevel = (level + 1) % 2\n\tif level == 0:\n\t\treturn 'NO'\n\treturn 'YES'\nfor _ in range(int(input())):\n\tn = int(input())\n\tline1 = input()\n\tline2 = input()\n\tprint(solve(n, line1, line2))\n", "q = int(input())\nfor _ in range(0, q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tflag = 0\n\tfor j in range(0, n):\n\t\tif flag == 0 and s1[j] <= '2':\n\t\t\tcontinue\n\t\telif flag == 1 and s2[j] <= '2':\n\t\t\tcontinue\n\t\telif flag == 0 and s1[j] > '2' and (s2[j] > '2'):\n\t\t\tflag += 1\n\t\telif flag == 1 and s2[j] > '2' and (s1[j] > '2'):\n\t\t\tflag -= 1\n\t\telse:\n\t\t\tflag = 0\n\t\t\tbreak\n\tif flag == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tA = [None]\n\tB = [None]\n\tfor i in input():\n\t\tif i == '1' or i == '2':\n\t\t\tA.append(0)\n\t\telse:\n\t\t\tA.append(1)\n\tfor i in input():\n\t\tif i == '1' or i == '2':\n\t\t\tB.append(0)\n\t\telse:\n\t\t\tB.append(1)\n\tF1 = [0 for i in range(n + 1)]\n\tF1[0] = 1\n\ttemp = 1\n\tfor i in range(1, len(A) - 1):\n\t\tif temp == 1:\n\t\t\tF1[i] = 1\n\t\t\tif A[i] == 0:\n\t\t\t\ttemp = 1\n\t\t\telif A[i] == 1 and B[i] == 0:\n\t\t\t\tF1[i] = 0\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ttemp = 2\n\t\telse:\n\t\t\tF1[i] = 1\n\t\t\tif B[i] == 0:\n\t\t\t\ttemp = 2\n\t\t\telif B[i] == 1 and A[i] == 0:\n\t\t\t\tF1[i] = 0\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ttemp = 1\n\tif F1[n - 1] == 1:\n\t\tif temp == 1:\n\t\t\tif A[n] == 1 and B[n] == 1:\n\t\t\t\tF1[n] = 1\n\t\t\telse:\n\t\t\t\tF1[n] = 0\n\t\telif B[n] == 0:\n\t\t\tF1[n] = 1\n\t\telse:\n\t\t\tF1[n] = 0\n\tflag = False\n\tfor i in range(1, n + 1):\n\t\tif F1[i] == 0:\n\t\t\tflag = True\n\t\t\tbreak\n\tif flag:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tL1 = [0] * n\n\tL2 = [0] * n\n\tptr = 1\n\tflag = 0\n\tif s1[0] == '1' or s1[0] == '2':\n\t\tL1[0] = 1\n\t\tptr = 1\n\telif int(s2[0]) > 2:\n\t\tL2[0] = 1\n\t\tptr = 2\n\telse:\n\t\tflag = 1\n\tfor i in range(1, len(s1)):\n\t\tif flag == 1:\n\t\t\tbreak\n\t\tif ptr == 1:\n\t\t\tif s1[i] == '1' or s1[i] == '2':\n\t\t\t\tL1[i] = 1\n\t\t\telif int(s2[i]) > 2:\n\t\t\t\tL2[i] = 1\n\t\t\t\tptr = 2\n\t\t\telse:\n\t\t\t\tflag = 1\n\t\telif s2[i] == '1' or s2[i] == '2':\n\t\t\tL2[i] = 1\n\t\telif int(s1[i]) > 2:\n\t\t\tL1[i] = 1\n\t\t\tptr = 1\n\t\telse:\n\t\t\tflag = 1\n\tif L2[-1] == 1 and flag == 0:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\n\ndef main():\n\n\tdef input():\n\t\treturn sys.stdin.readline()[:-1]\n\tq = int(input())\n\tfor _ in range(q):\n\t\tn = int(input())\n\t\ts1 = input()\n\t\ts2 = input()\n\t\tc = ['3', '4', '5', '6']\n\t\ty = 0\n\t\tf = 1\n\t\tfor now in range(n):\n\t\t\tif y == 0:\n\t\t\t\tif s1[now] == '1' or s1[now] == '2':\n\t\t\t\t\tpass\n\t\t\t\telif s1[now] in c and s2[now] in c:\n\t\t\t\t\ty = 1\n\t\t\t\telse:\n\t\t\t\t\tf = 0\n\t\t\t\t\tbreak\n\t\t\telif s2[now] == '1' or s2[now] == '2':\n\t\t\t\tpass\n\t\t\telif s1[now] in c and s2[now] in c:\n\t\t\t\ty = 0\n\t\t\telse:\n\t\t\t\tf = 0\n\t\t\t\tbreak\n\t\tif f == 0 or y == 0:\n\t\t\tprint('NO')\n\t\telse:\n\t\t\tprint('YES')\nmain()\n", "count = int(input())\nresult = []\nfor _ in range(count):\n\tnum = int(input())\n\tpipes_1 = list(map(lambda num: int(num), list(input())))\n\tpipes_2 = list(map(lambda num: int(num), list(input())))\n\tcurve = [3, 4, 5, 6]\n\tst = [1, 2]\n\tindex = 0\n\tdirection = 0\n\twhile index < num:\n\t\tif pipes_1[index] in curve and pipes_2[index] in curve:\n\t\t\tindex += 1\n\t\t\tif direction == 1:\n\t\t\t\tdirection = 0\n\t\t\telse:\n\t\t\t\tdirection = 1\n\t\telif direction == 0 and pipes_1[index] in st or (direction == 1 and pipes_2[index] in st):\n\t\t\tindex += 1\n\t\telif pipes_1[index] in st and pipes_2[index] in curve:\n\t\t\tbreak\n\t\telif pipes_2[index] in st and pipes_1[index] in curve:\n\t\t\tbreak\n\t\telif direction == 1 and index == num - 1 and (pipes_2[index] in st):\n\t\t\tindex += 1\n\t\telse:\n\t\t\tbreak\n\tif num == index and direction == 1:\n\t\tresult.append('YES')\n\telse:\n\t\tresult.append('NO')\nprint('\\n'.join(result))\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tmat = []\n\tmat.append(input())\n\tmat.append(input())\n\ttp = lambda x: 1 if int(x) < 3 else 2\n\trow = 0\n\tcan = True\n\tfor i in range(n):\n\t\tif tp(mat[row][i]) == 2:\n\t\t\trow = 1 if row == 0 else 0\n\t\t\tif tp(mat[row][i]) == 1:\n\t\t\t\tcan = False\n\t\t\t\tbreak\n\tprint('YES' if can and row == 1 else 'NO')\n\twhile True:\n\t\tbreak\n\t\tif tp(mat[row][col]) == 1:\n\t\t\tcol += 1\n\t\t\tptp = 1\n\t\telse:\n\t\t\tif ptp == 1:\n\t\t\t\trow = 0 if row == 1 else 1\n\t\t\telse:\n\t\t\t\tcol += 1\n\t\t\tptp = 2\n", "q = int(input())\nHORIZONTAL = 1\nVERTICAL = 2\nfor i in range(q):\n\tn = int(input())\n\tmapa = [None, None]\n\tmapa[0] = [int(i) for i in list(input())]\n\tmapa[1] = [int(i) for i in list(input())]\n\tx = 0\n\ty = 0\n\tmov = HORIZONTAL\n\twhile True:\n\t\tif x == n and y == 1:\n\t\t\tprint('YES')\n\t\t\tbreak\n\t\tif x >= n:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tatual = mapa[y][x]\n\t\tif atual == -1:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif atual <= 2:\n\t\t\tif mov == VERTICAL:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\tmov = HORIZONTAL\n\t\telif mov == HORIZONTAL:\n\t\t\tmov = VERTICAL\n\t\telse:\n\t\t\tmov = HORIZONTAL\n\t\tmapa[y][x] = -1\n\t\tif mov == HORIZONTAL:\n\t\t\tx += 1\n\t\telif mov == VERTICAL:\n\t\t\tif y == 0:\n\t\t\t\ty = 1\n\t\t\telse:\n\t\t\t\ty = 0\n", "q = int(input())\nI = {'1', '2'}\nV = {'3', '4', '5', '6'}\nfor case in range(q):\n\tn = int(input())\n\ta = ['$' + input(), '$' + input()]\n\tdp = [[False for _ in range(1 + n)], [False for _ in range(1 + n)]]\n\tdp[0][0] = True\n\tfor i in range(1, 1 + n):\n\t\tif a[0][i] in I:\n\t\t\tdp[0][i] = dp[0][i - 1]\n\t\tif a[1][i] in I:\n\t\t\tdp[1][i] = dp[1][i - 1]\n\t\tif a[0][i] in V and a[1][i] in V:\n\t\t\tdp[0][i] = dp[0][i] or dp[1][i - 1]\n\t\t\tdp[1][i] = dp[1][i] or dp[0][i - 1]\n\tprint('YES' if dp[1][n] else 'NO')\n", "for q in range(int(input())):\n\tcontrol = 0\n\tflag = 0\n\tn = int(input())\n\tra = list(map(int, list(input().strip())))\n\trb = list(map(int, list(input().strip())))\n\tr = [ra, rb]\n\tfor x in range(n):\n\t\tif r[control][x] in [1, 2]:\n\t\t\tpass\n\t\telif r[1 - control][x] in [3, 4, 5, 6]:\n\t\t\tcontrol = 1 - control\n\t\telse:\n\t\t\tflag = 1\n\t\t\tbreak\n\tif flag == 0 and control == 1:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tk = input()\n\tp = input()\n\ta = list(k)\n\tb = list(p)\n\tlis = [a, b]\n\tk = 'Yes'\n\tr = 0\n\tfor i in range(n):\n\t\tif lis[r][i] in '12':\n\t\t\tcontinue\n\t\telif lis[r ^ 1][i] not in '12':\n\t\t\tr ^= 1\n\t\t\tcontinue\n\t\telse:\n\t\t\tk = 'No'\n\t\t\tbreak\n\tif r == 0:\n\t\tk = 'No'\n\tprint(k)\n", "straight = set([1, 2])\nnstraight = set([3, 4, 5, 6])\nfor _ in range(int(input())):\n\tn = int(input())\n\tr1 = [int(x) for x in input().strip()]\n\tr2 = [int(x) for x in input().strip()]\n\tposs = [True, False]\n\tfor i in range(n):\n\t\tpossnew = [False, False]\n\t\tif poss[0] and r1[i] in straight:\n\t\t\tpossnew[0] = True\n\t\tif poss[1] and r2[i] in straight:\n\t\t\tpossnew[1] = True\n\t\tif r1[i] in nstraight and r2[i] in nstraight:\n\t\t\tif poss[0]:\n\t\t\t\tpossnew[1] = True\n\t\t\tif poss[1]:\n\t\t\t\tpossnew[0] = True\n\t\tposs = possnew\n\tif poss[1]:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "from collections import defaultdict as dc\nimport sys\nimport math\ninput = sys.stdin.readline\nfor _ in range(int(input())):\n\tn = int(input())\n\tl = []\n\tfor i in range(2):\n\t\tl.append(input()[:-1])\n\tr = 0\n\tf = 0\n\ti = 0\n\twhile i < n:\n\t\tif l[r][i] >= '3':\n\t\t\tif l[1 - r][i] < '3':\n\t\t\t\tf = 1\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tr = 1 - r\n\t\ti += 1\n\tif i == n and r == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\nq = int(sys.stdin.readline())\nfor i in range(q):\n\tn = int(sys.stdin.readline())\n\ts1 = sys.stdin.readline()\n\ts2 = sys.stdin.readline()\n\ts = [s1, s2]\n\tposition = (0, 0)\n\tbad = False\n\tprevious = (0, -1)\n\twhile 0 <= position[0] <= 1 and 0 <= position[1] < n:\n\t\t(x, y) = position\n\t\tif s[x][y] < '3':\n\t\t\tif previous[0] == x:\n\t\t\t\tprevious = position\n\t\t\t\tposition = (x, y + 1)\n\t\t\telse:\n\t\t\t\tbad = True\n\t\t\t\tbreak\n\t\telif previous[0] == x:\n\t\t\tprevious = position\n\t\t\tposition = ((x + 1) % 2, y)\n\t\telse:\n\t\t\tprevious = position\n\t\t\tposition = (x, y + 1)\n\tif bad or position != (1, n):\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "def run():\n\tn = eval(input())\n\tvals = []\n\tfor _ in range(n):\n\t\tinput()\n\t\trow1 = input()\n\t\trow2 = input()\n\t\tvals.append([row1, row2])\n\tpipes = dict()\n\tpipes['left_to_right'] = 1\n\tpipes['up_to_down'] = 1\n\tpipes['down_to_up'] = 1\n\tpipes['left_to_down'] = 6\n\tpipes['left_to_up'] = 6\n\tpipes['right_to_down'] = 6\n\tpipes['right_to_up'] = 6\n\tpipes['down_to_right'] = 6\n\tpipes['down_to_left'] = 6\n\tpipes['up_to_right'] = 6\n\tpipes['up_to_left'] = 6\n\tdirections = dict()\n\tdirections[1] = [1, 2]\n\tdirections[6] = [3, 4, 5, 6]\n\tfor i in range(n):\n\t\trow1 = [int(ch) for ch in vals[i][0]]\n\t\trow2 = [int(ch) for ch in vals[i][1]]\n\t\trows = [row1, row2]\n\t\tcurrent_row = 0\n\t\tcurrent_col = 0\n\t\tcurrent = 'left'\n\t\tj = 0\n\t\tnext_direction = None\n\t\twhile j < len(row1):\n\t\t\tcurrent_pipe = rows[current_row][j]\n\t\t\tnext_direction = None\n\t\t\tpossible_directions = []\n\t\t\tfor key in pipes.keys():\n\t\t\t\tif key.startswith(current) and current_pipe in directions[pipes[key]]:\n\t\t\t\t\tpossible_directions.append(key.split('_')[2])\n\t\t\tif 'right' in possible_directions and (current_col < len(row1) - 1 and current_row == 0 or (current_col < len(row1) and current_row == 1)):\n\t\t\t\tnext_direction = 'right'\n\t\t\telif 'left' in possible_directions and current_col > 0:\n\t\t\t\tnext_direction = 'left'\n\t\t\telif 'up' in possible_directions and current_row == 1:\n\t\t\t\tnext_direction = 'up'\n\t\t\telif 'down' in possible_directions and current_row == 0:\n\t\t\t\tnext_direction = 'down'\n\t\t\tif next_direction is None:\n\t\t\t\tbreak\n\t\t\tif next_direction != 'right' and current_row == 1 and (current_col == len(row1) - 1) and (j == len(row1) - 1):\n\t\t\t\tbreak\n\t\t\tif next_direction == 'right':\n\t\t\t\tcurrent = 'left'\n\t\t\t\tj += 1\n\t\t\t\tcurrent_col += 1\n\t\t\telif next_direction == 'left':\n\t\t\t\tcurrent = 'right'\n\t\t\t\tj -= 1\n\t\t\t\tcurrent_col -= 1\n\t\t\telif next_direction == 'up':\n\t\t\t\tcurrent = 'down'\n\t\t\t\tcurrent_row -= 1\n\t\t\telif next_direction == 'down':\n\t\t\t\tcurrent = 'up'\n\t\t\t\tcurrent_row += 1\n\t\tif j == len(row1) and current_col == len(row1) and (current_row == 1) and (next_direction == 'right'):\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\nrun()\n", "def yes_or_no(row1, row2, n):\n\tflag = False\n\tx = 0\n\ty = 0\n\twhile x < n:\n\t\trow = {0: row1, 1: row2}[y]\n\t\tfig = row[x]\n\t\tif fig == 1 or fig == 2:\n\t\t\tif flag:\n\t\t\t\treturn 'NO'\n\t\t\tx += 1\n\t\telif flag:\n\t\t\tx += 1\n\t\t\tflag = False\n\t\telse:\n\t\t\ty = 0 if y == 1 else 1\n\t\t\tflag = True\n\tif y == 1:\n\t\treturn 'YES'\n\telse:\n\t\treturn 'NO'\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\trow1 = list(map(int, input()))\n\trow2 = list(map(int, input()))\n\tprint(yes_or_no(row1, row2, n))\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ttb = [list(map(int, input())) for _ in range(2)]\n\t(x, y) = (0, 0)\n\tsl = True\n\twhile y < n:\n\t\tif tb[x][y] < 3 and sl:\n\t\t\ty += 1\n\t\t\tsl = True\n\t\telif tb[x][y] >= 3 and sl:\n\t\t\tx ^= 1\n\t\t\tsl = False\n\t\telif tb[x][y] >= 3 and (not sl):\n\t\t\ty += 1\n\t\t\tsl = True\n\t\telse:\n\t\t\tbreak\n\tif x == 1 and y == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "t = int(input())\nfor i in range(t):\n\tn = int(input())\n\tarr1 = input()\n\tarr1 = list(arr1)\n\tarr2 = input()\n\tarr2 = list(arr2)\n\tarr = []\n\tarr.append(arr1)\n\tarr.append(arr2)\n\trow = 0\n\tcol = 0\n\tj = 0\n\tflag = 0\n\twhile col < n:\n\t\tif arr[row][col] == '1' or arr[row][col] == '2':\n\t\t\tcol += 1\n\t\telif arr[1 - row][col] == '1' or arr[1 - row][col] == '2':\n\t\t\tprint('NO')\n\t\t\tflag = 1\n\t\t\tbreak\n\t\telse:\n\t\t\tcol += 1\n\t\t\trow = 1 - row\n\tif flag == 0 and col == n and (row == 1):\n\t\tprint('YES')\n\telif flag == 0 and (col != n or row != 1):\n\t\tprint('NO')\n", "for tc in range(int(input())):\n\tn = int(input())\n\trow = [[int(x) for x in list(input())], [int(x) for x in list(input())]]\n\trowPos = 0\n\tfor i in range(n):\n\t\tif row[rowPos][i] == 1 or row[rowPos][i] == 2:\n\t\t\tcontinue\n\t\trowPos = 0 if rowPos == 1 else 1\n\t\tif row[rowPos][i] == 1 or row[rowPos][i] == 2:\n\t\t\tprint('NO')\n\t\t\tbreak\n\telse:\n\t\tif rowPos == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "t = int(input())\nfor ts in range(t):\n\tl = int(input())\n\ta = [int(i) >= 3 for i in list(input())]\n\ta = [a, [int(i) >= 3 for i in list(input())]]\n\tw = 0\n\tfor i in range(l):\n\t\tif a[0][i] and a[1][i]:\n\t\t\tw = (w + 1) % 2\n\t\telif a[w][i]:\n\t\t\tw = 0\n\t\t\tbreak\n\tif w == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "for i in range(int(input())):\n\tq = int(input())\n\tw = input()\n\te = input()\n\tr = w\n\tk = 0\n\tl = 0\n\tp = 0\n\tfor i in range(q):\n\t\tif r[i] != '1' and r[i] != '2':\n\t\t\tif k == 0:\n\t\t\t\tr = e\n\t\t\t\tp = 1\n\t\t\t\tk = 1\n\t\t\telse:\n\t\t\t\tk = 0\n\t\t\t\tr = w\n\t\t\t\tp = 0\n\t\t\tif r[i] == '1' or r[i] == '2':\n\t\t\t\tprint('NO')\n\t\t\t\tl = 1\n\t\t\t\tbreak\n\tif l != 1 and p == 1:\n\t\tprint('YES')\n\telif l != 1:\n\t\tprint('NO')\n", "import sys, math, queue, collections\nMOD = 10 ** 9 + 7\nsys.setrecursionlimit(1000000)\n\ndef solve():\n\tn = int(input())\n\ta = []\n\ta.append(list(map(int, list(input()))))\n\ta.append(list(map(int, list(input()))))\n\tdp = [[[False for i in range(7)] for i in range(n)] for i in range(2)]\n\tif a[0][0] <= 2:\n\t\tdp[0][0][2] = True\n\telse:\n\t\tdp[0][0][4] = True\n\t\tif a[1][0] <= 2:\n\t\t\tdp[1][0][1] = True\n\t\telse:\n\t\t\tdp[1][0][5] = dp[1][0][6] = True\n\tfor i in range(1, n):\n\t\tif a[0][i] <= 2:\n\t\t\tdp[0][i][2] = dp[0][i - 1][2] or dp[0][i - 1][3]\n\t\t\tif a[1][i] <= 2:\n\t\t\t\tdp[1][i][2] = dp[1][i - 1][2] or dp[1][i - 1][6]\n\t\t\telse:\n\t\t\t\tdp[1][i][5] = dp[1][i - 1][2] or dp[1][i - 1][6]\n\t\telse:\n\t\t\tdp[0][i][4] = dp[0][i - 1][2] or dp[0][i - 1][3]\n\t\t\tif a[1][i] <= 2:\n\t\t\t\tdp[1][i][2] = dp[1][i - 1][2] or dp[1][i - 1][6]\n\t\t\telse:\n\t\t\t\tdp[1][i][6] = dp[0][i][4]\n\t\t\t\tdp[1][i][5] = dp[1][i - 1][2] or dp[1][i - 1][6]\n\t\t\tdp[0][i][3] = dp[1][i][5]\n\tans = dp[1][n - 1][2] or dp[1][n - 1][6]\n\tprint('YES' if ans else 'NO')\nfor _ in range(int(input())):\n\tsolve()\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\trow1 = input()\n\trow2 = input()\n\tpos = (0, 0)\n\tturn = '3456'\n\tstraight = '12'\n\twhile pos != (1, n) and pos[1] < n:\n\t\tif pos[0] == 0:\n\t\t\tif row1[pos[1]] in turn:\n\t\t\t\tif row2[pos[1]] in turn:\n\t\t\t\t\tpos = (1, pos[1] + 1)\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tpos = (0, pos[1] + 1)\n\t\telif pos[0] == 1:\n\t\t\tif row2[pos[1]] in turn:\n\t\t\t\tif row1[pos[1]] in turn:\n\t\t\t\t\tpos = (0, pos[1] + 1)\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tpos = (1, pos[1] + 1)\n\tif pos == (1, n):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tfieldInLinesOfArray = (tuple(map(int, tuple(input()))), tuple(map(int, tuple(input()))))\n\tfieldInLine = 0\n\tYesNoFlag = False\n\tYesNoFlagOfswitching = False\n\ti = 0\n\twhile i != n:\n\t\tif fieldInLinesOfArray[fieldInLine][i] < 3:\n\t\t\ti += 1\n\t\t\tYesNoFlagOfswitching = False\n\t\telif fieldInLinesOfArray[1 - fieldInLine][i] > 2 and (not YesNoFlagOfswitching):\n\t\t\tfieldInLine = 1 - fieldInLine\n\t\t\tYesNoFlagOfswitching = True\n\t\telif YesNoFlagOfswitching:\n\t\t\ti += 1\n\t\t\tYesNoFlagOfswitching = False\n\t\telse:\n\t\t\tYesNoFlag = True\n\t\t\tprint('NO')\n\t\t\tbreak\n\tif YesNoFlag:\n\t\tcontinue\n\tif fieldInLine == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def dfs():\n\tif nl[0][0] in R1:\n\t\td = 0\n\telse:\n\t\td = 1\n\tst = [[0, 0, d]]\n\twhile st:\n\t\t(x, y, d) = st.pop()\n\t\tif x == N - 1 and y == 1:\n\t\t\tif d == 0:\n\t\t\t\treturn True\n\t\t\telse:\n\t\t\t\treturn False\n\t\tif d == 0:\n\t\t\ttx = x + 1\n\t\t\tty = y\n\t\t\tif tx < N and 0 <= ty < 2:\n\t\t\t\tif nl[ty][tx] in R1:\n\t\t\t\t\tst.append([tx, ty, d])\n\t\t\t\telif ty == 0:\n\t\t\t\t\tst.append([tx, ty, 1])\n\t\t\t\telse:\n\t\t\t\t\tst.append([tx, ty, 2])\n\t\telse:\n\t\t\ttx = x\n\t\t\tif d == 1:\n\t\t\t\tty = y + 1\n\t\t\telse:\n\t\t\t\tty = y - 1\n\t\t\tif nl[ty][tx] not in R1:\n\t\t\t\tst.append([tx, ty, 0])\n\treturn False\nR1 = {'1', '2'}\nT = int(input())\nfor t in range(T):\n\tN = int(input())\n\tnl = [list(input()) for _ in range(2)]\n\tif dfs():\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\ts1 = str(input())\n\ts2 = str(input())\n\td = [s1, s2]\n\trow = 0\n\tfor i in range(n):\n\t\tif int(d[row][i]) > 2:\n\t\t\trow ^= 1\n\t\t\tif int(d[row][i]) <= 2:\n\t\t\t\trow = 0\n\t\t\t\tbreak\n\tif row == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "from typing import Tuple, List, Dict\n\nclass PipeType:\n\tSTRAIGHT = 1\n\tBENT = 2\n\nclass Board:\n\n\tdef __init__(self, num_of_cols: int, pipes: Tuple[List[int], List[int]]):\n\t\tself.num_of_cols = num_of_cols\n\t\tself.verticals = {'top': Board.init_false_array(num_of_cols + 1), 'bottom': Board.init_false_array(num_of_cols + 1)}\n\t\tself.pipes = {'top': list(map(Board.transform_pipe_type, pipes[0])), 'bottom': list(map(Board.transform_pipe_type, pipes[1]))}\n\t\tself.verticals['top'][0] = True\n\n\t@staticmethod\n\tdef transform_pipe_type(original_pipe_type: int):\n\t\tif original_pipe_type in [1, 2]:\n\t\t\treturn PipeType.STRAIGHT\n\t\telse:\n\t\t\treturn PipeType.BENT\n\n\tdef __connect(self, col_num: int):\n\t\tfor row in ['top', 'bottom']:\n\t\t\tif self.pipes[row][col_num] == PipeType.STRAIGHT:\n\t\t\t\tself.verticals[row][col_num + 1] |= self.verticals[row][col_num]\n\t\tif self.pipes['top'][col_num] == PipeType.BENT and self.pipes['bottom'][col_num] == PipeType.BENT:\n\t\t\tself.verticals['top'][col_num + 1] |= self.verticals['bottom'][col_num]\n\t\t\tself.verticals['bottom'][col_num + 1] |= self.verticals['top'][col_num]\n\n\t@staticmethod\n\tdef init_false_array(length: int):\n\t\treturn [False] * length\n\n\tdef __connect_all(self):\n\t\tfor i in range(self.num_of_cols):\n\t\t\tself.__connect(i)\n\n\tdef connected(self) -> bool:\n\t\tself.__connect_all()\n\t\treturn self.verticals['bottom'][self.num_of_cols]\n\ndef test():\n\tassert Board(7, ([2, 3, 2, 3, 2, 1, 6], [1, 6, 1, 5, 1, 2, 4])).connected()\n\tassert Board(1, ([3], [4])).connected()\n\tassert Board(2, ([1, 3], [2, 4])).connected()\n\tassert not Board(2, ([1, 2], [3, 4])).connected()\n\tassert Board(3, ([5, 3, 6], [3, 4, 5])).connected()\n\tassert not Board(2, ([4, 6], [5, 4])).connected()\nq = int(input())\nfor __ in range(q):\n\tn = int(input())\n\ttop = [int(c) for c in input()]\n\tbottom = [int(c) for c in input()]\n\tif Board(n, (top, bottom)).connected():\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\n(ans, f) = ([], True)\nfor i in range(q):\n\tn = int(input())\n\tl = [input().replace('1', '-').replace('2', '-').replace('3', '*').replace('4', '*').replace('5', '*').replace('6', '*') for i in (1, 2)]\n\tf = True\n\trow = 0\n\tfor j in range(n):\n\t\tif l[row][j] == '-':\n\t\t\tcontinue\n\t\telif l[row ^ 1][j] == '*':\n\t\t\trow ^= 1\n\t\telse:\n\t\t\tf = False\n\t\t\tbreak\n\tif f and row:\n\t\tans.append('YES')\n\telse:\n\t\tans.append('NO')\nprint(*ans, sep='\\n')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tpipe = []\n\tpipe.append(a)\n\tpipe.append(b)\n\tpos = 0\n\tans = True\n\tfor i in range(n):\n\t\tif pipe[pos][i] > '2':\n\t\t\tpos = 1 - pos\n\t\t\tif pipe[pos][i] <= '2':\n\t\t\t\tans = False\n\t\t\t\tbreak\n\tif pos == 0:\n\t\tans = False\n\tif ans:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "st = ['1', '2']\ntera = ['3', '4', '5', '6']\nfor _ in range(int(input())):\n\tn = int(input())\n\tli = [[], []]\n\tli[0] = input()\n\tli[1] = input()\n\tj = 0\n\tflag = 1\n\ti = 0\n\twhile i < n:\n\t\tif li[j][i] in st:\n\t\t\ti += 1\n\t\telif j == 0:\n\t\t\tif li[1][i] not in tera:\n\t\t\t\tflag = 0\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tj = 1\n\t\t\t\ti += 1\n\t\telif li[0][i] not in tera:\n\t\t\tflag = 0\n\t\t\tbreak\n\t\telse:\n\t\t\tj = 0\n\t\t\ti += 1\n\tif flag == 1 and j == 1:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n", "t = int(input())\nwhile t:\n\tn = int(input())\n\tr1 = input()\n\tr2 = input()\n\tlol = 1\n\tpr = 1\n\ti = 0\n\twhile i < n:\n\t\tif lol == 1:\n\t\t\tif (r1[i] == '1' or r1[i] == '2') and pr == 2:\n\t\t\t\tlol = 1\n\t\t\t\tbreak\n\t\t\telif (r1[i] == '1' or r1[i] == '2') and pr == 1:\n\t\t\t\ti += 1\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tif pr == 1:\n\t\t\t\t\tlol = 2\n\t\t\t\telif pr == 2:\n\t\t\t\t\tlol = 1\n\t\t\t\t\ti += 1\n\t\t\t\tpr = 1\n\t\telif (r2[i] == '1' or r2[i] == '2') and pr == 1:\n\t\t\tlol = 1\n\t\t\tbreak\n\t\telif (r2[i] == '1' or r2[i] == '2') and pr == 2:\n\t\t\ti += 1\n\t\t\tcontinue\n\t\telse:\n\t\t\tif pr == 1:\n\t\t\t\tlol = 2\n\t\t\t\ti += 1\n\t\t\telif pr == 2:\n\t\t\t\tlol = 1\n\t\t\tpr = 2\n\tif lol == 2:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n\tt -= 1\n", "for _ in range(int(input())):\n\tn = int(input())\n\tplum = [list(map(int, list(input()))), list(map(int, list(input())))]\n\th = 0\n\tanswer = 'YES'\n\tfor i in range(n):\n\t\tif plum[h][i] > 2:\n\t\t\tif plum[(h + 1) % 2][i] > 2:\n\t\t\t\th = (h + 1) % 2\n\t\t\telse:\n\t\t\t\tanswer = 'NO'\n\t\t\t\tbreak\n\tif h != 1:\n\t\tanswer = 'NO'\n\tprint(answer)\n", "for _ in range(int(input())):\n\tn = int(input())\n\tr1 = [list(input()), list(input())]\n\t(i, j) = (0, 0)\n\tpi = 0\n\twhile j <= n:\n\t\tif j == n:\n\t\t\tif i == 1:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\tbreak\n\t\telif i == pi:\n\t\t\tif r1[i][j] in ['1', '2']:\n\t\t\t\tj += 1\n\t\t\t\tpi = i\n\t\t\telse:\n\t\t\t\tpi = i\n\t\t\t\ti ^= 1\n\t\telif r1[i][j] in ['1', '2']:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\telse:\n\t\t\tj += 1\n\t\t\tpi = i\n", "import string\nimport sys\ninput = sys.stdin.readline\n\ndef getInts():\n\treturn [int(s) for s in input().split()]\n\ndef getInt():\n\treturn int(input())\n\ndef getStrs():\n\treturn [s for s in input().split()]\n\ndef getStr():\n\treturn input().strip()\n\ndef listStr():\n\treturn list(input().strip())\nimport collections as col\nimport math, itertools\n\ndef solve():\n\tN = getInt()\n\tA = [int(s) for s in input().strip()]\n\tB = [int(s) for s in input().strip()]\n\tpos = [0, 0]\n\tleft_flag = True\n\twhile True:\n\t\tarr = A if pos[0] == 0 else B\n\t\tif left_flag:\n\t\t\tif arr[pos[1]] <= 2:\n\t\t\t\tpos[1] += 1\n\t\t\telse:\n\t\t\t\tpos[0] = 1 - pos[0]\n\t\t\t\tleft_flag = False\n\t\telif arr[pos[1]] <= 2:\n\t\t\treturn 'NO'\n\t\telse:\n\t\t\tpos[1] += 1\n\t\t\tleft_flag = True\n\t\tif pos == [1, N]:\n\t\t\treturn 'YES'\n\t\tif pos[1] == N:\n\t\t\treturn 'NO'\nfor _ in range(getInt()):\n\tprint(solve())\n", "for _ in range(int(input())):\n\tn = int(input())\n\tl1 = input()\n\tl2 = input()\n\tarr = [l1, l2]\n\tposition = 0\n\tfor i in range(n):\n\t\tif arr[position][i] > '2':\n\t\t\tposition = 1 - position\n\t\t\tif arr[position][i] <= '2':\n\t\t\t\tposition = 0\n\t\t\t\tbreak\n\tif position:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import math\nline = [1, 2]\ncircle = [3, 4, 5, 6]\n\ndef Pipes(n_, l1, l2):\n\tflag = 0\n\tfor i in range(0, n_):\n\t\tif flag == 0:\n\t\t\tif l1[i] in line:\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tif l2[i] in line:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\treturn\n\t\t\t\tflag = 1\n\t\telif l2[i] in line:\n\t\t\tcontinue\n\t\telse:\n\t\t\tif l1[i] in line:\n\t\t\t\tprint('NO')\n\t\t\t\treturn\n\t\t\tflag = 0\n\tif flag == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\nn = int(input())\nfor i in range(0, n):\n\tn_ = int(input())\n\tl1 = list(map(int, input().rstrip().strip()))\n\tl2 = list(map(int, input().rstrip().strip()))\n\tPipes(n_, l1, l2)\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\tpole = []\n\ta = input()\n\tb = input()\n\tpole.append(a)\n\tpole.append(b)\n\tj = 0\n\tk = 0\n\tlast = 0\n\tt = False\n\twhile True:\n\t\tif k >= 2 or j >= n:\n\t\t\tbreak\n\t\tif last == 0 and (pole[k][j] == '1' or pole[k][j] == '2'):\n\t\t\tj += 1\n\t\telif last != 0 and (pole[k][j] == '1' or pole[k][j] == '2'):\n\t\t\tt = True\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\telif last == 0 and k == 0:\n\t\t\tk += 1\n\t\t\tlast = 1\n\t\telif last == 0 and k == 1:\n\t\t\tk -= 1\n\t\t\tlast = 1\n\t\telif last == 1:\n\t\t\tlast = 0\n\t\t\tj += 1\n\tif not t:\n\t\tif k == 1 and j >= n:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\ta = list(input())\n\tb = list(input())\n\tc = 1\n\tk = 0\n\tfor i in range(n):\n\t\tif c == 1:\n\t\t\tif a[i] != '1' and a[i] != '2':\n\t\t\t\tc = 0\n\t\t\t\tif b[i] == '1' or b[i] == '2':\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tk = 1\n\t\t\t\t\tbreak\n\t\telif b[i] != '1' and b[i] != '2':\n\t\t\tc = 1\n\t\t\tif a[i] == '1' or a[i] == '2':\n\t\t\t\tprint('NO')\n\t\t\t\tk = 1\n\t\t\t\tbreak\n\tif k == 1:\n\t\tcontinue\n\tif c == 1:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ts1 = list(input())\n\ts2 = list(input())\n\tpos = 0\n\tflag = False\n\tfor i in range(len(s1)):\n\t\tx = int(s1[i])\n\t\ty = int(s2[i])\n\t\tif pos == 0:\n\t\t\tif x <= 2 and y <= 2:\n\t\t\t\tpass\n\t\t\telif x <= 2 and y > 2:\n\t\t\t\tpass\n\t\t\telif x > 2 and y <= 2:\n\t\t\t\tflag = True\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tpos = 1\n\t\telif x <= 2 and y <= 2:\n\t\t\tpass\n\t\telif x <= 2 and y > 2:\n\t\t\tflag = True\n\t\t\tbreak\n\t\telif x > 2 and y <= 2:\n\t\t\tpass\n\t\telse:\n\t\t\tpos = 0\n\tprint('NO') if pos == 0 or flag else print('YES')\n", "def solver():\n\tT = int(input().strip())\n\tfor case in range(T):\n\t\tn = int(input().strip())\n\t\ts = []\n\t\ts.append(input())\n\t\ts.append(input())\n\t\tans = [[0 for i in range(n + 1)] for j in range(5)]\n\t\tans[1][0] = 1\n\t\tfor i in range(n):\n\t\t\tt1 = 1 if s[0][i] in ('1', '2') else 2\n\t\t\tt2 = 1 if s[1][i] in ('1', '2') else 2\n\t\t\tif ans[1][i] == 1:\n\t\t\t\tif t1 == 1:\n\t\t\t\t\tans[1][i + 1] = 1\n\t\t\t\telse:\n\t\t\t\t\tans[4][i] = 1\n\t\t\tif ans[3][i] == 1:\n\t\t\t\tif t2 == 1:\n\t\t\t\t\tans[3][i + 1] = 1\n\t\t\t\telse:\n\t\t\t\t\tans[2][i] = 1\n\t\t\tif ans[2][i] == 1 and t1 == 2:\n\t\t\t\tans[1][i + 1] = 1\n\t\t\tif ans[4][i] == 1 and t2 == 2:\n\t\t\t\tans[3][i + 1] = 1\n\t\tif ans[3][n] == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\ndef main():\n\twhile True:\n\t\ttry:\n\t\t\tsolver()\n\t\texcept EOFError:\n\t\t\tbreak\nmain()\n", "for _ in range(int(input())):\n\tn = int(input())\n\ts = []\n\ts.append(input())\n\ts.append(input())\n\tk = 0\n\tfor i in range(n):\n\t\tif s[k % 2][i] in ('1', '2'):\n\t\t\tcontinue\n\t\tif s[(k + 1) % 2][i] not in ('3', '4', '5', '6'):\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tk += 1\n\telse:\n\t\tif k % 2 == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "from collections import deque, defaultdict\nfrom math import sqrt, ceil, factorial, floor, inf, gcd, log\nimport bisect\nimport sys\nimport copy\n\ndef get_array():\n\treturn list(map(int, sys.stdin.readline().strip().split()))\n\ndef get_ints():\n\treturn map(int, sys.stdin.readline().strip().split())\n\ndef input():\n\treturn sys.stdin.readline().strip()\nfor _ in range(int(input())):\n\tn = int(input())\n\tf = input()\n\ts = input()\n\tarr = [[f[i], s[i]] for i in range(n)]\n\tends = 0\n\tok = True\n\tfor i in range(n):\n\t\tif arr[i][ends] >= '3':\n\t\t\tif arr[i][ends ^ 1] < '3':\n\t\t\t\tok = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tends ^= 1\n\tif ok and ends == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\nq = int(sys.stdin.readline())\nwhile q:\n\tq -= 1\n\tn = int(sys.stdin.readline())\n\tpipe = [[], []]\n\tpip_type = {1: 1, 2: 1, 3: 2, 4: 2, 5: 2, 6: 2}\n\tfor i in range(2):\n\t\ttmp = map(int, sys.stdin.readline().rstrip())\n\t\tpipe[i] = [pip_type[k] for k in tmp]\n\tstate = [1, 0]\n\tSUCCESS = True\n\tfor i in range(n):\n\t\tif not state[0] and (not state[1]):\n\t\t\tSUCCESS = False\n\t\t\tbreak\n\t\ttmp = [0, 0]\n\t\tif state[0]:\n\t\t\ttmp[0] = 1 if pipe[0][i] == 1 else 0\n\t\t\ttmp[1] = 1 if pipe[0][i] == 2 and pipe[1][i] == 2 else 0\n\t\tif state[1]:\n\t\t\ttmp[1] = 1 if tmp[1] or pipe[1][i] == 1 else 0\n\t\t\ttmp[0] = 1 if tmp[0] or (pipe[0][i] == 2 and pipe[1][i] == 2) else 0\n\t\tstate = tmp\n\tif SUCCESS and state[1]:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ttube = [[0] * 2 for i in range(n + 1)]\n\ta = [int(x) for x in list(input())]\n\tb = [int(x) for x in list(input())]\n\tk = 0\n\tfor i in range(n):\n\t\tif a[i] == 1 or a[i] == 2:\n\t\t\ttube[i][0] = 1\n\t\tif b[i] == 1 or b[i] == 2:\n\t\t\ttube[i][1] = 1\n\tfor i in range(n):\n\t\tif tube[i][k] == 0:\n\t\t\tif tube[i][(k + 1) % 2] == 0:\n\t\t\t\tk = (k + 1) % 2\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\telse:\n\t\tif k == 0:\n\t\t\tprint('NO')\n\t\telse:\n\t\t\tprint('YES')\n", "q = int(input())\nj = 0\nj1 = 0\nfinal = []\n\ndef super():\n\tglobal j, j1\n\tl = int(input())\n\tx1 = input()\n\ty1 = input()\n\tx = [[int(xx) for xx in str(x1)], [int(xx) for xx in str(y1)]]\n\tglobal j\n\tfor j in [0, 1]:\n\t\tfor i in range(0, len(x[j])):\n\t\t\tif x[j][i] in [1, 2]:\n\t\t\t\tx[j][i] = 0\n\t\t\telse:\n\t\t\t\tx[j][i] = 1\n\tj = 0\n\tj1 = 0\n\n\tdef next():\n\t\tglobal j, j1\n\t\tj1 = j\n\t\tif j == 0:\n\t\t\tj = 1\n\t\t\treturn 1\n\t\telse:\n\t\t\tj = 0\n\t\t\treturn 0\n\tflip = False\n\ti = 0\n\twhile i < l - 1:\n\t\tif x[j][i] == 1:\n\t\t\tif not flip:\n\t\t\t\tflip = True\n\t\t\t\tif x[next()][i] != 1:\n\t\t\t\t\tfinal.append('NO')\n\t\t\t\t\treturn\n\t\t\telse:\n\t\t\t\tflip = False\n\t\t\t\ti += 1\n\t\telse:\n\t\t\ti += 1\n\tif 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):\n\t\tfinal.append('YES')\n\telse:\n\t\tfinal.append('NO')\nfor i in range(0, q):\n\tsuper()\nfor t in final:\n\tprint(t)\n", "Q = int(input())\n\ndef solve():\n\tN = int(input())\n\ttop = [int(x) > 2 for x in input()]\n\tbot = [int(x) > 2 for x in input()]\n\tdp = [set() for _ in range(N)]\n\tflows = {}\n\tflows[0, 0] = [(0, 0), (1, 1)]\n\tflows[0, 1] = [(0, 0)]\n\tflows[1, 0] = [(1, 1)]\n\tflows[1, 1] = [(0, 1), (1, 0)]\n\tfor i in range(N - 1, -1, -1):\n\t\ttp = (top[i], bot[i])\n\t\tif i == N - 1:\n\t\t\tfor f in flows[tp]:\n\t\t\t\tif f[1] == 1:\n\t\t\t\t\tdp[i].add(f)\n\t\telse:\n\t\t\tfor f in flows[tp]:\n\t\t\t\tfor n in dp[i + 1]:\n\t\t\t\t\tif f[1] == n[0]:\n\t\t\t\t\t\tdp[i].add(f)\n\tfor x in dp[0]:\n\t\tif x[0] == 0:\n\t\t\treturn True\n\treturn False\nfor _ in range(Q):\n\tprint('YES' if solve() else 'NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tlayer = False\n\tfor i in range(n):\n\t\tif layer:\n\t\t\tif s2[i] in ['6', '5', '3', '4']:\n\t\t\t\tif s1[i] in ['6', '5', '3', '4']:\n\t\t\t\t\tlayer = not layer\n\t\t\t\telse:\n\t\t\t\t\tlayer = False\n\t\t\t\t\tbreak\n\t\telif s1[i] in ['6', '5', '3', '4']:\n\t\t\tif s2[i] in ['6', '5', '3', '4']:\n\t\t\t\tlayer = not layer\n\t\t\telse:\n\t\t\t\tlayer = False\n\t\t\t\tbreak\n\tif layer:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "line = {1, 2}\nugol = {3, 4, 5, 6}\nq = int(input())\nfor ii in range(q):\n\tn = int(input())\n\ta = [int(i) for i in input()]\n\tb = [int(i) for i in input()]\n\tt = 1\n\tfor i in range(n):\n\t\tif t == 0:\n\t\t\tbreak\n\t\tif t == 1 and a[i] in line:\n\t\t\tcontinue\n\t\tif t == 1 and a[i] in ugol and (b[i] in ugol):\n\t\t\tt = 2\n\t\t\tcontinue\n\t\tif t == 2 and b[i] in line:\n\t\t\tcontinue\n\t\tif t == 2 and b[i] in ugol and (a[i] in ugol):\n\t\t\tt = 1\n\t\t\tcontinue\n\t\tif t == 3:\n\t\t\tif a[i] in line and b[i] in line:\n\t\t\t\tcontinue\n\t\t\tif a[i] in ugol and b[i] in ugol:\n\t\t\t\tcontinue\n\t\t\tif a[i] in line:\n\t\t\t\tt = 1\n\t\t\t\tcontinue\n\t\t\tif b[i] in line:\n\t\t\t\tt = 2\n\t\t\t\tcontinue\n\t\tt = 0\n\t\tbreak\n\tif t == 0 or t == 1:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tr1 = input()\n\tr2 = input()\n\tr = [r1, r2]\n\tfrom_side = True\n\tfrom_up = True\n\tpos = 0\n\tpossible = True\n\twhile pos < n:\n\t\tif from_side:\n\t\t\tif r[0 if from_up else 1][pos] in '12':\n\t\t\t\tpos += 1\n\t\t\telse:\n\t\t\t\tfrom_side = False\n\t\t\t\tfrom_up = from_up\n\t\telif r[1 if from_up else 0][pos] in '12':\n\t\t\tpossible = False\n\t\t\tbreak\n\t\telse:\n\t\t\tpos += 1\n\t\t\tfrom_side = True\n\t\t\tfrom_up = not from_up\n\tif from_up:\n\t\tpossible = False\n\tif possible:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "x = lambda i: 1 if i in ['1', '2'] else 0\n\ndef is_possible(m, d, i, j, n):\n\twhile True:\n\t\tif j == n:\n\t\t\treturn 'NO' if i == 0 else 'YES'\n\t\tif i == 0:\n\t\t\tif d == 'e':\n\t\t\t\tif m[i][j] == 1:\n\t\t\t\t\tj += 1\n\t\t\t\telse:\n\t\t\t\t\td = 'd'\n\t\t\t\t\ti = 1\n\t\t\telif d == 'u':\n\t\t\t\tif m[i][j] == 1:\n\t\t\t\t\treturn 'NO'\n\t\t\t\telse:\n\t\t\t\t\td = 'e'\n\t\t\t\t\tj += 1\n\t\t\telse:\n\t\t\t\treturn 'NO'\n\t\telif d == 'd':\n\t\t\tif m[i][j] == 1:\n\t\t\t\treturn 'NO'\n\t\t\telse:\n\t\t\t\tj += 1\n\t\t\t\td = 'e'\n\t\telif d == 'e':\n\t\t\tif m[i][j] == 1:\n\t\t\t\tj += 1\n\t\t\telse:\n\t\t\t\td = 'u'\n\t\t\t\ti = 0\n\t\telse:\n\t\t\treturn 'NO'\nfor _ in range(int(input())):\n\tn = int(input())\n\tm = [list(map(x, input().strip())) for _ in range(2)]\n\tprint(is_possible(m, 'e', 0, 0, n))\n", "q = int(input())\nh = {1: 0, 2: 0, 3: 1, 4: 1, 5: 1, 6: 1}\nfor w in range(q):\n\tn = int(input())\n\ta = [[int(i) for i in input()] for j in range(2)]\n\tdp = [[False for i in range(n)] for j in range(2)]\n\tif h[a[0][0]] == 1 and h[a[1][0]] == 0:\n\t\tprint('NO')\n\telse:\n\t\tif h[a[0][0]] == 0:\n\t\t\tk = 0\n\t\telse:\n\t\t\tk = 1\n\t\tdp[k][0] = True\n\t\tf = 1\n\t\tfor i in range(1, n):\n\t\t\tif h[a[k][i]] == 0:\n\t\t\t\tdp[k][i] = True\n\t\t\telif h[a[1 - k][i]] == 0:\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tk = 1 - k\n\t\t\t\tdp[k][i] = True\n\t\tif dp[1][n - 1] == True:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "from sys import stdin\nfrom collections import defaultdict\np_type = {1: 1, 2: 1, 3: 2, 4: 2, 5: 2, 6: 2}\n\ndef c_poss(l1, l2, n):\n\tlvl = 0\n\tfor i in range(n):\n\t\tc_p = l1[i] if lvl == 0 else l2[i]\n\t\tp_t = p_type[c_p]\n\t\tif p_t == 1:\n\t\t\tif i == n - 1:\n\t\t\t\treturn lvl\n\t\telse:\n\t\t\tlvl = 1 - lvl\n\t\t\tn_p = l1[i] if lvl == 0 else l2[i]\n\t\t\tif p_type[n_p] == 1:\n\t\t\t\treturn False\n\t\t\telif i == n - 1:\n\t\t\t\treturn lvl\nfor _ in range(int(stdin.readline())):\n\tn = int(stdin.readline())\n\tl1 = list(map(int, list(stdin.readline().rstrip())))\n\tl2 = list(map(int, list(stdin.readline().rstrip())))\n\tprint('YES' if c_poss(l1, l2, n) else 'NO')\n", "def changerow(crow):\n\tif crow == 0:\n\t\tcrow = 1\n\telse:\n\t\tcrow = 0\n\treturn crow\nt = int(input())\nd = {'s': (1, 2), 'c': (3, 4, 5, 6)}\nwhile t > 0:\n\tt -= 1\n\tn = int(input())\n\tr1 = input()\n\tr2 = input()\n\tmat = [[int(i) for i in r1], [int(i) for i in r2]]\n\tcrow = 0\n\tprv = mat[0][0]\n\tflag = 0\n\tfor i in range(n):\n\t\tele = mat[crow][i]\n\t\tif ele == 1 or ele == 2:\n\t\t\tcontinue\n\t\telse:\n\t\t\tcrow2 = changerow(crow)\n\t\t\tif mat[crow][i] >= 3 and mat[crow2][i] >= 3:\n\t\t\t\tcrow = changerow(crow)\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\tif flag == 1:\n\t\tprint('NO')\n\telif crow == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\ta = [[int(x) for x in input()] for i in range(2)]\n\tcur = 0\n\tfor i in range(n):\n\t\tif a[0][i] > 2 and a[1][i] > 2:\n\t\t\tcur ^= 1\n\t\telif a[cur][i] > 2:\n\t\t\tprint('NO')\n\t\t\tbreak\n\telse:\n\t\tprint('YES' if cur == 1 else 'NO')\n", "def solve(n, a):\n\tp = 0\n\tif n == 1:\n\t\treturn 'YES' if a[0][0] == a[1][0] == 2 else 'NO'\n\tfor i in range(n):\n\t\tif a[p][i] == 2:\n\t\t\tif a[p ^ 1][i] == 2:\n\t\t\t\tp ^= 1\n\t\t\telse:\n\t\t\t\treturn 'NO'\n\treturn 'YES' if p == 1 else 'NO'\n\ndef main():\n\tq = int(input())\n\tfor i in range(q):\n\t\tn = int(input())\n\t\ta = []\n\t\ta.append([1 if int(x) == 1 or int(x) == 2 else 2 for x in input()])\n\t\ta.append([1 if int(x) == 1 or int(x) == 2 else 2 for x in input()])\n\t\tprint(solve(n, a))\nmain()\n", "t = int(input())\nfor i in range(t):\n\tn = int(input())\n\ttubes = []\n\tfor j in range(2):\n\t\ttubes.append(list(map(int, list(input()))))\n\tr = [0, 0]\n\tfl_ord = False\n\twhile True:\n\t\tif tubes[r[0]][r[1]] <= 2:\n\t\t\tif fl_ord:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tr[1] += 1\n\t\telse:\n\t\t\tif fl_ord:\n\t\t\t\tr[1] += 1\n\t\t\telse:\n\t\t\t\tr[0] = 1 - r[0]\n\t\t\tfl_ord = not fl_ord\n\t\tif r == [1, n]:\n\t\t\tprint('YES')\n\t\t\tbreak\n\t\telif r == [0, n]:\n\t\t\tprint('NO')\n\t\t\tbreak\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ta = [input(), input()]\n\tans = True\n\tx = 0\n\ty = 0\n\th = 0\n\twhile True:\n\t\tif y >= n:\n\t\t\tif x == 0:\n\t\t\t\tans = False\n\t\t\tbreak\n\t\tif x == 0 and y == 0:\n\t\t\tif a[0][0] < '3':\n\t\t\t\ty = 1\n\t\t\telse:\n\t\t\t\tx = 1\n\t\telif x == 0:\n\t\t\tif h == 0:\n\t\t\t\tif a[x][y] < '3':\n\t\t\t\t\ty += 1\n\t\t\t\telse:\n\t\t\t\t\tx = 1\n\t\t\telse:\n\t\t\t\th = 0\n\t\t\t\tif a[x][y] < '3':\n\t\t\t\t\tans = False\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\ty += 1\n\t\telif h == 0:\n\t\t\th = 1\n\t\t\tif a[x][y] < '3':\n\t\t\t\tans = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ty += 1\n\t\telif a[x][y] < '3':\n\t\t\ty += 1\n\t\telse:\n\t\t\tx = 0\n\tif ans:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = input()\ninp = [input() for i in range(int(q) * 3)]\ni = 0\nj = 0\nwhile i < int(q):\n\tl = int(inp[j])\n\tup = inp[j + 1]\n\tdown = inp[j + 2]\n\tflow_down = False\n\tend = False\n\tfor k in range(l):\n\t\tif k == 0:\n\t\t\tif int(up[k]) > 2 and int(down[k]) < 3:\n\t\t\t\tprint('NO')\n\t\t\t\tend = True\n\t\t\t\tbreak\n\t\tif int(up[k]) > 2 and int(down[k]) > 2:\n\t\t\tflow_down = True if not flow_down else False\n\t\telif flow_down and int(down[k]) > 2 and (int(up[k]) < 3):\n\t\t\tprint('NO')\n\t\t\tend = True\n\t\t\tbreak\n\t\telif not flow_down and int(down[k]) < 3 and (int(up[k]) > 2):\n\t\t\tprint('NO')\n\t\t\tend = True\n\t\t\tbreak\n\tif not end:\n\t\tif flow_down:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\ti += 1\n\tj += 3\n", "from sys import *\nfor i in range(int(input())):\n\tn = int(stdin.readline())\n\tl1 = list(map(int, input()))\n\tl2 = list(map(int, input()))\n\tif n == 1:\n\t\tif l1[0] > 2 and l2[0] > 2:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\t\tcontinue\n\t(top, bot) = (0, 0)\n\tif l1[0] < 3:\n\t\ttop = 1\n\tif l1[0] > 2 and l2[0] > 2:\n\t\tbot = 1\n\tf = 0\n\tfor i in range(1, n - 1):\n\t\tif top == 0 and bot == 0:\n\t\t\tf = 1\n\t\t\tbreak\n\t\tif top == 1 and bot == 0:\n\t\t\tif l1[i] < 3:\n\t\t\t\tcontinue\n\t\t\tif l1[i] > 2 and l2[i] > 2:\n\t\t\t\tbot = 1\n\t\t\t\ttop = 0\n\t\t\telse:\n\t\t\t\tf = 1\n\t\t\t\tbreak\n\t\telif top == 0 and bot == 1:\n\t\t\tif l2[i] < 3:\n\t\t\t\tcontinue\n\t\t\tif l2[i] > 2 and l1[i] > 2:\n\t\t\t\ttop = 1\n\t\t\t\tbot = 0\n\t\t\telse:\n\t\t\t\tf = 1\n\t\t\t\tbreak\n\tif f:\n\t\tprint('NO')\n\telif top == 1 and l1[-1] > 2 and (l2[-1] > 2):\n\t\tprint('YES')\n\telif bot == 1 and l2[-1] < 3:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\tl1 = list(map(int, input()))\n\tl2 = list(map(int, input()))\n\t(row, col) = (0, 0)\n\tvert = False\n\tans = ''\n\ttype1 = [1, 2]\n\ttype2 = [3, 4, 5, 6]\n\twhile True:\n\t\tif row not in [0, 1] or col >= n:\n\t\t\tans = 'NO'\n\t\t\tbreak\n\t\tif row == 1 and col == n - 1:\n\t\t\tif vert == True:\n\t\t\t\tans = 'YES' if l2[col] in type2 else 'NO'\n\t\t\telse:\n\t\t\t\tans = 'YES' if l2[col] in type1 else 'NO'\n\t\t\tbreak\n\t\telif row == 0 and col == 0:\n\t\t\tif l1[col] in type1:\n\t\t\t\tvert = False\n\t\t\t\tcol += 1\n\t\t\telse:\n\t\t\t\tvert = True\n\t\t\t\trow += 1\n\t\telif row == 0:\n\t\t\tif l1[col] in type1:\n\t\t\t\tif vert == True:\n\t\t\t\t\trow -= 1\n\t\t\t\telse:\n\t\t\t\t\tcol += 1\n\t\t\t\t\tvert = False\n\t\t\telif vert == True:\n\t\t\t\tcol += 1\n\t\t\t\tvert = False\n\t\t\telse:\n\t\t\t\trow += 1\n\t\t\t\tvert = True\n\t\telif l2[col] in type1:\n\t\t\tif vert == True:\n\t\t\t\trow += 1\n\t\t\telse:\n\t\t\t\tcol += 1\n\t\t\t\tvert = False\n\t\telif vert == True:\n\t\t\tcol += 1\n\t\t\tvert = False\n\t\telse:\n\t\t\trow -= 1\n\t\t\tvert = True\n\tprint(ans)\n", "import os\nT = int(input())\nfor t in range(T):\n\tn = int(input())\n\ts = [[int(i) for i in input()] for j in range(2)]\n\tidx = 0\n\tfor i in range(n):\n\t\tif s[0][i] > 2 and s[1][i] > 2:\n\t\t\tidx ^= 1\n\t\telse:\n\t\t\tif s[0][i] > 2 and idx == 0:\n\t\t\t\tbreak\n\t\t\tif s[1][i] > 2 and idx == 1:\n\t\t\t\tidx = 0\n\t\t\t\tbreak\n\tif idx:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def solve():\n\tn = int(input())\n\tr1 = input()\n\tr2 = input()\n\ttop = 1\n\tfor i in range(n):\n\t\tif top:\n\t\t\tif int(r1[i]) > 2:\n\t\t\t\tif int(r2[i]) > 2:\n\t\t\t\t\ttop = 0\n\t\t\t\telse:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\treturn\n\t\telif int(r2[i]) > 2:\n\t\t\tif int(r1[i]) > 2:\n\t\t\t\ttop = 1\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\treturn\n\tif top:\n\t\tprint('NO')\n\t\treturn\n\tprint('YES')\nfor _ in range(int(input())):\n\tsolve()\n", "def sol():\n\tw = int(input())\n\tpath = []\n\tfor i in range(2):\n\t\tarr = list(map(int, list(input())))\n\t\tfor g in range(w):\n\t\t\tif arr[g] == 2 or arr[g] == 1:\n\t\t\t\tarr[g] = 1\n\t\t\telse:\n\t\t\t\tarr[g] = 2\n\t\tpath.append(arr)\n\tallOkay = True\n\tnowX = 0\n\tnowY = 0\n\tlastDir = 0\n\tif path[0][0] == 1:\n\t\tnowX += 1\n\t\tlastDir = 2\n\telse:\n\t\tnowY += 1\n\t\tlastDir = 1\n\tfor i in range(2 * w + 1):\n\t\tif nowY == 1 and nowX == w:\n\t\t\tbreak\n\t\telif nowX < 0 or nowX >= w:\n\t\t\tallOkay = False\n\t\t\tbreak\n\t\telif nowY < 0 or nowY >= 2:\n\t\t\tallOkay = False\n\t\t\tbreak\n\t\tpicked = False\n\t\tif lastDir == 2:\n\t\t\tif path[nowY][nowX] == 1:\n\t\t\t\tnowX += 1\n\t\t\t\tlastDir = 2\n\t\t\telif nowY == 0:\n\t\t\t\tlastDir = 1\n\t\t\t\tnowY += 1\n\t\t\telse:\n\t\t\t\tlastDir = 3\n\t\t\t\tnowY -= 1\n\t\t\tpicked = True\n\t\telif lastDir == 1 or lastDir == 3:\n\t\t\tif path[nowY][nowX] == 2:\n\t\t\t\tnowX += 1\n\t\t\t\tlastDir = 2\n\t\t\t\tpicked = True\n\t\tif picked:\n\t\t\tcontinue\n\t\telse:\n\t\t\tallOkay = False\n\t\t\tbreak\n\tif allOkay:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\nfor _ in range(int(input())):\n\tsol()\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ttab = [[True, False]]\n\ts1 = input()\n\ts2 = input()\n\tfor j in range(1, n + 1):\n\t\tup = False\n\t\tdown = False\n\t\tif int(s1[j - 1]) < 3 and tab[j - 1][0]:\n\t\t\tup = True\n\t\tif int(s2[j - 1]) < 3 and tab[j - 1][1]:\n\t\t\tdown = True\n\t\tif int(s1[j - 1]) > 2 and int(s2[j - 1]) > 2 and tab[j - 1][0]:\n\t\t\tdown = True\n\t\tif int(s1[j - 1]) > 2 and int(s2[j - 1]) > 2 and tab[j - 1][1]:\n\t\t\tup = True\n\t\ttab.append([up, down])\n\tif tab[n][1]:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "que = int(input())\na = []\nfor i in range(que):\n\tn = int(input())\n\tbool_map = lambda x: True if int(x) <= 2 else False\n\trow1 = list(map(bool_map, input().strip('\\n')))\n\trow2 = list(map(bool_map, input().strip('\\n')))\n\tcurrent = False\n\tfor (r1, r2) in zip(row1, row2):\n\t\tif r1 and (not current):\n\t\t\tpass\n\t\telif r2 and current:\n\t\t\tpass\n\t\telif not r1 and (not r2):\n\t\t\tcurrent = not current\n\t\telse:\n\t\t\tcurrent = False\n\t\t\tbreak\n\tif current:\n\t\ta.append('YES')\n\telse:\n\t\ta.append('NO')\nprint('\\n'.join(a))\n", "for _ in range(int(input())):\n\tn = int(input())\n\tr1 = input()\n\tr2 = input()\n\tflag = 1\n\tcount = 0\n\tf = 1\n\tfor i in range(n):\n\t\tif r1[i] in '3456' and r2[i] in '3456':\n\t\t\tcount += 1\n\t\t\tif f:\n\t\t\t\tf = 0\n\t\t\telse:\n\t\t\t\tf = 1\n\t\telif f and (r1[i] in '3456' and r2[i] in '12'):\n\t\t\tflag = 0\n\t\t\tbreak\n\t\telif not f and (r1[i] in '12' and r2[i] in '3456'):\n\t\t\tflag = 0\n\t\t\tbreak\n\tif count % 2 and flag:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\ninf = float('inf')\n(mod, MOD) = (1000000007, 998244353)\n\ndef get_array():\n\treturn list(map(int, sys.stdin.readline().strip().split()))\n\ndef get_ints():\n\treturn map(str, sys.stdin.readline().strip().split())\n\ndef input():\n\treturn sys.stdin.readline().strip()\nT = int(input())\nwhile T > 0:\n\tn = int(input())\n\tstring1 = input()\n\tstring2 = input()\n\tdp1 = [False] * n\n\tdp2 = [False] * n\n\tif '1' <= string1[0] <= '2':\n\t\tdp1[0] = True\n\tif '3' <= string1[0] <= '6' and '3' <= string2[0] <= '6':\n\t\tdp2[0] = True\n\tfor i in range(n - 1):\n\t\tif dp1[i] and '1' <= string1[i + 1] <= '2':\n\t\t\tdp1[i + 1] = True\n\t\tif dp1[i] and '3' <= string1[i + 1] <= '6' and ('3' <= string2[i + 1] <= '6'):\n\t\t\tdp2[i + 1] = True\n\t\tif dp2[i] and '1' <= string2[i + 1] <= '2':\n\t\t\tdp2[i + 1] = True\n\t\tif dp2[i] and '3' <= string2[i + 1] <= '6' and ('3' <= string1[i + 1] <= '6'):\n\t\t\tdp1[i + 1] = True\n\tprint(['No', 'Yes'][dp2[-1]])\n\tT -= 1\n", "for q in range(int(input())):\n\tn = int(input())\n\ts = [None, None]\n\ts[0] = input()\n\ts[1] = input()\n\to = 'YES'\n\tr = 0\n\tfor i in range(n):\n\t\tif s[r][i] in '12':\n\t\t\tcontinue\n\t\telif s[r ^ 1][i] not in '12':\n\t\t\tr ^= 1\n\t\telse:\n\t\t\to = 'NO'\n\t\t\tbreak\n\tif r == 0:\n\t\to = 'NO'\n\tprint(o)\n", "t = int(input())\nfor test in range(t):\n\tn = int(input())\n\tline = []\n\tdp = []\n\tfor i in range(2):\n\t\tdp.append([False] * (n + 2))\n\tline.append(list('0' + input() + '0'))\n\tline.append(list('0' + input() + '0'))\n\tsol = True\n\tlast = [True, False]\n\tfor i in range(1, n + 1):\n\t\tnew = [False, False]\n\t\tboth = 0\n\t\tif line[0][i] == '1' or line[0][i] == '2':\n\t\t\tnew[0] = last[0]\n\t\telse:\n\t\t\tboth += 1\n\t\tif line[1][i] == '1' or line[1][i] == '2':\n\t\t\tnew[1] = last[1]\n\t\telse:\n\t\t\tboth += 1\n\t\tif both == 2:\n\t\t\tnew[0] = last[1]\n\t\t\tnew[1] = last[0]\n\t\tlast = new\n\t\tif not last[0] and (not last[1]):\n\t\t\tbreak\n\t\t\tsol = False\n\tif last[1]:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\n\ndef input():\n\treturn sys.stdin.readline().strip()\n\ndef list2d(a, b, c):\n\treturn [[c] * b for i in range(a)]\n\ndef list3d(a, b, c, d):\n\treturn [[[d] * c for j in range(b)] for i in range(a)]\n\ndef list4d(a, b, c, d, e):\n\treturn [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]\n\ndef ceil(x, y=1):\n\treturn int(-(-x // y))\n\ndef INT():\n\treturn int(input())\n\ndef MAP():\n\treturn map(int, input().split())\n\ndef LIST(N=None):\n\treturn list(MAP()) if N is None else [INT() for i in range(N)]\n\ndef Yes():\n\tprint('Yes')\n\ndef No():\n\tprint('No')\n\ndef YES():\n\tprint('YES')\n\ndef NO():\n\tprint('NO')\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nMOD = 10 ** 9 + 7\nfor _ in range(INT()):\n\tN = INT()\n\tgrid = [None] * 2\n\tgrid[0] = list(map(int, list(input())))\n\tgrid[1] = list(map(int, list(input())))\n\tcur = 0\n\tfor i in range(N):\n\t\tif grid[0][i] <= 2 and grid[1][i] <= 2:\n\t\t\tpass\n\t\telif grid[0][i] > 2 and grid[1][i] > 2:\n\t\t\tcur = 1 - cur\n\t\telif grid[cur][i] > 2:\n\t\t\tNO()\n\t\t\tbreak\n\telse:\n\t\tif cur == 1:\n\t\t\tYES()\n\t\telse:\n\t\t\tNO()\n", "def main():\n\tq = int(input())\n\tfor i in range(q):\n\t\tn = int(input())\n\t\ta = input()\n\t\tb = input()\n\t\tt = 0\n\t\tlevel = 0\n\t\twhile t < n:\n\t\t\tif level == 0 and (a[t] == '2' or a[t] == '1'):\n\t\t\t\tt += 1\n\t\t\telif 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'):\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telif 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')):\n\t\t\t\tlevel = 1\n\t\t\t\tt += 1\n\t\t\telif 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'):\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telif 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')):\n\t\t\t\tlevel = 0\n\t\t\t\tt += 1\n\t\t\telif level == 1 and (b[t] == '2' or b[t] == '1'):\n\t\t\t\tt += 1\n\t\tif t == n and level == 1:\n\t\t\tprint('YES')\n\t\tif t == n and level == 0:\n\t\t\tprint('NO')\nmain()\n", "from sys import stdin\nq = int(stdin.readline().strip())\nfor _ in range(q):\n\tn = int(stdin.readline().strip())\n\tarr = []\n\tfor k in range(2):\n\t\tarr.append(list(map(int, list(stdin.readline().strip()))))\n\ti = 0\n\tj = 0\n\tf = 'l'\n\twhile True:\n\t\tif j == n:\n\t\t\tbreak\n\t\tif i < 0 or i >= 2:\n\t\t\tbreak\n\t\tif f == 'l':\n\t\t\tif arr[i][j] in [1, 2]:\n\t\t\t\tj += 1\n\t\t\t\tf = 'l'\n\t\t\telif arr[i][j] in [3, 4, 5, 6]:\n\t\t\t\tif i == 0:\n\t\t\t\t\tf = 't'\n\t\t\t\t\ti += 1\n\t\t\t\telif i == 1:\n\t\t\t\t\tf = 'd'\n\t\t\t\t\ti -= 1\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\t\telif f == 'd':\n\t\t\tif arr[i][j] in [1, 2]:\n\t\t\t\tbreak\n\t\t\telif arr[i][j] in [3, 4, 5, 6]:\n\t\t\t\tif i == 0:\n\t\t\t\t\tj += 1\n\t\t\t\t\tf = 'l'\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\t\telif f == 't':\n\t\t\tif arr[i][j] in [1, 2]:\n\t\t\t\tbreak\n\t\t\telif arr[i][j] in [3, 4, 5, 6]:\n\t\t\t\tif i == 1:\n\t\t\t\t\tj += 1\n\t\t\t\t\tf = 'l'\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\tif i == 1 and j == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\trow_1 = input().replace('2', '1').replace('3', '2').replace('4', '2').replace('5', '2').replace('6', '2')\n\trow_2 = input().replace('2', '1').replace('3', '2').replace('4', '2').replace('5', '2').replace('6', '2')\n\tplace = 1\n\tflag = True\n\tfor i in range(len(row_2)):\n\t\tif place == 1 and row_1[i] == '2' and (row_2[i] == '2'):\n\t\t\tplace = 2\n\t\telif place == 2 and row_1[i] == '2' and (row_2[i] == '2'):\n\t\t\tplace = 1\n\t\telif 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')):\n\t\t\tflag = False\n\tif flag and place == 2:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ts1 = [int(x) for x in input().strip()]\n\ts2 = [int(x) for x in input().strip()]\n\ta = [s1, s2]\n\tj = 0\n\ti = 0\n\tb = 0\n\tif n == 1:\n\t\tif a[0][0] >= 3 and a[1][0] >= 3:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\telse:\n\t\tif a[i][j] < 3:\n\t\t\tj += 1\n\t\t\tb = 0\n\t\telse:\n\t\t\ti = 1\n\t\t\tj = 0\n\t\t\tb = 0\n\t\twhile j < n:\n\t\t\tif a[i][j] < 3:\n\t\t\t\tif i != b:\n\t\t\t\t\tbreak\n\t\t\t\tj += 1\n\t\t\telif b == i:\n\t\t\t\tb = i\n\t\t\t\ti = 1 - i\n\t\t\telse:\n\t\t\t\tj += 1\n\t\t\t\tb = i\n\t\tif n == j and i == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "tc = int(input())\nfor i in range(tc):\n\tn = int(input())\n\tp1 = input()\n\tp2 = input()\n\tl = 0\n\tc = 0\n\thor = True\n\tok = True\n\twhile ok:\n\t\tif l == n:\n\t\t\tif c == 1:\n\t\t\t\tok = True\n\t\t\telse:\n\t\t\t\tok = False\n\t\t\tbreak\n\t\tif c == 0:\n\t\t\tcrt = p1[l]\n\t\telse:\n\t\t\tcrt = p2[l]\n\t\tif crt == '1' or crt == '2':\n\t\t\ttp = 0\n\t\telse:\n\t\t\ttp = 1\n\t\tif c == 0:\n\t\t\tif tp == 0:\n\t\t\t\tif hor:\n\t\t\t\t\tl += 1\n\t\t\t\telse:\n\t\t\t\t\tok = False\n\t\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tif hor:\n\t\t\t\t\tc += 1\n\t\t\t\telse:\n\t\t\t\t\tl += 1\n\t\t\t\thor = not hor\n\t\telif tp == 0:\n\t\t\tif hor:\n\t\t\t\tl += 1\n\t\t\telse:\n\t\t\t\tok = False\n\t\t\t\tbreak\n\t\telse:\n\t\t\tif hor:\n\t\t\t\tc -= 1\n\t\t\telse:\n\t\t\t\tl += 1\n\t\t\thor = not hor\n\tif ok:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def solve(n, a):\n\t(row, pos) = (0, -1)\n\tfor i in range(n):\n\t\tif int(a[row][i]) >= 3 and int(a[row ^ 1][i]) <= 2:\n\t\t\tbreak\n\t\telse:\n\t\t\tif int(a[row][i]) >= 3 and int(a[row ^ 1][i]) >= 3:\n\t\t\t\trow = row ^ 1\n\t\t\tpos = i\n\tif row == 1 and pos == n - 1:\n\t\treturn 1\n\treturn 0\nt = int(input())\nfor _ in range(t):\n\tn = int(input())\n\ta = []\n\tfor _ in range(2):\n\t\ta.append(input())\n\tif solve(n, a):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def line():\n\treturn map(int, input().split())\n\ndef num():\n\treturn int(input())\nfrom itertools import repeat\nq = num()\nst = {1, 2}\nfor _ in repeat(None, q):\n\tn = num()\n\ttubes = [list(map(int, input())) for _ in range(2)]\n\tc = [1, 0]\n\tfor i in range(n):\n\t\tif not c[0] and (not c[1]):\n\t\t\tbreak\n\t\tp = (tubes[0][i], tubes[1][i])\n\t\tr = [0, 0]\n\t\tif c[0]:\n\t\t\tif p[0] not in st and p[1] not in st:\n\t\t\t\tr[1] = 1\n\t\t\tif p[0] in st:\n\t\t\t\tr[0] = 1\n\t\tif c[1]:\n\t\t\tif p[0] not in st and p[1] not in st:\n\t\t\t\tr[0] = 1\n\t\t\tif p[1] in st:\n\t\t\t\tr[1] = 1\n\t\tc = r\n\tprint('YES' if c[1] else 'NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\ts = [''] * 2\n\ts[0] = input()\n\ts[1] = input()\n\tp = 0\n\tfor i in range(n):\n\t\tif s[p][i] > '2':\n\t\t\tp = 1 - p\n\t\t\tif s[p][i] <= '2':\n\t\t\t\tp = 0\n\t\t\t\tbreak\n\tprint('YES' if p else 'NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\ts = [input(), input()]\n\tx = 0\n\tfor i in range(n):\n\t\tif s[x][i] != '1' and s[x][i] != '2':\n\t\t\tx ^= 1\n\t\t\tif s[x][i] == '1' or s[x][i] == '2':\n\t\t\t\tx = 0\n\t\t\t\tbreak\n\tif x == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "a = int(input())\nfor i in range(a):\n\tln = int(input())\n\tpipe = [[], []]\n\tfor j in range(2):\n\t\tpipe[j] = list(input())\n\t\tpipe[j] = list(map(int, pipe[j]))\n\tfor j in range(2):\n\t\tfor k in range(ln):\n\t\t\tif pipe[j][k] <= 2:\n\t\t\t\tpipe[j][k] = 1\n\t\t\telse:\n\t\t\t\tpipe[j][k] = 2\n\tprev = 0\n\tcrd = [0, 0]\n\twhile crd[1] < ln and (crd[0] == 0 or crd[0] == 1):\n\t\tif crd[0] == 0:\n\t\t\tif prev == 0:\n\t\t\t\tif pipe[crd[0]][crd[1]] == 1:\n\t\t\t\t\tcrd[1] += 1\n\t\t\t\telse:\n\t\t\t\t\tcrd[0] += 1\n\t\t\t\t\tprev = 1\n\t\t\telif pipe[crd[0]][crd[1]] == 1:\n\t\t\t\tcrd[0] += prev\n\t\t\telse:\n\t\t\t\tcrd[1] += 1\n\t\t\t\tprev = 0\n\t\telif prev == 0:\n\t\t\tif pipe[crd[0]][crd[1]] == 1:\n\t\t\t\tcrd[1] += 1\n\t\t\telse:\n\t\t\t\tcrd[0] += -1\n\t\t\t\tprev = -1\n\t\telif pipe[crd[0]][crd[1]] == 1:\n\t\t\tcrd[0] += prev\n\t\telse:\n\t\t\tcrd[1] += 1\n\t\t\tprev = 0\n\tif crd == [1, ln]:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "input = __import__('sys').stdin.readline\nprint = __import__('sys').stdout.write\nthres = 3\nfor _ in range(int(input())):\n\tcurrent = False\n\tN = int(input())\n\ttmp = [list(map(int, list(input()[:-1]))), list(map(int, list(input()[:-1])))]\n\tfor i in range(N):\n\t\tif tmp[current][i] < thres:\n\t\t\tcontinue\n\t\telif tmp[not current][i] < thres:\n\t\t\tbreak\n\t\telse:\n\t\t\tcurrent = not current\n\telse:\n\t\tif current:\n\t\t\tprint('YES\\n')\n\t\telse:\n\t\t\tprint('NO\\n')\n\t\tcontinue\n\tprint('NO\\n')\n", "q = int(input())\nfor iter in range(q):\n\tarr = []\n\tn = int(input())\n\tfor read in range(2):\n\t\tarr.append([int(x) for x in list(input())])\n\tcurr_i = 0\n\tcurr_j = 0\n\tflag = 0\n\twhile curr_j < n:\n\t\tele = arr[curr_i][curr_j]\n\t\tif ele == 1 or ele == 2:\n\t\t\tcurr_j += 1\n\t\telse:\n\t\t\tcurr_i = 1 - curr_i\n\t\t\tnew_ele = arr[curr_i][curr_j]\n\t\t\tif new_ele == 1 or new_ele == 2:\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\t\t\tcurr_j += 1\n\tif curr_i == 0 or flag == 1:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "q = int(input().strip())\nfor _ in range(q):\n\tn = int(input().strip())\n\ts = []\n\ts.append(input())\n\ts.append(input())\n\tpossible = True\n\tfrom_pipe = 0\n\tother_pipe = 1\n\tfor i in range(n):\n\t\tif not (s[from_pipe][i] == '1' or s[from_pipe][i] == '2'):\n\t\t\tif not (s[other_pipe][i] == '1' or s[other_pipe][i] == '2'):\n\t\t\t\tfrom_pipe = 1 - from_pipe\n\t\t\t\tother_pipe = 1 - other_pipe\n\t\t\telse:\n\t\t\t\tpossible = False\n\t\t\t\tbreak\n\tif possible == False or from_pipe == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "import sys\ninput = sys.stdin.readline\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tS = [input()[:-1] for _ in range(2)]\n\t(cx, cy, dire) = (0, 0, 0)\n\twhile True:\n\t\tif dire == 0 and S[cx][cy] in ['1', '2']:\n\t\t\tcy += 1\n\t\telif dire == 0 and S[cx][cy] in ['3', '4', '5', '6']:\n\t\t\tif cx == 0:\n\t\t\t\tcx = 1\n\t\t\t\tdire = 2\n\t\t\telif cx == 1:\n\t\t\t\tcx = 0\n\t\t\t\tdire = 1\n\t\telif dire == 1 and S[cx][cy] in ['1', '2']:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\telif dire == 1 and S[cx][cy] in ['3', '4', '5', '6']:\n\t\t\tcy += 1\n\t\t\tdire = 0\n\t\telif dire == 2 and S[cx][cy] in ['1', '2']:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\telif dire == 2 and S[cx][cy] in ['3', '4', '5', '6']:\n\t\t\tcy += 1\n\t\t\tdire = 0\n\t\tif cy == n:\n\t\t\tif cx == 1:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\tbreak\n", "for i in range(int(input())):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\ta = [s1, s2]\n\tlvl = 0\n\tf = True\n\tfor i in range(n):\n\t\tif '1' <= a[lvl][i] <= '2':\n\t\t\tcontinue\n\t\telif '1' <= a[(lvl + 1) % 2][i] <= '2':\n\t\t\tf = False\n\t\t\tbreak\n\t\telse:\n\t\t\tlvl = (lvl + 1) % 2\n\tprint('YES' if f and lvl == 1 else 'NO')\n", "q = int(input())\nfor k in range(q):\n\tn = int(input())\n\tarr1 = input()\n\tarr2 = input()\n\tarr = []\n\tfor i in range(n):\n\t\tarr.append([int(arr1[i]), int(arr2[i])])\n\tpath = True\n\tnew = 0\n\tfor i in range(n):\n\t\tif 1 <= arr[i][new] <= 2:\n\t\t\tcontinue\n\t\telif 1 <= arr[i][(new + 1) % 2] <= 2:\n\t\t\tpath = False\n\t\t\tbreak\n\t\telse:\n\t\t\tnew = (new + 1) % 2\n\tprint('YES' if path and new == 1 else 'NO')\n", "for q in range(int(input())):\n\tn = int(input())\n\td1 = [c > '2' for c in input()]\n\td2 = [c > '2' for c in input()]\n\tdp = [[1, 0]]\n\tfor i in range(n):\n\t\tans = [0, 0]\n\t\tif dp[-1][0]:\n\t\t\tif d1[i] == 0:\n\t\t\t\tans[0] = 1\n\t\t\telif d1[i] and d2[i]:\n\t\t\t\tans[1] = 1\n\t\tif dp[-1][1]:\n\t\t\tif d2[i] == 0:\n\t\t\t\tans[1] = 1\n\t\t\telif d1[i] and d2[i]:\n\t\t\t\tans[0] = 1\n\t\tdp.append(ans)\n\tprint(['NO', 'YES'][dp[-1][1]])\n", "for x in range(int(input())):\n\tn = int(input())\n\ta = []\n\tfor y in range(2):\n\t\ta.append(list(input()))\n\t(i, j) = (0, 0)\n\tprev = [i, j]\n\tok = False\n\twhile True:\n\t\tif j == n - 1:\n\t\t\tif i == 0:\n\t\t\t\tif a[i][j] not in '12' and a[i + 1][j] not in '12':\n\t\t\t\t\tok = True\n\t\t\telif i == 1:\n\t\t\t\tif a[i][j] in '12':\n\t\t\t\t\tok = True\n\t\t\tbreak\n\t\tif a[i][j] in '12':\n\t\t\tprev[0] = i\n\t\t\tprev[1] = j\n\t\t\tj += 1\n\t\telif i == j == 0:\n\t\t\tif a[1][0] not in '12':\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tbreak\n\t\telif i == 1 and prev[0] + 1 == i:\n\t\t\tprev[0] = i\n\t\t\tprev[1] = j\n\t\t\tj += 1\n\t\telif i == 1 and prev[1] + 1 == j:\n\t\t\tif a[i - 1][j] in '12':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tprev[0] = i\n\t\t\t\tprev[1] = j\n\t\t\t\ti -= 1\n\t\telif i == 0 and prev[0] - 1 == i:\n\t\t\tprev[0] = i\n\t\t\tprev[1] = j\n\t\t\tj += 1\n\t\telif i == 0 and prev[1] + 1 == j:\n\t\t\tif a[i + 1][j] in '12':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tprev[0] = i\n\t\t\t\tprev[1] = j\n\t\t\t\ti += 1\n\tif ok == True:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tl1 = list(map(int, list(input())))\n\tl2 = list(map(int, list(input())))\n\tline = 0\n\tfor i in range(n):\n\t\tif line == 0:\n\t\t\tif l1[i] == 1 or l1[i] == 2:\n\t\t\t\tcontinue\n\t\t\telif l2[i] != 1 and l2[i] != 2:\n\t\t\t\tline = 1\n\t\t\telse:\n\t\t\t\tline = 0\n\t\t\t\tbreak\n\t\telif l2[i] == 1 or l2[i] == 2:\n\t\t\tcontinue\n\t\telif l1[i] != 1 and l1[i] != 2:\n\t\t\tline = 0\n\t\telse:\n\t\t\tline = 0\n\t\t\tbreak\n\tif line == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "mod = 10 ** 9 + 7\nimport sys\nsys.setrecursionlimit(10 ** 6)\nfrom sys import stdin, stdout\nimport bisect\nfrom bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nimport itertools\nimport collections\nimport math\nimport heapq\nimport random\n\ndef modinv(n, p):\n\treturn pow(n, p - 2, p)\n\ndef ncr(n, r, p):\n\tt = fact[n] * (ifact[r] * ifact[n - r] % p) % p\n\treturn t\n\ndef cin():\n\treturn map(int, sin().split())\n\ndef ain():\n\treturn list(map(int, sin().split()))\n\ndef sin():\n\treturn input()\n\ndef inin():\n\treturn int(input())\n\ndef GCD(x, y):\n\twhile y:\n\t\t(x, y) = (y, x % y)\n\treturn x\n\ndef main():\n\tt = inin()\n\tfor _ in range(t):\n\t\tn = inin()\n\t\ta = []\n\t\ta.append(list(sin()))\n\t\ta.append(list(sin()))\n\t\tfor i in range(2):\n\t\t\tfor j in range(n):\n\t\t\t\tx = int(a[i][j])\n\t\t\t\tif x / 3 < 1:\n\t\t\t\t\ta[i][j] = 1\n\t\t\t\telse:\n\t\t\t\t\ta[i][j] = 2\n\t\tx = 0\n\t\tans = 'NO'\n\t\ttt = 1\n\t\tfor i in range(n - 1):\n\t\t\tif a[x][i] == 2:\n\t\t\t\tif a[x ^ 1][i] == 2:\n\t\t\t\t\tx = x ^ 1\n\t\t\t\telse:\n\t\t\t\t\ttt = 0\n\t\t\t\t\tbreak\n\t\tif x == 0 and tt == 1 and (a[x][n - 1] == 2) and (a[x ^ 1][n - 1] == 2):\n\t\t\tans = 'YES'\n\t\tif x == 1 and tt == 1 and (a[x][n - 1] == 1):\n\t\t\tans = 'YES'\n\t\tprint(ans)\npy2 = round(0.5)\nif py2:\n\tfrom future_builtins import ascii, filter, hex, map, oct, zip\n\trange = xrange\nimport os, sys\nfrom io import IOBase, BytesIO\nBUFSIZE = 8192\n\nclass FastIO(BytesIO):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._file = file\n\t\tself._fd = file.fileno()\n\t\tself.writable = 'x' in file.mode or 'w' in file.mode\n\t\tself.write = super(FastIO, self).write if self.writable else None\n\n\tdef _fill(self):\n\t\ts = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\tself.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])\n\t\treturn s\n\n\tdef read(self):\n\t\twhile self._fill():\n\t\t\tpass\n\t\treturn super(FastIO, self).read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\ts = self._fill()\n\t\t\tself.newlines = s.count(b'\\n') + (not s)\n\t\tself.newlines -= 1\n\t\treturn super(FastIO, self).readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.getvalue())\n\t\t\t(self.truncate(0), self.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tif py2:\n\t\t\tself.write = self.buffer.write\n\t\t\tself.read = self.buffer.read\n\t\t\tself.readline = self.buffer.readline\n\t\telse:\n\t\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nimport sys\n\nclass ostream:\n\n\tdef __lshift__(self, a):\n\t\tsys.stdout.write(str(a))\n\t\treturn self\ncout = ostream()\nendl = '\\n'\n\ndef readnumbers(zero=0):\n\tconv = ord if py2 else lambda x: x\n\tA = []\n\tnumb = zero\n\tsign = 1\n\ti = 0\n\ts = sys.stdin.buffer.read()\n\ttry:\n\t\twhile True:\n\t\t\tif s[i] >= b'0'[0]:\n\t\t\t\tnumb = 10 * numb + conv(s[i]) - 48\n\t\t\telif s[i] == b'-'[0]:\n\t\t\t\tsign = -1\n\t\t\telif s[i] != b'\\r'[0]:\n\t\t\t\tA.append(sign * numb)\n\t\t\t\tnumb = zero\n\t\t\t\tsign = 1\n\t\t\ti += 1\n\texcept:\n\t\tpass\n\tif s and s[-1] >= b'0'[0]:\n\t\tA.append(sign * numb)\n\treturn A\nmain()\n", "import sys\nimport math\nfrom collections import defaultdict\ntry:\n\tsys.stdin = open('input.txt', 'r')\n\tsys.stdout = open('output.txt', 'w')\nexcept:\n\tpass\n\ndef takeInput():\n\treturn [int(x) for x in input().strip().split()]\n\nclass Graph:\n\n\tdef __init__(self):\n\t\tself.neighbours = defaultdict(list)\n\n\tdef addEdge(self, u, v):\n\t\tself.neighbours[u].append(v)\n\n\tdef BFS(self, destination):\n\t\tqueue = [1]\n\t\tvisited = defaultdict(lambda : False)\n\t\twhile queue:\n\t\t\tu = queue.pop(0)\n\t\t\tif u == destination:\n\t\t\t\treturn True\n\t\t\tfor v in self.neighbours[u]:\n\t\t\t\tif not visited[v]:\n\t\t\t\t\tvisited[v] = True\n\t\t\t\t\tqueue.append(v)\n\t\treturn False\nt = int(input())\nwhile t != 0:\n\tt -= 1\n\tn = int(input())\n\trow1 = input()\n\trow2 = input()\n\trow1 = [int(x) for x in list(row1)]\n\trow2 = [int(x) for x in list(row2)]\n\tfor (i, r) in enumerate(row1):\n\t\tif r == 1 or r == 2:\n\t\t\trow1[i] = 1\n\t\telse:\n\t\t\trow1[i] = 3\n\tfor (i, r) in enumerate(row2):\n\t\tif r == 1 or r == 2:\n\t\t\trow2[i] = 1\n\t\telse:\n\t\t\trow2[i] = 3\n\tmaze = [0] + row1 + row2 + [0]\n\tg = Graph()\n\tfor i in range(1, 2 * n + 1):\n\t\tif maze[i] == 1:\n\t\t\tif i != n:\n\t\t\t\tg.addEdge(i, i + 1)\n\t\tif i <= n:\n\t\t\tif maze[i] == 3 and maze[i + n] == 3:\n\t\t\t\tg.addEdge(i, i + n + 1)\n\t\telif maze[i] == 3 and maze[i - n] == 3:\n\t\t\tif i != 2 * n:\n\t\t\t\tg.addEdge(i, i - n + 1)\n\tdestination = 2 * n + 1\n\tif g.BFS(destination):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\ts = [input(), input()]\n\ti = -1\n\tj = 0\n\twhile i < n - 1:\n\t\tif s[j][i + 1] < '3':\n\t\t\ti += 1\n\t\telif s[j ^ 1][i + 1] > '2':\n\t\t\ti += 1\n\t\t\tj ^= 1\n\t\telse:\n\t\t\tprint('NO')\n\t\t\tbreak\n\telse:\n\t\tif j == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "for nt in range(int(input())):\n\tn = int(input())\n\tdp = []\n\tdp.append(input())\n\tdp.append(input())\n\tcurr = [1, 1]\n\tprev = 0\n\twhile True:\n\t\tif int(dp[curr[0] - 1][curr[1] - 1]) <= 2:\n\t\t\tif prev == 1:\n\t\t\t\tflag = 0\n\t\t\t\tbreak\n\t\t\tcurr = [curr[0], curr[1] + 1]\n\t\t\tprev = 0\n\t\telif prev == 0:\n\t\t\tif curr[0] == 1:\n\t\t\t\tcurr = [curr[0] + 1, curr[1]]\n\t\t\telse:\n\t\t\t\tcurr = [curr[0] - 1, curr[1]]\n\t\t\tprev = 1\n\t\telif prev == 1:\n\t\t\tcurr = [curr[0], curr[1] + 1]\n\t\t\tprev = 0\n\t\tif curr[0] == 2 and curr[1] == n + 1:\n\t\t\tflag = 1\n\t\t\tbreak\n\t\tif curr[0] > 2 or curr[1] > n:\n\t\t\tflag = 0\n\t\t\tbreak\n\tif flag:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\to = input()\n\to1 = input()\n\tarr = [[], []]\n\tfor i in range(n):\n\t\tif o[i] == '1' or o[i] == '2':\n\t\t\tarr[0] += [1]\n\t\telse:\n\t\t\tarr[0] += [2]\n\t\tif o1[i] == '1' or o1[i] == '2':\n\t\t\tarr[1] += [1]\n\t\telse:\n\t\t\tarr[1] += [2]\n\ta = 0\n\tb = 0\n\tflag = True\n\twhile b < n:\n\t\tif arr[a][b] == 1:\n\t\t\tb += 1\n\t\telif arr[a][b] == 2 and a == 0:\n\t\t\ta = 1\n\t\t\tif arr[a][b] == 1:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tb += 1\n\t\telif arr[a][b] == 2 and a == 1:\n\t\t\ta = 0\n\t\t\tif arr[a][b] == 1:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tb += 1\n\tif flag and a == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for rpt in range(int(input())):\n\tpipelength = int(input())\n\tcross = [input(), input()]\n\tparity = 0\n\tfor i in range(pipelength):\n\t\tif not (cross[parity][i] == '1' or cross[parity][i] == '2'):\n\t\t\tif not (cross[(parity + 1) % 2][i] == '1' or cross[(parity + 1) % 2][i] == '2'):\n\t\t\t\tparity = (parity + 1) % 2\n\t\t\telse:\n\t\t\t\tparity = 0\n\t\t\t\tbreak\n\tif parity == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ts = [input(), input()]\n\tl2 = ['1', '2']\n\tg2 = ['3', '4', '5', '6']\n\ts = [[c for c in l] for l in s]\n\tb = [[True], [False]]\n\tfor i in range(n):\n\t\tfor j in range(2):\n\t\t\tc = s[j][i]\n\t\t\tx = False\n\t\t\tif c in l2 and b[j][i]:\n\t\t\t\tx = True\n\t\t\tif c in g2 and s[j ^ 1][i] in g2 and b[j ^ 1][i]:\n\t\t\t\tx = True\n\t\t\tb[j].append(x)\n\tprint('YES' if b[1][-1] else 'NO')\n", "import heapq\nimport math\nimport sys\ninput = sys.stdin.readline\n\ndef li():\n\treturn [int(i) for i in input().rstrip('\\n').split()]\n\ndef value():\n\treturn int(input())\n\ndef typ(a):\n\tif a < 3:\n\t\treturn 1\n\treturn 2\nfor _ in range(int(input())):\n\tn = int(input())\n\ta = list(map(int, input().rstrip('\\n')))\n\tb = list(map(int, input().rstrip('\\n')))\n\tfor i in range(n):\n\t\ta[i] = [a[i], b[i]]\n\tans = 1\n\tcurrline = 0\n\tfor i in range(n):\n\t\tif typ(a[i][currline]) == 2:\n\t\t\tcurrline = not currline\n\t\t\tif typ(a[i][currline]) == 1:\n\t\t\t\tans = 0\n\t\t\t\tbreak\n\tif currline == 0:\n\t\tans = 0\n\tif ans:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\treachable = True\n\tpath = zip(map(int, list(input().strip())), map(int, list(input().strip())))\n\tlevel = False\n\tfor step in path:\n\t\tif step[level] in {1, 2}:\n\t\t\tpass\n\t\telif 1 not in step and 2 not in step:\n\t\t\tlevel = not level\n\t\telse:\n\t\t\treachable = False\n\t\t\tbreak\n\tprint('YES' if reachable and level else 'NO')\n", "n = int(input())\nans = []\nfor _ in range(n):\n\ta = int(input())\n\tb = input()\n\tc = input()\n\ts = [b, c]\n\trow = 0\n\tcount = 0\n\tfor i in range(a):\n\t\tif s[row][i] >= '3':\n\t\t\tif s[row ^ 1][i] < '3':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\trow = row ^ 1\n\t\tcount += 1\n\tif row == 1 and count == a:\n\t\tans.append('YES')\n\telse:\n\t\tans.append('NO')\nfor i in ans:\n\tprint(i)\n", "tc = int(input())\n\ndef check(p, n):\n\tif 0 <= p[0] <= 1 and 0 <= p[1] <= n:\n\t\treturn True\n\telse:\n\t\treturn False\nouts = []\nfor i in range(tc):\n\tn = int(input())\n\tstrs = []\n\tstrs.append(input())\n\tstrs.append(input())\n\tp = [0, 0]\n\tflag = 0\n\twhile True:\n\t\tif strs[p[0]][p[1]] in ['1', '2']:\n\t\t\tp[1] += 1\n\t\telif strs[p[0]][p[1]] not in ['1', '2'] and strs[1 - p[0]][p[1]] not in ['1', '2']:\n\t\t\tp[0] = 1 - p[0]\n\t\t\tp[1] += 1\n\t\telse:\n\t\t\tflag = 0\n\t\t\tbreak\n\t\tif not check(p, n - 1):\n\t\t\tflag = 1\n\t\t\tbreak\n\tif flag == 0:\n\t\touts.append('NO')\n\telif p != [1, n]:\n\t\touts.append('NO')\n\telse:\n\t\touts.append('YES')\nfor i in outs:\n\tprint(i)\n", "R = lambda : map(int, input().split())\nfor _ in range(int(input())):\n\tn = int(input())\n\tmx = [list(map(int, input())), list(map(int, input()))]\n\tvis = [[0] * (n + 1) for i in range(2)]\n\tvis[0][0] = 1\n\tfor c in range(n):\n\t\tfor r in range(2):\n\t\t\tif vis[r][c] > 0:\n\t\t\t\tif 1 <= mx[r][c] <= 2:\n\t\t\t\t\tvis[r][c + 1] = 1\n\t\t\t\telif 3 <= mx[r][c] <= 6 and 3 <= mx[1 - r][c] <= 6:\n\t\t\t\t\tvis[1 - r][c + 1] = 1\n\tprint('YES' if vis[1][n] else 'NO')\n", "def function(a):\n\tr = 0\n\tc = 0\n\tflip = False\n\tn = len(a[0])\n\tif n == 1:\n\t\tif a[0][0] > 2 and a[1][0] > 2:\n\t\t\treturn 'YES'\n\t\telse:\n\t\t\treturn 'NO'\n\twhile c < n:\n\t\tif a[r][c] > 2 and (not flip):\n\t\t\tr = 0 if r else 1\n\t\t\tflip = True\n\t\telif flip and a[r][c] <= 2:\n\t\t\treturn 'NO'\n\t\telif a[r][c] > 2:\n\t\t\tflip = False\n\t\t\tc += 1\n\t\telse:\n\t\t\tc += 1\n\t\t\tflip = False\n\tif r == 0:\n\t\treturn 'NO'\n\tif c == n:\n\t\treturn 'YES'\n\treturn 'NO'\nn = int(input())\nfor _ in range(n):\n\t_ = input()\n\ta = []\n\ta.append(list(map(int, input())))\n\ta.append(list(map(int, input())))\n\tprint(function(a))\n", "def soln() -> None:\n\n\tdef logic() -> None:\n\t\tn = int(input())\n\t\tA = list(input())\n\t\tB = list(input())\n\t\tone = ('1', '2')\n\t\ttwo = ('3', '4', '5', '6')\n\t\tshift = False\n\t\tfor (i, j) in zip(A, B):\n\t\t\tif not shift:\n\t\t\t\tif i not in one:\n\t\t\t\t\tshift = not shift\n\t\t\t\t\tif j not in two:\n\t\t\t\t\t\tprint('NO')\n\t\t\t\t\t\tbreak\n\t\t\telif j not in one:\n\t\t\t\tshift = not shift\n\t\t\t\tif i not in two:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\telse:\n\t\t\tif shift:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\tfor _ in range(int(input())):\n\t\tlogic()\nsoln()\n", "for i in range(int(input())):\n\tn = int(input())\n\t(s1, s2) = (input(), input())\n\tb = [[int(s1[i]), int(s2[i])] for i in range(n)][::-1]\n\ta = 1\n\tans = 'YES'\n\tfor i in b:\n\t\tif i[a] > 2:\n\t\t\tif i[a ^ 1] < 3:\n\t\t\t\tans = 'NO'\n\t\t\telse:\n\t\t\t\ta ^= 1\n\tif a != 0:\n\t\tans = 'NO'\n\tprint(ans)\n", "q = int(input())\nres = list()\nfor i in range(q):\n\tn = int(input())\n\tpt = input()\n\tpb = input()\n\tflag = True\n\tcounter = 1\n\tfor i in range(n):\n\t\tif counter == 1:\n\t\t\tif pt[i] == '3' or pt[i] == '4' or pt[i] == '5' or (pt[i] == '6'):\n\t\t\t\tif pb[i] == '3' or pb[i] == '4' or pb[i] == '5' or (pb[i] == '6'):\n\t\t\t\t\tcounter = 2\n\t\t\t\t\tflag = True\n\t\t\t\telse:\n\t\t\t\t\tflag = False\n\t\t\t\t\tbreak\n\t\telif counter == 2:\n\t\t\tif pb[i] == '3' or pb[i] == '4' or pb[i] == '5' or (pb[i] == '6'):\n\t\t\t\tflag = False\n\t\t\t\tif pt[i] == '3' or pt[i] == '4' or pt[i] == '5' or (pt[i] == '6'):\n\t\t\t\t\tcounter = 1\n\t\t\t\t\tflag = True\n\t\t\t\telse:\n\t\t\t\t\tflag = False\n\t\t\t\t\tbreak\n\tif counter == 2 and flag == True:\n\t\tres.append('YES')\n\telse:\n\t\tres.append('NO')\nfor i in res:\n\tprint(i)\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tp = 0\n\ta = [1, 1]\n\ta[0] = input()\n\ta[1] = input()\n\t(f, h, i) = (0, 1, 0)\n\twhile i < n - 1:\n\t\tk = a[h - 1][i]\n\t\tif f == 0:\n\t\t\tif k == '1' or k == '2':\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tif h == 1:\n\t\t\t\t\th = 2\n\t\t\t\telse:\n\t\t\t\t\th = 1\n\t\t\t\tf = 1\n\t\telif k == '1' or k == '2':\n\t\t\tprint('NO')\n\t\t\tp = p + 1\n\t\t\tbreak\n\t\telse:\n\t\t\tf = 0\n\t\t\ti += 1\n\tif p == 0:\n\t\tif h == 2:\n\t\t\tk = a[h - 1][i]\n\t\t\tif k == '1' or k == '2':\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\telse:\n\t\t\t(k, t) = (a[0][i], a[1][i])\n\t\t\tz = ['3', '4', '5', '6']\n\t\t\tif k in z and t in z:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\tt1 = list(input())\n\tt2 = list(input())\n\tl1 = list(t1)\n\tl2 = list(t2)\n\tflag = 0\n\tfor i in range(n):\n\t\tif int(l1[i]) >= 3:\n\t\t\tif int(l2[i]) >= 3:\n\t\t\t\t(l1, l2) = (l2, l1)\n\t\t\telse:\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\tif flag == 1:\n\t\tprint('NO')\n\telif l1 == t2 and l1 != t1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def main():\n\tq = int(input())\n\tfor _ in range(q):\n\t\tn = int(input())\n\t\trow1 = [0] + [int(x) for x in input()]\n\t\trow2 = [0] + [int(x) for x in input()]\n\t\ti = 1\n\t\tj = 0\n\t\tok = True\n\t\twhile j < n and ok:\n\t\t\tif i == 1:\n\t\t\t\tif row1[j + 1] <= 2:\n\t\t\t\t\tj += 1\n\t\t\t\telif row2[j + 1] >= 3:\n\t\t\t\t\ti = 2\n\t\t\t\t\tj += 1\n\t\t\t\telse:\n\t\t\t\t\tok = False\n\t\t\telif row2[j + 1] <= 2:\n\t\t\t\tj += 1\n\t\t\telif row1[j + 1] >= 3:\n\t\t\t\ti = 1\n\t\t\t\tj += 1\n\t\t\telse:\n\t\t\t\tok = False\n\t\tif not ok:\n\t\t\tprint('NO')\n\t\telif i == 2:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\treturn\nimport sys\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\ndef oneLineArrayPrint(arr):\n\tprint(' '.join([str(x) for x in arr]))\n\ndef multiLineArrayPrint(arr):\n\tprint('\\n'.join([str(x) for x in arr]))\n\ndef multiLineArrayOfArraysPrint(arr):\n\tprint('\\n'.join([' '.join([str(x) for x in y]) for y in arr]))\n\ndef readIntArr():\n\treturn [int(x) for x in input().split()]\n\ndef makeArr(defaultValFactory, dimensionArr):\n\tdv = defaultValFactory\n\tda = dimensionArr\n\tif len(da) == 1:\n\t\treturn [dv() for _ in range(da[0])]\n\telse:\n\t\treturn [makeArr(dv, da[1:]) for _ in range(da[0])]\n\ndef queryInteractive(i, j):\n\tprint('? {} {}'.format(i, j))\n\tsys.stdout.flush()\n\treturn int(input())\n\ndef answerInteractive(ans):\n\tprint('! {}'.format(' '.join([str(x) for x in ans])))\n\tsys.stdout.flush()\ninf = float('inf')\nMOD = 10 ** 9 + 7\nfor _abc in range(1):\n\tmain()\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\tl1 = list(input())\n\tl1 = [int(i) for i in l1]\n\tl2 = list(input())\n\tl2 = [int(i) for i in l2]\n\tl = [l1, l2]\n\ta = 0\n\tb = 0\n\tpossible = 'YES'\n\twhile True:\n\t\tif b == n and a == 1:\n\t\t\tbreak\n\t\telif b == n and a == 0:\n\t\t\tpossible = 'NO'\n\t\t\tbreak\n\t\telif l[a][b] == 1 or l[a][b] == 2:\n\t\t\tb += 1\n\t\telif a == 0 and l[a + 1][b] > 2:\n\t\t\ta += 1\n\t\t\tb += 1\n\t\telif a == 1 and l[a - 1][b] > 2:\n\t\t\tb += 1\n\t\t\ta -= 1\n\t\telse:\n\t\t\tpossible = 'NO'\n\t\t\tbreak\n\tprint(possible)\n", "for _ in range(int(input())):\n\tn = int(input())\n\ta = list(map('12'.__contains__, input().strip()))\n\tb = list(map('12'.__contains__, input().strip()))\n\t(u, d) = (True, False)\n\tfor i in range(n):\n\t\tif a[i]:\n\t\t\tif not b[i]:\n\t\t\t\td = False\n\t\telif b[i]:\n\t\t\tu = False\n\t\telse:\n\t\t\t(u, d) = (d, u)\n\t\tif not (u or d):\n\t\t\tbreak\n\tprint('YES' if d else 'NO')\n", "from sys import stdin, exit\nfrom typing import List, Tuple\n\ndef swap_row(row: int) -> int:\n\treturn abs(row - 1)\n\ndef is_curved(pipe: int) -> bool:\n\treturn 3 <= pipe <= 6\n\ndef is_straight(pipe: int) -> bool:\n\treturn 1 <= pipe <= 2\n\ndef can_water_flow(pipes: List[List[int]]) -> bool:\n\tcurr_row = 0\n\tfor i in range(len(pipes[0])):\n\t\tif is_straight(pipes[curr_row][i]):\n\t\t\tcontinue\n\t\telif is_straight(pipes[swap_row(curr_row)][i]):\n\t\t\treturn False\n\t\telse:\n\t\t\tcurr_row = swap_row(curr_row)\n\treturn curr_row == 1\nqueries = int(stdin.readline().rstrip())\nfor _ in range(queries):\n\tstdin.readline()\n\tpipes = [None, None]\n\tpipes[0] = [int(v) for v in stdin.readline().rstrip()]\n\tpipes[1] = [int(v) for v in stdin.readline().rstrip()]\n\tprint(('NO', 'YES')[can_water_flow(pipes)])\n", "import sys\ninput = sys.stdin.readline\nfrom collections import *\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tpipes = ['', '']\n\tpipes[0] = input().strip()\n\tpipes[1] = input().strip()\n\tpos = 0\n\tans = 'YES'\n\tfor i in range(n):\n\t\tif pipes[pos][i] > '2':\n\t\t\tif pipes[1 - pos][i] > '2':\n\t\t\t\tpos = 1 - pos\n\t\t\telse:\n\t\t\t\tans = 'NO'\n\t\t\t\tbreak\n\tif pos == 0:\n\t\tans = 'NO'\n\tprint(ans)\n", "import sys\ninput = lambda : sys.stdin.readline()\nMOD = 1000000007\nii = lambda : int(input())\nsi = lambda : input()\ndgl = lambda : list(map(int, input()))\nf = lambda : list(map(int, input().split()))\nil = lambda : list(map(int, input().split()))\nls = lambda : list(input())\nlstr = lambda : list(input().split())\nst2 = {'3', '4', '5', '6'}\nfor _ in range(ii()):\n\tn = ii()\n\ts1 = si()\n\ts2 = si()\n\tl = [s1, s2]\n\tpfg = 0\n\tfg = 0\n\tfor i in range(n):\n\t\tif l[pfg][i] in st2:\n\t\t\tif not l[pfg ^ 1][i] in st2:\n\t\t\t\tfg = 1\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tpfg ^= 1\n\tif fg == 0 and pfg == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "from collections import defaultdict, Counter\nimport os\nimport sys\nfrom io import BytesIO, IOBase\nii = lambda : int(input())\nlmii = lambda : list(map(int, input().split()))\nslmii = lambda : sorted(map(int, input().split()))\nli = lambda : list(input())\nmii = lambda : map(int, input().split())\nmsi = lambda : map(str, input().split())\n\ndef gcd(a, b):\n\tif b == 0:\n\t\treturn a\n\treturn gcd(b, a % b)\n\ndef lcm(a, b):\n\treturn a * b // gcd(a, b)\n\ndef main():\n\tfor _ in ' ' * int(input()):\n\t\tn = ii()\n\t\ta = li()\n\t\tb = li()\n\t\tfor i in range(n):\n\t\t\tif int(a[i]) in [1, 2]:\n\t\t\t\ta[i] = 's'\n\t\t\telse:\n\t\t\t\ta[i] = 't'\n\t\t\tif int(b[i]) in [1, 2]:\n\t\t\t\tb[i] = 's'\n\t\t\telse:\n\t\t\t\tb[i] = 't'\n\t\ts = 'YES'\n\t\tf = 1\n\t\ti = 0\n\t\twhile 1:\n\t\t\tif f == 2 and i == n - 1:\n\t\t\t\tif b[i] == 't':\n\t\t\t\t\tif a[i] == '1':\n\t\t\t\t\t\tb[i] = '1'\n\t\t\t\t\t\tbreak\n\t\t\t\t\telse:\n\t\t\t\t\t\ts = 'NO'\n\t\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tb[i] = '1'\n\t\t\t\t\tbreak\n\t\t\tif f == 1:\n\t\t\t\tif a[i] == 't':\n\t\t\t\t\tif i == 0 or a[i - 1] == '1':\n\t\t\t\t\t\tif b[i] == 's':\n\t\t\t\t\t\t\ts = 'NO'\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\ta[i] = '1'\n\t\t\t\t\t\tif i:\n\t\t\t\t\t\t\ta[i - 1] = 'f'\n\t\t\t\t\t\tf = 2\n\t\t\t\t\telif i + 1 < n:\n\t\t\t\t\t\ta[i] = '1'\n\t\t\t\t\t\tb[i] = 'f'\n\t\t\t\t\t\ti += 1\n\t\t\t\t\telse:\n\t\t\t\t\t\ts = 'NO'\n\t\t\t\t\t\tbreak\n\t\t\t\telif i + 1 < n:\n\t\t\t\t\ta[i] = '1'\n\t\t\t\t\ti += 1\n\t\t\t\telse:\n\t\t\t\t\ts = 'NO'\n\t\t\t\t\tbreak\n\t\t\telif b[i] == 't':\n\t\t\t\tif i > 0 and b[i - 1] == '1':\n\t\t\t\t\tif a[i] == 's':\n\t\t\t\t\t\ts = 'NO'\n\t\t\t\t\t\tbreak\n\t\t\t\t\tb[i] = '1'\n\t\t\t\t\tb[i - 1] = 'f'\n\t\t\t\t\tf = 1\n\t\t\t\telif i + 1 < n:\n\t\t\t\t\tb[i] = '1'\n\t\t\t\t\ta[i] = 'f'\n\t\t\t\t\ti += 1\n\t\t\t\telse:\n\t\t\t\t\ts = 'NO'\n\t\t\t\t\tbreak\n\t\t\telif i + 1 < n:\n\t\t\t\tb[i] = '1'\n\t\t\t\ta[i] = 'f'\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\ts = 'NO'\n\t\t\t\tbreak\n\t\tprint(s)\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nmain()\n", "import re, math, decimal, bisect\n\ndef read():\n\treturn input().strip()\n\ndef iread():\n\treturn int(input().strip())\n\ndef viread():\n\treturn [int(_) for _ in input().strip().split()]\nfor i in range(iread()):\n\tn = iread()\n\tupper = read()\n\tlower = read()\n\tup = True\n\tcol = 0\n\twhile col < n:\n\t\tif up:\n\t\t\tif upper[col] == '1' or upper[col] == '2':\n\t\t\t\tcol += 1\n\t\t\telif lower[col] != '1' and lower[col] != '2':\n\t\t\t\tup = False\n\t\t\t\tcol += 1\n\t\t\telse:\n\t\t\t\tbreak\n\t\telif lower[col] == '1' or lower[col] == '2':\n\t\t\tcol += 1\n\t\telif upper[col] != '1' and upper[col] != '2':\n\t\t\tup = True\n\t\t\tcol += 1\n\t\telse:\n\t\t\tbreak\n\tif col == n and up == False:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "from sys import stdin\n\ndef main():\n\tl = stdin.read().splitlines()\n\t(l, l1) = (l[2::3], l[3::3])\n\tfor (i, ab) in enumerate(zip(l, l1)):\n\t\tp = 2\n\t\tfor (a, b) in zip(*ab):\n\t\t\tp = (0, 2, 1, 0, 1, 0, 0, 0, 2, 0, 1, 2)[((a < '3') * 2 + (b < '3')) * 3 + p]\n\t\tl[i] = ('NO', 'YES')[p & 1]\n\tprint('\\n'.join(l))\nmain()\n", "def solve(matrix, n):\n\t(i, j) = (0, 0)\n\tprev = 'L'\n\twhile j < n:\n\t\tif matrix[i][j] == '1' or matrix[i][j] == '2':\n\t\t\tif prev != 'L':\n\t\t\t\tprint('NO')\n\t\t\t\treturn\n\t\t\tj += 1\n\t\t\tprev = 'L'\n\t\telif matrix[i][j] == '3' or matrix[i][j] == '4' or matrix[i][j] == '5' or (matrix[i][j] == '6'):\n\t\t\tif i == 0:\n\t\t\t\tif prev == 'L':\n\t\t\t\t\ti = 1\n\t\t\t\t\tprev = 'U'\n\t\t\t\telse:\n\t\t\t\t\tj += 1\n\t\t\t\t\tprev = 'L'\n\t\t\telif prev == 'L':\n\t\t\t\ti = 0\n\t\t\t\tprev = 'D'\n\t\t\telse:\n\t\t\t\tj += 1\n\t\t\t\tprev = 'L'\n\tif i == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\nq = int(input())\nwhile q > 0:\n\tn = int(input())\n\tsolve([input(), input()], n)\n\tq -= 1\n", "q = int(input().split()[0])\nfor x in range(q):\n\ta = int(input().split()[0])\n\ts1 = input()\n\ts2 = input()\n\tc = 1\n\tfor i in range(a):\n\t\tif c == 1:\n\t\t\tif ord(s1[i]) > 50:\n\t\t\t\tc = 2\n\t\t\t\tif ord(s2[i]) <= 50:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tc = 3\n\t\t\t\t\tbreak\n\t\telif ord(s2[i]) > 50:\n\t\t\tc = 1\n\t\t\tif ord(s1[i]) <= 50:\n\t\t\t\tprint('NO')\n\t\t\t\tc = 3\n\t\t\t\tbreak\n\tif c == 2:\n\t\tprint('YES')\n\telif c == 1:\n\t\tprint('NO')\n", "def solve():\n\tn = int(input())\n\ta = [list(map(lambda x: 1 if int(x) <= 2 else 2, input())) for i in range(2)]\n\tj = 0\n\tfor i in range(n):\n\t\tif a[j][i] == 2:\n\t\t\tif a[j ^ 1][i] == 1:\n\t\t\t\treturn False\n\t\t\tj ^= 1\n\treturn j == 1\n\ndef main():\n\tq = int(input())\n\tfor i in range(q):\n\t\tprint('YES' if solve() else 'NO')\nmain()\n", "t = int(input())\nfor i in range(t):\n\tn = int(input())\n\ta = [list(map(int, input())), list(map(int, input()))]\n\tpred = 'L'\n\tc = [0, 0]\n\tdone = False\n\twhile c[0] < 2 and c[1] < n and (not done):\n\t\tif a[c[0]][c[1]] < 3:\n\t\t\tif pred == 'L':\n\t\t\t\tc[1] += 1\n\t\t\telse:\n\t\t\t\tbreak\n\t\telif c[0] == 0:\n\t\t\tif pred == 'L':\n\t\t\t\tpred = 'UP'\n\t\t\t\tc[0] += 1\n\t\t\telse:\n\t\t\t\tpred = 'L'\n\t\t\t\tc[1] += 1\n\t\telif pred == 'L':\n\t\t\tpred = 'DOWN'\n\t\t\tc[0] -= 1\n\t\telse:\n\t\t\tpred = 'L'\n\t\t\tc[1] += 1\n\t\tif c == [1, n]:\n\t\t\tdone = True\n\tif done:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ta = [input(), input()]\n\tr = c = 0\n\trowChange = False\n\twhile c < n:\n\t\tif rowChange == True and a[r][c] in '3456':\n\t\t\tc += 1\n\t\t\trowChange = False\n\t\telif rowChange == False and a[r][c] in '12':\n\t\t\tc += 1\n\t\telif rowChange == False and a[r][c] in '3456':\n\t\t\tr = (r + 1) % 2\n\t\t\trowChange = True\n\t\telse:\n\t\t\tr = -1\n\t\t\tbreak\n\tif r == 1 and c == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "n = int(input())\nfor i in range(n):\n\tq = int(input())\n\ts1 = input()\n\ts2 = input()\n\ta = [[], []]\n\tfor j in range(q):\n\t\tif s1[j] == '1' or s1[j] == '2':\n\t\t\ta[0].append(1)\n\t\telse:\n\t\t\ta[0].append(2)\n\t\tif s2[j] == '1' or s2[j] == '2':\n\t\t\ta[1].append(1)\n\t\telse:\n\t\t\ta[1].append(2)\n\tcounter = 0\n\ttyp = 0\n\tflag = False\n\twhile counter < q:\n\t\tsv_counter = counter\n\t\twhile counter < q and a[typ % 2][counter] == 1:\n\t\t\tcounter += 1\n\t\tif counter < q:\n\t\t\tif a[0][counter] == 2 and a[1][counter] == 2:\n\t\t\t\tcounter += 1\n\t\t\t\ttyp += 1\n\t\t\telse:\n\t\t\t\tflag = True\n\t\tif counter == sv_counter:\n\t\t\tcounter += 1\n\tif not flag and typ % 2 == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\ndata = int(input())\nfor i in range(data):\n\tans = 0\n\tnum = int(input())\n\tarr = []\n\tarr.append(str(input().strip()))\n\tarr.append(str(input().strip()))\n\t(inf, virus, corona) = (0, 0, 0)\n\twhile inf < num:\n\t\tif arr[corona][inf] == '1' or arr[corona][inf] == '2':\n\t\t\tif virus == 0:\n\t\t\t\tinf += 1\n\t\t\telse:\n\t\t\t\tbreak\n\t\telif virus == 0:\n\t\t\tvirus = 1\n\t\t\tif corona == 0:\n\t\t\t\tcorona = 1\n\t\t\telse:\n\t\t\t\tcorona = 0\n\t\telse:\n\t\t\tvirus = 0\n\t\t\tinf += 1\n\tif inf == num and corona == 1:\n\t\tprint('YES')\n\t\tans = 1\n\tif ans == 0:\n\t\tprint('NO')\n", "from sys import stdin, stdout\nquery = int(input())\nfor i in range(query):\n\tn = int(input())\n\trows = [list(input()), list(input())]\n\trowi = 0\n\tans = True\n\tfor k in range(n):\n\t\tif rows[rowi][k] >= '3':\n\t\t\tif rows[rowi - 1][k] <= '2':\n\t\t\t\tans = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\trowi = (rowi - 1) % 2\n\tif rowi == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES' if ans else 'NO')\n", "def main():\n\tn = int(input())\n\tfor _ in range(n):\n\t\tnum = int(input())\n\t\ttop = input()\n\t\tbottom = input()\n\t\tcheck = ['1', '2']\n\t\tflag = True\n\t\tbot = False\n\t\tfor i in range(num):\n\t\t\tif top[i] in check and (not bot):\n\t\t\t\tcontinue\n\t\t\telif bottom[i] in check and bot:\n\t\t\t\tcontinue\n\t\t\telif top[i] not in check and bottom[i] not in check:\n\t\t\t\tif bot:\n\t\t\t\t\tbot = False\n\t\t\t\telse:\n\t\t\t\t\tbot = True\n\t\t\telse:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\tif flag and bot:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\nmain()\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nimport math\nimport itertools\nimport bisect\nimport heapq\n\ndef main():\n\tpass\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\ndef binary(n):\n\treturn bin(n).replace('0b', '')\n\ndef decimal(s):\n\treturn int(s, 2)\n\ndef pow2(n):\n\tp = 0\n\twhile n > 1:\n\t\tn //= 2\n\t\tp += 1\n\treturn p\n\ndef primeFactors(n):\n\tl = []\n\twhile n % 2 == 0:\n\t\tl.append(2)\n\t\tn = n / 2\n\tfor i in range(3, int(math.sqrt(n)) + 1, 2):\n\t\twhile n % i == 0:\n\t\t\tl.append(i)\n\t\t\tn = n / i\n\tif n > 2:\n\t\tl.append(int(n))\n\treturn l\n\ndef isPrime(n):\n\tif n == 1:\n\t\treturn False\n\telse:\n\t\troot = int(n ** 0.5)\n\t\troot += 1\n\t\tfor i in range(2, root):\n\t\t\tif n % i == 0:\n\t\t\t\treturn False\n\t\treturn True\n\ndef maxPrimeFactors(n):\n\tmaxPrime = -1\n\twhile n % 2 == 0:\n\t\tmaxPrime = 2\n\t\tn >>= 1\n\tfor i in range(3, int(math.sqrt(n)) + 1, 2):\n\t\twhile n % i == 0:\n\t\t\tmaxPrime = i\n\t\t\tn = n / i\n\tif n > 2:\n\t\tmaxPrime = n\n\treturn int(maxPrime)\n\ndef countcon(s, i):\n\tc = 0\n\tch = s[i]\n\tfor i in range(i, len(s)):\n\t\tif s[i] == ch:\n\t\t\tc += 1\n\t\telse:\n\t\t\tbreak\n\treturn c\n\ndef lis(arr):\n\tn = len(arr)\n\tlis = [1] * n\n\tfor i in range(1, n):\n\t\tfor j in range(0, i):\n\t\t\tif arr[i] > arr[j] and lis[i] < lis[j] + 1:\n\t\t\t\tlis[i] = lis[j] + 1\n\tmaximum = 0\n\tfor i in range(n):\n\t\tmaximum = max(maximum, lis[i])\n\treturn maximum\n\ndef isSubSequence(str1, str2):\n\tm = len(str1)\n\tn = len(str2)\n\tj = 0\n\ti = 0\n\twhile j < m and i < n:\n\t\tif str1[j] == str2[i]:\n\t\t\tj = j + 1\n\t\ti = i + 1\n\treturn j == m\n\ndef maxfac(n):\n\troot = int(n ** 0.5)\n\tfor i in range(2, root + 1):\n\t\tif n % i == 0:\n\t\t\treturn n // i\n\treturn n\n\ndef p2(n):\n\tc = 0\n\twhile n % 2 == 0:\n\t\tn //= 2\n\t\tc += 1\n\treturn c\n\ndef seive(n):\n\tprimes = [True] * (n + 1)\n\tprimes[1] = primes[0] = False\n\tfor i in range(2, n + 1):\n\t\tif primes[i]:\n\t\t\tfor j in range(i + i, n + 1, i):\n\t\t\t\tprimes[j] = False\n\tp = []\n\tfor i in range(0, n + 1):\n\t\tif primes[i]:\n\t\t\tp.append(i)\n\treturn p\n\ndef ncr(n, r, p):\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\n\ndef denofactinverse(n, m):\n\tfac = 1\n\tfor i in range(1, n + 1):\n\t\tfac = fac * i % m\n\treturn pow(fac, m - 2, m)\n\ndef numofact(n, m):\n\tfac = 1\n\tfor i in range(1, n + 1):\n\t\tfac = fac * i % m\n\treturn fac\n\ndef chk(n, d):\n\tif str(d) in str(n):\n\t\treturn True\n\treturn False\nfor xyz in range(0, int(input())):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tup = True\n\ttype = {'1', '2'}\n\tans = True\n\tfor i in range(0, n + 1):\n\t\tif i == n:\n\t\t\tif up == True:\n\t\t\t\tans = False\n\t\t\tbreak\n\t\tif up:\n\t\t\tif s1[i] not in type:\n\t\t\t\tup = False\n\t\t\t\tif s2[i] in type:\n\t\t\t\t\tans = False\n\t\t\t\t\tbreak\n\t\telif s2[i] not in type:\n\t\t\tup = True\n\t\t\tif s1[i] in type:\n\t\t\t\tans = False\n\t\t\t\tbreak\n\tif ans:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "req = int(input())\nfor z in range(req):\n\tisit = True\n\tamount = int(input())\n\tcurrent = [list(map(int, list(input()))), list(map(int, list(input())))]\n\twater = 0\n\tfor i in range(amount):\n\t\tif current[0][i] <= 2:\n\t\t\tcurrent[0][i] = 1\n\t\telse:\n\t\t\tcurrent[0][i] = 2\n\t\tif current[1][i] <= 2:\n\t\t\tcurrent[1][i] = 1\n\t\telse:\n\t\t\tcurrent[1][i] = 2\n\t\tif current[0][i] == 2 and current[1][i] == 2:\n\t\t\twater = 1 - water\n\t\telif current[water][i] == 1:\n\t\t\tpass\n\t\telse:\n\t\t\tisit = False\n\t\t\tbreak\n\tif water == 0:\n\t\tisit = False\n\tif isit:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "n = int(input())\nfor i in range(0, n):\n\tk = int(input())\n\tstr1 = input()\n\tstr2 = input()\n\tstr0 = str1 + str2\n\ts = 0\n\tx = 1\n\twhile True:\n\t\tif s == k - 1:\n\t\t\tif int(str0[s]) <= 2:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ts += k\n\t\t\t\tx = -1\n\t\tif s == 2 * k - 1:\n\t\t\tif (int(str0[s]) - 2.5) * x < 0:\n\t\t\t\tprint('YES')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\tif int(str0[s]) <= 2:\n\t\t\tif x == -1:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ts += 1\n\t\telse:\n\t\t\tif x == 1:\n\t\t\t\ts = (s + k) % (2 * k)\n\t\t\telse:\n\t\t\t\ts += 1\n\t\t\tx = -x\n", "import sys\nfrom collections import deque, defaultdict\nfrom fractions import gcd\nfrom math import ceil\n\ndef N():\n\treturn int(sys.stdin.readline())\n\ndef NK():\n\treturn map(int, sys.stdin.readline().split())\n\ndef LS_I():\n\treturn [int(x) for x in sys.stdin.readline().split()]\n\ndef LS_S():\n\treturn list(input())\n\ndef main():\n\tq = N()\n\tfor _ in range(q):\n\t\tn = N()\n\t\t(ls1, ls2) = ([0 for _ in range(n)], [0 for _ in range(n)])\n\t\tfor (num, i) in enumerate(list(input())):\n\t\t\tif int(i) == 1 or int(i) == 2:\n\t\t\t\tls1[num] = 1\n\t\t\telse:\n\t\t\t\tpass\n\t\tfor (num, i) in enumerate(list(input())):\n\t\t\tif int(i) == 1 or int(i) == 2:\n\t\t\t\tls2[num] = 1\n\t\t\telse:\n\t\t\t\tpass\n\t\tflg = False\n\t\tans = 'YES'\n\t\tfor (i, j) in zip(ls1, ls2):\n\t\t\tif flg == False:\n\t\t\t\tif i == 1:\n\t\t\t\t\tpass\n\t\t\t\telif int(i + j) == 0:\n\t\t\t\t\tflg = True\n\t\t\t\telse:\n\t\t\t\t\tans = 'NO'\n\t\t\t\t\tbreak\n\t\t\telif j == 1:\n\t\t\t\tpass\n\t\t\telif int(i + j) == 0:\n\t\t\t\tflg = False\n\t\t\telse:\n\t\t\t\tans = 'NO'\n\t\t\t\tbreak\n\t\tif flg:\n\t\t\tprint(ans)\n\t\telse:\n\t\t\tprint('NO')\nmain()\n", "for _ in range(int(input())):\n\tn = int(input())\n\tf = [*map(int, input())]\n\ts = [*map(int, input())]\n\tt = 1\n\tans = 'YES'\n\tfor i in range(n - 1, -1, -1):\n\t\tif t:\n\t\t\tif s[i] > 2:\n\t\t\t\tt = 0\n\t\t\t\ts[i] = 6\n\t\t\t\tif f[i] > 2:\n\t\t\t\t\tf[i] = 4\n\t\t\t\telse:\n\t\t\t\t\tans = 'NO'\n\t\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ts[i] = 2\n\t\telif f[i] > 2:\n\t\t\tt = 1\n\t\t\tf[i] = 3\n\t\t\tif s[i] > 2:\n\t\t\t\ts[i] = 5\n\t\t\telse:\n\t\t\t\tans = 'NO'\n\t\t\t\tbreak\n\t\telse:\n\t\t\tf[i] = 2\n\tprint(ans if t == 0 else 'NO')\n", "answer = []\nfor _ in range(int(input())):\n\tn = int(input())\n\tuc = input()\n\tlc = input()\n\tcount = 0\n\tfor (u, l) in zip(uc, lc):\n\t\tif u in ['3', '4', '5', '6'] and l in ['1', '2'] and (count % 2 == 0):\n\t\t\tanswer.append('NO')\n\t\t\tbreak\n\t\tif l in ['3', '4', '5', '6'] and u in ['1', '2'] and (count % 2 == 1):\n\t\t\tanswer.append('NO')\n\t\t\tbreak\n\t\tif u in ['3', '4', '5', '6'] and l in ['3', '4', '5', '6']:\n\t\t\tcount += 1\n\telse:\n\t\tif count % 2:\n\t\t\tanswer.append('YES')\n\t\telse:\n\t\t\tanswer.append('NO')\nfor ans in answer:\n\tprint(ans)\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ta = str(input())\n\ta = list(map(int, a))\n\tb = str(input())\n\tb = list(map(int, b))\n\tpipe = [a, b]\n\tj = 0\n\tk = 0\n\tno = 0\n\twhile k < n:\n\t\tif pipe[j][k] <= 2:\n\t\t\tk = k + 1\n\t\telif j == 0:\n\t\t\tif pipe[j + 1][k] <= 2:\n\t\t\t\tno = 1\n\t\t\t\tbreak\n\t\t\tj = j + 1\n\t\t\tk = k + 1\n\t\telse:\n\t\t\tif pipe[j - 1][k] <= 2:\n\t\t\t\tno = 1\n\t\t\t\tbreak\n\t\t\tj = j - 1\n\t\t\tk = k + 1\n\tif no == 1:\n\t\tprint('NO')\n\telif j == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ts = input()\n\tr = input()\n\tx = [s, r]\n\ti = 0\n\tflag = 0\n\tfor j in range(n):\n\t\tif x[i][j] == '1' or x[i][j] == '2':\n\t\t\tcontinue\n\t\ti ^= 1\n\t\tif x[i][j] == '1' or x[i][j] == '2':\n\t\t\tflag = 1\n\t\t\tbreak\n\tif flag == 0 and i == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "from sys import stdin\nimport math\nA = int(stdin.readline())\nfor t in range(0, A):\n\tB = int(stdin.readline())\n\tC = stdin.readline()\n\tD = stdin.readline()\n\trow = 1\n\tcolumn = 1\n\tstate = 1\n\tP = 0\n\twhile column <= B:\n\t\tif row == 1:\n\t\t\tif state == 1:\n\t\t\t\tif C[column - 1] == '1' or C[column - 1] == '2':\n\t\t\t\t\tif column == B:\n\t\t\t\t\t\tprint('NO')\n\t\t\t\t\t\tP = 1\n\t\t\t\t\t\tbreak\n\t\t\t\t\telse:\n\t\t\t\t\t\tcolumn += 1\n\t\t\t\telse:\n\t\t\t\t\trow = 2\n\t\t\t\t\tstate = 2\n\t\t\telif state == 4:\n\t\t\t\tif C[column - 1] == '1' or C[column - 1] == '2':\n\t\t\t\t\tP = 1\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\trow = 1\n\t\t\t\t\tif column == B:\n\t\t\t\t\t\tprint('NO')\n\t\t\t\t\t\tP = 1\n\t\t\t\t\t\tbreak\n\t\t\t\t\telse:\n\t\t\t\t\t\tcolumn += 1\n\t\t\t\t\t\tstate = 1\n\t\tif row == 2:\n\t\t\tif state == 1:\n\t\t\t\tif D[column - 1] == '1' or D[column - 1] == '2':\n\t\t\t\t\tcolumn += 1\n\t\t\t\telse:\n\t\t\t\t\tstate = 4\n\t\t\t\t\trow = 1\n\t\t\telif state == 2:\n\t\t\t\tif D[column - 1] == '1' or D[column - 1] == '2':\n\t\t\t\t\tP = 1\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tcolumn += 1\n\t\t\t\t\tstate = 1\n\tif P == 0:\n\t\tprint('YES')\n", "for itr in range(int(input())):\n\tn = int(input())\n\tarr = []\n\ta = list(str(input()))\n\tb = list(str(input()))\n\tfor i in range(n):\n\t\tif a[i] == '1' or a[i] == '2':\n\t\t\ta[i] = 0\n\t\telse:\n\t\t\ta[i] = 1\n\t\tif b[i] == '1' or b[i] == '2':\n\t\t\tb[i] = 0\n\t\telse:\n\t\t\tb[i] = 1\n\tarr.append(a)\n\tarr.append(b)\n\ti = 0\n\tj = 0\n\tans = 1\n\tdirection = 0\n\twhile 1:\n\t\tif arr[i][j] == 0:\n\t\t\tif direction == 0:\n\t\t\t\tj += 1\n\t\t\telif direction == 1:\n\t\t\t\ti += 1\n\t\t\telif direction == 2:\n\t\t\t\ti -= 1\n\t\telif direction == 0:\n\t\t\tif i == 0:\n\t\t\t\ti = 1\n\t\t\t\tdirection = 1\n\t\t\telse:\n\t\t\t\ti = 0\n\t\t\t\tdirection = 2\n\t\telif direction == 1:\n\t\t\tdirection = 0\n\t\t\tj += 1\n\t\telif direction == 2:\n\t\t\tdirection = 0\n\t\t\tj += 1\n\t\tif i == 1 and j == n:\n\t\t\tbreak\n\t\tif i > 1 or i < 0 or j >= n:\n\t\t\tans = 0\n\t\t\tbreak\n\tif ans:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tc = 0\n\t(first, second) = ([], [])\n\tfor i in range(n):\n\t\tif a[i] == '1' or a[i] == '2':\n\t\t\tfirst.append(1)\n\t\telse:\n\t\t\tfirst.append(2)\n\t\tif b[i] == '1' or b[i] == '2':\n\t\t\tsecond.append(1)\n\t\telse:\n\t\t\tsecond.append(2)\n\twater = 0\n\tf = 0\n\t(a, b) = (first.copy(), second.copy())\n\tfor i in range(n):\n\t\tif water == 0:\n\t\t\tif a[i] == 2:\n\t\t\t\twater = 1\n\t\t\t\tif b[i] == 1:\n\t\t\t\t\tf = 1\n\t\t\t\t\tbreak\n\t\telif b[i] == 2:\n\t\t\twater = 0\n\t\t\tif a[i] == 1:\n\t\t\t\tf = 1\n\t\t\t\tbreak\n\tif water == 1 and f == 0:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import time\nimport collections\nLOCAL = False\nstart_time = None\nif LOCAL:\n\tstart_time = time.time()\nq = int(input())\nwhile q:\n\tq -= 1\n\tn = int(input())\n\tf = input()\n\ts = input()\n\tt = True\n\tb = False\n\tlin = ['1', '2']\n\tfor i in range(n):\n\t\ttop_is_line = f[i] in lin\n\t\tbot_is_line = s[i] in lin\n\t\tnewTop = False\n\t\tnewBot = False\n\t\tif top_is_line and t:\n\t\t\tnewTop = True\n\t\tif bot_is_line and b:\n\t\t\tnewBot = True\n\t\tif not top_is_line and (not bot_is_line):\n\t\t\tnewTop = b\n\t\t\tnewBot = t\n\t\tt = newTop\n\t\tb = newBot\n\tprint('YES' if b else 'NO')\nif LOCAL:\n\tprint('--- %s seconds ---' % (time.time() - start_time))\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ts = [list(input()) for i in range(2)]\n\tu = True\n\tfor i in range(n):\n\t\tif s[0][i] == '1' or s[0][i] == '2':\n\t\t\tif s[1][i] == '1' or s[1][i] == '2':\n\t\t\t\tu = u\n\t\t\telif not u:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tu = u\n\t\telif s[1][i] == '1' or s[1][i] == '2':\n\t\t\tif u:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tu = u\n\t\telse:\n\t\t\tu ^= True\n\telse:\n\t\tif u == False:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "import sys\ninput = sys.stdin.readline\n\ndef check(N: int, P: 'Array[Array[int]]') -> str:\n\tcur = 0\n\tfor i in range(N):\n\t\tif P[cur][i] > 2:\n\t\t\tif P[cur ^ 1][i] > 2:\n\t\t\t\tcur ^= 1\n\t\t\telse:\n\t\t\t\treturn 'NO'\n\treturn 'YES' if cur else 'NO'\n\ndef main():\n\tQ = int(input())\n\tans = []\n\tfor _ in range(Q):\n\t\tN = int(input())\n\t\tP = [list(map(int, input().rstrip())) for _ in range(2)]\n\t\tans.append(check(N, P))\n\tprint('\\n'.join(map(str, ans)))\nmain()\n", "import sys\ns1 = set((1, 2))\n\nclass Direction:\n\t__slots__ = ['left', 'top', 'down']\n\n\tdef __init__(self, left, top, down):\n\t\tself.left = left\n\t\tself.top = top\n\t\tself.down = down\nmydir = Direction(left=1, top=2, down=3)\n\ndef move(arr, i, j, dir, n):\n\tif j == n:\n\t\tif dir == mydir.left and i == 1:\n\t\t\treturn True\n\t\treturn False\n\tv = arr[i][j]\n\tif v in s1:\n\t\tif dir == mydir.left:\n\t\t\treturn move(arr, i, j + 1, mydir.left, n)\n\telif i == 0:\n\t\tif dir == mydir.left:\n\t\t\treturn move(arr, 1, j, mydir.top, n)\n\t\telif dir == mydir.down:\n\t\t\treturn move(arr, 0, j + 1, mydir.left, n)\n\telif dir == mydir.left:\n\t\treturn move(arr, 0, j, mydir.down, n)\n\telif dir == mydir.top:\n\t\treturn move(arr, 1, j + 1, mydir.left, n)\n\treturn False\n\ndef solution():\n\tinput = sys.stdin.readline\n\tq = int(input())\n\tfor i in range(q):\n\t\tn = int(input())\n\t\tarr1 = [int(x) for x in input().strip()]\n\t\tarr2 = [int(x) for x in input().strip()]\n\t\tarr3 = [arr1, arr2]\n\t\ttry:\n\t\t\tout = move(arr3, 0, 0, 1, n)\n\t\t\tif out:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\texcept:\n\t\t\tprint('YES')\nsolution()\n", "(l1, l2) = (['1', '2'], ['3', '4', '5', '6'])\nfor i in range(int(input())):\n\t(n, s1, cur) = (int(input()), [input() for i in range(2)], 0)\n\tfor j in range(n):\n\t\tif s1[cur][j] in l2:\n\t\t\tcur ^= 1\n\t\t\tif s1[cur][j] not in l2:\n\t\t\t\tcur = 0\n\t\t\t\tbreak\n\tprint('YES' if cur else 'NO')\n", "q = int(input())\nwhile q > 0:\n\tn = int(input())\n\tn1 = n\n\trow1 = list(input())\n\trow2 = list(input())\n\tc_row = row1\n\tc2_row = row2\n\ti = 0\n\tline = [1, 2]\n\tcurve = [3, 4, 5, 6]\n\twhile i < n:\n\t\tif int(c_row[i]) in line:\n\t\t\ti += 1\n\t\telif int(c_row[i]) in curve:\n\t\t\tif int(c2_row[i]) in curve:\n\t\t\t\ttemp_row = c2_row\n\t\t\t\tc2_row = c_row\n\t\t\t\tc_row = temp_row\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\tif i == n and c_row is row2:\n\t\tprint('YES')\n\tif i == n and c_row is row1:\n\t\tprint('NO')\n\tq = q - 1\n", "T = int(input())\nfor i in range(T):\n\tn = int(input())\n\tl1 = input()\n\tl2 = input()\n\tl1 = list(map(int, l1))\n\tl2 = list(map(int, l2))\n\trow = 0\n\tif l1[0] == 1 or l1[0] == 2:\n\t\tpipe = 'L'\n\t\tprev = 'L'\n\t\trow = 1\n\t\tj = 1\n\telse:\n\t\tpipe = 'C'\n\t\tprev = 'T'\n\t\trow = 2\n\t\tj = 0\n\twhile j < n:\n\t\tif row == 1:\n\t\t\tx = l1[j]\n\t\t\tif x == 1 or x == 2:\n\t\t\t\tpipe = 'L'\n\t\t\telse:\n\t\t\t\tpipe = 'C'\n\t\telif row == 2:\n\t\t\tx = l2[j]\n\t\t\tif x == 1 or x == 2:\n\t\t\t\tpipe = 'L'\n\t\t\telse:\n\t\t\t\tpipe = 'C'\n\t\tif row == 1 and pipe == 'L' and (prev == 'L'):\n\t\t\tj += 1\n\t\telif row == 1 and pipe == 'L' and (prev == 'T'):\n\t\t\tbreak\n\t\t\tprint('NO')\n\t\t\tj += 1\n\t\telif row == 1 and pipe == 'C' and (prev == 'L'):\n\t\t\trow = 2\n\t\t\tprev = 'T'\n\t\telif row == 1 and pipe == 'C' and (prev == 'T'):\n\t\t\trow = 1\n\t\t\tprev = 'L'\n\t\t\tj += 1\n\t\telif row == 2 and pipe == 'L' and (prev == 'L'):\n\t\t\tj += 1\n\t\telif row == 2 and pipe == 'L' and (prev == 'T'):\n\t\t\tbreak\n\t\t\tprint('NO')\n\t\t\tj += 1\n\t\telif row == 2 and pipe == 'C' and (prev == 'L'):\n\t\t\trow = 1\n\t\t\tprev = 'T'\n\t\telif row == 2 and pipe == 'C' and (prev == 'T'):\n\t\t\trow = 2\n\t\t\tj += 1\n\t\t\tprev = 'L'\n\tif row == 2 and j == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def main():\n\tQ = int(input())\n\tdata = []\n\tfor _ in range(Q):\n\t\tN = int(input())\n\t\tS1 = [int(a) for a in list(input())]\n\t\tS2 = [int(a) for a in list(input())]\n\t\tdata.append((N, [S1, S2]))\n\tA = [3, 4, 5, 6]\n\tB = [1, 2]\n\tfor (N, S) in data:\n\t\tdp = [[0, 0] for _ in range(N + 1)]\n\t\tdp[0][0] = 1\n\t\tfor n in range(N):\n\t\t\tif S[0][n] in A and S[1][n] in A:\n\t\t\t\tdp[n + 1][0] = dp[n][1]\n\t\t\t\tdp[n + 1][1] = dp[n][0]\n\t\t\telif S[0][n] in B and S[1][n] in A:\n\t\t\t\tdp[n + 1][0] = dp[n][0]\n\t\t\t\tdp[n + 1][1] = 0\n\t\t\telif S[0][n] in A and S[1][n] in B:\n\t\t\t\tdp[n + 1][0] = 0\n\t\t\t\tdp[n + 1][1] = dp[n][1]\n\t\t\telse:\n\t\t\t\tdp[n + 1][0] = dp[n][0]\n\t\t\t\tdp[n + 1][1] = dp[n][1]\n\t\tif dp[N][1] == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\ndef __starting_point():\n\tmain()\n__starting_point()\n", "import math\nfrom collections import deque\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tlst = list()\n\trow1 = [int(x) for x in input()]\n\trow2 = [int(x) for x in input()]\n\tlst.append(row1)\n\tlst.append(row2)\n\tx = 0\n\ty = 0\n\twait = -1\n\tans = 1\n\twhile x < n:\n\t\tif wait == -1:\n\t\t\tif lst[y][x] == 1 or lst[y][x] == 2:\n\t\t\t\twait = 0\n\t\t\t\tx += 1\n\t\t\telse:\n\t\t\t\twait = 1\n\t\t\t\ty = (y + 1) % 2\n\t\telif (lst[y][x] == 1 or lst[y][x] == 2) and wait == 0:\n\t\t\twait = 0\n\t\t\tx += 1\n\t\telif lst[y][x] > 2 and wait == 0:\n\t\t\twait = 1\n\t\t\ty = (y + 1) % 2\n\t\telif lst[y][x] > 2 and wait == 1:\n\t\t\twait = 0\n\t\t\tx += 1\n\t\telse:\n\t\t\tbreak\n\tif y == 1 and x == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def solve(line1, line2, n):\n\tfor i in range(n):\n\t\tif line1[i] == '0' and line2[i] == '1' or (line1[i] == '1' and line2[i] == '0'):\n\t\t\treturn False\n\tif line1.count('0') % 2 == 0:\n\t\treturn False\n\treturn True\n\ndef main():\n\tq = int(input())\n\tfor _ in range(q):\n\t\tn = int(input())\n\t\tline1 = input().replace('2', '1')\n\t\tline2 = input().replace('2', '1')\n\t\tfor c in '3456':\n\t\t\tline1 = line1.replace(c, '0')\n\t\t\tline2 = line2.replace(c, '0')\n\t\tgrid = [line1, line2]\n\t\ti = j = 0\n\t\tprev = 1\n\t\tiprev = 0\n\t\twhile True:\n\t\t\tif not (0 <= i <= 1 and 0 <= j < n):\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\tnew_iprev = i\n\t\t\tif grid[i][j] == '0':\n\t\t\t\tif prev == 1:\n\t\t\t\t\ti = i + 1 if i == 0 else i - 1\n\t\t\t\telif prev == 0:\n\t\t\t\t\tif iprev != i:\n\t\t\t\t\t\tj += 1\n\t\t\t\t\telse:\n\t\t\t\t\t\ti = i + 1 if i == 0 else i - 1\n\t\t\t\tprev = 0\n\t\t\telse:\n\t\t\t\tif prev == 0 and iprev != i:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\t\tj += 1\n\t\t\t\tprev = 1\n\t\t\tiprev = new_iprev\n\t\t\tif i == 1 and j == n:\n\t\t\t\tprint('YES')\n\t\t\t\tbreak\nmain()\n", "from sys import setcheckinterval, stdin, setrecursionlimit\nsetcheckinterval(1000)\nsetrecursionlimit(10 ** 7)\n\ndef iin():\n\treturn int(stdin.readline())\n\ndef lin():\n\treturn list(map(int, stdin.readline().split()))\nchg = {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}}\nsol = {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): {}}\nfor _ in range(iin()):\n\tn = iin()\n\ta = [list(map(int, list(input()))), list(map(int, list(input())))]\n\tnxt = [0, 0]\n\tfor i in chg[a[0][0]]:\n\t\tif i in sol[0]:\n\t\t\ta[0][0] = i\n\t\t\tbreak\n\telse:\n\t\tprint('NO')\n\t\tcontinue\n\twhile 1:\n\t\t(x, y) = nxt\n\t\t(nx, ny) = (x, y + 1)\n\t\tif a[x][y] != 2:\n\t\t\txx = a[x][y]\n\t\t\tif xx == 3:\n\t\t\t\tnx = 0\n\t\t\t\tny = y + 1\n\t\t\telif xx == 4:\n\t\t\t\tnx = 1\n\t\t\t\tny = y\n\t\t\telif xx == 5:\n\t\t\t\tnx = 0\n\t\t\t\tny = y\n\t\t\telif xx == 6:\n\t\t\t\tnx = 1\n\t\t\t\tny = y + 1\n\t\tif ny >= n:\n\t\t\tif nx == 1 and ny == n:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\tbreak\n\t\tfor i in chg[a[nx][ny]]:\n\t\t\tif i in sol[a[x][y], x]:\n\t\t\t\ta[nx][ny] = i\n\t\t\t\tbreak\n\t\telse:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tnxt = [nx, ny]\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\tlines = [list(input()), list(input())]\n\tlinei = 0\n\tans = True\n\tfor k in range(n):\n\t\tif lines[linei][k] >= '3':\n\t\t\tif lines[linei - 1][k] <= '2':\n\t\t\t\tans = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tlinei = (linei - 1) % 2\n\tif linei == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES' if ans else 'NO')\n", "import sys\nimport bisect\ntry:\n\tfin = open('in')\nexcept:\n\tfin = sys.stdin\ninput = lambda : fin.readline().strip()\nfor _ in range(int(input())):\n\tn = int(input())\n\tg = [list(input()) for _ in range(2)]\n\trow = 0\n\tcol = 0\n\twhile col < n:\n\t\tif g[row][col] >= '3':\n\t\t\tif g[row ^ 1][col] <= '2':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\trow ^= 1\n\t\tcol += 1\n\tif row == 1 and col == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor qq in range(q):\n\tn = int(input())\n\tt0 = list(map(int, input()))\n\tt1 = list(map(int, input()))\n\ttube = [[0] * (n + 1) for _ in range(2)]\n\ttube[0][0] = 1\n\tfor i in range(n):\n\t\tfor _ in range(2):\n\t\t\tif t0[i] <= 2 and tube[0][i] % 10 > 0:\n\t\t\t\ttube[0][i + 1] += 1\n\t\t\tif t1[i] <= 2 and tube[1][i] % 10 > 0:\n\t\t\t\ttube[1][i + 1] += 1\n\t\t\tif t0[i] > 2 and tube[0][i] // 10 > 0:\n\t\t\t\ttube[0][i + 1] += 1\n\t\t\tif t1[i] > 2 and tube[1][i] // 10 > 0:\n\t\t\t\ttube[1][i + 1] += 1\n\t\t\tif t0[i] > 2 and tube[0][i] % 10 > 0:\n\t\t\t\ttube[1][i] += 10\n\t\t\tif t1[i] > 2 and tube[1][i] % 10 > 0:\n\t\t\t\ttube[0][i] += 10\n\tprint('YES' if tube[1][n] > 0 else 'NO')\n", "import sys\nimport math\nfrom collections import defaultdict\ntry:\n\tsys.stdin = open('input.txt', 'r')\n\tsys.stdout = open('output.txt', 'w')\nexcept:\n\tpass\n\ndef takeInput():\n\treturn [int(x) for x in input().strip().split()]\nt = int(input())\nwhile t != 0:\n\tt -= 1\n\tn = int(input())\n\trow1 = input()\n\trow2 = input()\n\trow1 = [int(x) for x in list(row1)]\n\trow2 = [int(x) for x in list(row2)]\n\tfor (i, r) in enumerate(row1):\n\t\tif r == 1 or r == 2:\n\t\t\trow1[i] = 1\n\t\telse:\n\t\t\trow1[i] = 3\n\tfor (i, r) in enumerate(row2):\n\t\tif r == 1 or r == 2:\n\t\t\trow2[i] = 1\n\t\telse:\n\t\t\trow2[i] = 3\n\trow1 = [0] + row1\n\trow2 = [0] + row2\n\trows = [[], row1, row2]\n\tr = 1\n\tc = 1\n\tpossible = True\n\tfor c in range(1, n + 1):\n\t\tif rows[r][c] == 3:\n\t\t\tif r == 1:\n\t\t\t\tif rows[2][c] == 3:\n\t\t\t\t\tr = 2\n\t\t\t\telse:\n\t\t\t\t\tpossible = False\n\t\t\telif r == 2:\n\t\t\t\tif rows[1][c] == 3:\n\t\t\t\t\tr = 1\n\t\t\t\telse:\n\t\t\t\t\tpossible = False\n\tif r == 1 or not possible:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "def solver(length, pipes):\n\tstuck = False\n\tcoords = [0, 0]\n\tflowType = 1\n\twhile True:\n\t\tunderInspection = pipes[coords[0]][coords[1]]\n\t\tcomponentType = 1 if underInspection == 1 or underInspection == 2 else 2\n\t\tif componentType == 1:\n\t\t\tif flowType == 1:\n\t\t\t\tflowType = 1\n\t\t\t\tcoords[1] += 1\n\t\t\telse:\n\t\t\t\tstuck = True\n\t\t\t\tbreak\n\t\telif flowType == 2:\n\t\t\tflowType = 1\n\t\t\tcoords[1] += 1\n\t\telif flowType == 3:\n\t\t\tflowType = 1\n\t\t\tcoords[1] += 1\n\t\telif coords[0] == 0:\n\t\t\tflowType = 2\n\t\t\tcoords[0] += 1\n\t\telse:\n\t\t\tflowType = 3\n\t\t\tcoords[0] -= 1\n\t\tif coords[1] == length:\n\t\t\tif coords[0] == 0:\n\t\t\t\tstuck = True\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tbreak\n\treturn 'NO' if stuck else 'YES'\n\ndef main():\n\tfor _ in range(int(input().strip())):\n\t\tlength = int(input().strip())\n\t\tpipes = []\n\t\tpipes.append([int(x) for x in str(input().strip())])\n\t\tpipes.append([int(x) for x in str(input().strip())])\n\t\tprint(solver(length, pipes))\nmain()\n", "def evaluate(a, n):\n\tprev = (1, n)\n\tcurr = (1, n - 1)\n\twhile curr != (0, -1):\n\t\tif curr[1] == -1 and curr[0] != 0:\n\t\t\treturn 'NO'\n\t\ttmp = curr\n\t\tif prev[0] == curr[0] + 1 or prev[0] == curr[0] - 1:\n\t\t\tif a[curr[0]][curr[1]] == '1' or a[curr[0]][curr[1]] == '2':\n\t\t\t\treturn 'NO'\n\t\t\tcurr = (curr[0], curr[1] - 1)\n\t\telif prev[1] == curr[1] + 1:\n\t\t\tif a[curr[0]][curr[1]] == '1' or a[curr[0]][curr[1]] == '2':\n\t\t\t\tcurr = (curr[0], curr[1] - 1)\n\t\t\telse:\n\t\t\t\tcurr = (int(curr[0] == 0), curr[1])\n\t\tprev = tmp\n\treturn 'YES'\nfor _ in range(int(input())):\n\tn = int(input())\n\t(row1, row2) = (input(), input())\n\tprint(evaluate([row1, row2], n))\n", "import math\nfrom collections import deque, defaultdict\nfrom sys import stdin, stdout\nlistin = lambda : list(map(int, input().split()))\nmapin = lambda : map(int, input().split())\nfor _ in range(int(input())):\n\tn = int(input())\n\ta = []\n\tfor i in range(2):\n\t\ts = input()\n\t\tz = [int(i) for i in s]\n\t\ta.append(z)\n\ti = 0\n\tj = 0\n\tmove = 'l'\n\tflag = True\n\twhile True:\n\t\tif i == 0:\n\t\t\tif a[i][j] <= 2 and move == 'l':\n\t\t\t\tj += 1\n\t\t\telif a[i][j] <= 2 and move == 'u':\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telif a[i][j] > 2 and move == 'u':\n\t\t\t\tj += 1\n\t\t\t\tmove = 'l'\n\t\t\telse:\n\t\t\t\ti += 1\n\t\t\t\tmove = 'd'\n\t\telif a[i][j] <= 2 and move == 'd':\n\t\t\tflag = False\n\t\t\tbreak\n\t\telif a[i][j] <= 2 and move == 'l':\n\t\t\tj += 1\n\t\telif a[i][j] > 2 and move == 'd':\n\t\t\tj += 1\n\t\t\tmove = 'l'\n\t\telse:\n\t\t\ti -= 1\n\t\t\tmove = 'u'\n\t\tif j == n and i == 1:\n\t\t\tbreak\n\t\telif j == n and i == 0:\n\t\t\tflag = False\n\t\t\tbreak\n\tif flag:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tcurr = 'u'\n\tnow = 0\n\tst = {'1', '2'}\n\tcurv = {'3', '4', '5', '6'}\n\tans = True\n\twhile now <= n - 1:\n\t\tif curr == 'u':\n\t\t\tif a[now] in st:\n\t\t\t\tpass\n\t\t\telif a[now] in curv and b[now] in curv:\n\t\t\t\tcurr = 'd'\n\t\t\t\tpass\n\t\t\telse:\n\t\t\t\tans = False\n\t\telif curr == 'd':\n\t\t\tif b[now] in st:\n\t\t\t\tpass\n\t\t\telif a[now] in curv and b[now] in curv:\n\t\t\t\tcurr = 'u'\n\t\t\t\tpass\n\t\t\telse:\n\t\t\t\tans = False\n\t\tnow += 1\n\tif ans == True and curr == 'd':\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tsiz = int(input())\n\tso = [[int(s) for s in input()], [int(q) for q in input()]]\n\t(beg, r, c, flag) = (so[0][0], 0, 0, True)\n\twhile 1:\n\t\tif beg == 1 or beg == 2:\n\t\t\tif c + 1 < siz:\n\t\t\t\tc += 1\n\t\t\t\tbeg = so[r][c]\n\t\t\telif c + 1 == siz and r == 1:\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\telif r + 1 < 2 and so[r + 1][c] != '*':\n\t\t\tif so[r + 1][c] > 2:\n\t\t\t\tso[r][c] = '*'\n\t\t\t\tr += 1\n\t\t\t\tbeg = so[r][c]\n\t\t\telse:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\telif r - 1 > -1 and so[r - 1][c] != '*':\n\t\t\tif so[r - 1][c] > 2:\n\t\t\t\tso[r][c] = '*'\n\t\t\t\tr -= 1\n\t\t\t\tbeg = so[r][c]\n\t\t\telse:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\telif c + 1 < siz:\n\t\t\tso[r][c] = '*'\n\t\t\tc += 1\n\t\t\tbeg = so[r][c]\n\t\telif c + 1 == siz and r == 1:\n\t\t\tbreak\n\t\telse:\n\t\t\tflag = False\n\t\t\tbreak\n\tprint('YES' if flag else 'NO')\n", "from sys import stdin, stdout\nfrom os import path\nrd = lambda : stdin.readline().strip()\nwr = stdout.write\nif path.exists('input.txt'):\n\tstdin = open('input.txt', 'r')\nimport math\nfor _ in range(int(rd())):\n\tx = int(rd())\n\tamr = [rd(), rd()]\n\ti = j = 0\n\tflag = True\n\tvisited = [[0] * x, [0] * x]\n\twhile True:\n\t\tif j > x - 1:\n\t\t\tbreak\n\t\telif amr[i][j] == '1' or amr[i][j] == '2':\n\t\t\tvisited[i][j] = 1\n\t\t\tj += 1\n\t\telif i == 0 and int(amr[i + 1][j]) > 2 and (visited[i + 1][j] != 1):\n\t\t\tvisited[i][j] = 1\n\t\t\tvisited[i + 1][j] = 1\n\t\t\ti += 1\n\t\t\tj += 1\n\t\telif i == 1 and int(amr[i - 1][j]) > 2 and (visited[i - 1][j] != 1):\n\t\t\tvisited[i][j] = 1\n\t\t\tvisited[i - 1][j] = 1\n\t\t\ti -= 1\n\t\t\tj += 1\n\t\telse:\n\t\t\ti = 0\n\t\t\tbreak\n\tprint('YES' if i == 1 else 'NO')\n", "import sys, os, io\n\ndef rs():\n\treturn sys.stdin.readline().rstrip()\n\ndef ri():\n\treturn int(sys.stdin.readline())\n\ndef ria():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef ws(s):\n\tsys.stdout.write(s + '\\n')\n\ndef wi(n):\n\tsys.stdout.write(str(n) + '\\n')\n\ndef wia(a):\n\tsys.stdout.write(' '.join([str(x) for x in a]) + '\\n')\nimport math, datetime, functools, itertools, operator, bisect, fractions, statistics\nfrom collections import deque, defaultdict, OrderedDict, Counter\nfrom fractions import Fraction\nfrom decimal import Decimal\nfrom sys import stdout\n\ndef main():\n\tstarttime = datetime.datetime.now()\n\tif os.path.exists('input.txt'):\n\t\tsys.stdin = open('input.txt', 'r')\n\t\tsys.stdout = open('output.txt', 'w')\n\tfor _ in range(ri()):\n\t\tn = ri()\n\t\ta = []\n\t\ta.append(list(rs()))\n\t\ta.append(list(rs()))\n\t\tcurr = 0\n\t\tans = 'YES'\n\t\tfor i in range(n):\n\t\t\tif a[curr][i] > '2':\n\t\t\t\tif a[1 - curr][i] < '3':\n\t\t\t\t\tans = 'NO'\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tcurr = 1 - curr\n\t\tif curr:\n\t\t\tprint(ans)\n\t\telse:\n\t\t\tprint('NO')\n\tendtime = datetime.datetime.now()\n\ttime = (endtime - starttime).total_seconds() * 1000\n\tif os.path.exists('input.txt'):\n\t\tprint('Time:', time, 'ms')\n\nclass FastReader(io.IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, fd, chunk_size=1024 * 8):\n\t\tself._fd = fd\n\t\tself._chunk_size = chunk_size\n\t\tself.buffer = io.BytesIO()\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self, size=-1):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\nclass FastWriter(io.IOBase):\n\n\tdef __init__(self, fd):\n\t\tself._fd = fd\n\t\tself.buffer = io.BytesIO()\n\t\tself.write = self.buffer.write\n\n\tdef flush(self):\n\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass FastStdin(io.IOBase):\n\n\tdef __init__(self, fd=0):\n\t\tself.buffer = FastReader(fd)\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n\nclass FastStdout(io.IOBase):\n\n\tdef __init__(self, fd=1):\n\t\tself.buffer = FastWriter(fd)\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.flush = self.buffer.flush\nsys.stdin = FastStdin()\nsys.stdout = FastStdout()\nmain()\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tup = input()\n\tdown = input()\n\tpipe = []\n\tpipe.append(up)\n\tpipe.append(down)\n\tpos = 0\n\tcan = True\n\tfor i in range(n):\n\t\tif pipe[pos][i] > '2':\n\t\t\tpos ^= 1\n\t\t\tif pipe[pos][i] <= '2':\n\t\t\t\tcan = False\n\t\t\t\tbreak\n\tif pos == 0:\n\t\tcan = False\n\tif can:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for t in range(int(input())):\n\tn = int(input())\n\ts = ['', input(), input()]\n\ti = 1\n\tj = 0\n\tflow = '-'\n\tfor p in range(10 * n):\n\t\tc = s[i][j]\n\t\tif flow == '-':\n\t\t\tif i == 1:\n\t\t\t\tif c == '1' or c == '2':\n\t\t\t\t\tj += 1\n\t\t\t\telse:\n\t\t\t\t\ti = 2\n\t\t\t\t\tflow = '|'\n\t\t\telif c == '1' or c == '2':\n\t\t\t\tj += 1\n\t\t\telse:\n\t\t\t\ti = 1\n\t\t\t\tflow = '|'\n\t\telif i == 1:\n\t\t\tif c == '1' or c == '2':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tj += 1\n\t\t\t\tflow = '-'\n\t\telif c == '1' or c == '2':\n\t\t\tbreak\n\t\telse:\n\t\t\tj += 1\n\t\t\tflow = '-'\n\t\tif j >= n:\n\t\t\tbreak\n\tif i == 2 and j == n and (flow == '-'):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "I = lambda : int(input())\n\ndef is_possible():\n\tcr = 0\n\tn = I()\n\tget_row = lambda : list(map(lambda x: 0 if x < 3 else 1, map(int, list(input()))))\n\trows = [get_row(), get_row()]\n\tfor i in range(n):\n\t\tif rows[cr][i]:\n\t\t\tif not rows[not cr][i]:\n\t\t\t\treturn False\n\t\t\telse:\n\t\t\t\tcr = not cr\n\treturn not not cr\nfor _ in range(I()):\n\tprint('YES' if is_possible() else 'NO')\n", "q = int(input())\nans = list()\nfor i in range(q):\n\tn = int(input())\n\tr = [input() for i in range(2)]\n\tflag = True\n\tcurR = 0\n\tfor i in range(n):\n\t\tif int(r[0][i]) > 2 and int(r[1][i]) > 2:\n\t\t\tcurR = (curR + 1) % 2\n\t\t\tcontinue\n\t\tif int(r[curR][i]) <= 2:\n\t\t\tcontinue\n\t\tflag = False\n\t\tbreak\n\tif flag and curR == 1:\n\t\tans.append('YES')\n\telse:\n\t\tans.append('NO')\nfor i in ans:\n\tprint(i)\n", "q = int(input())\nconv = {'1': 1, '2': 1, '3': 2, '4': 2, '5': 2, '6': 2}\nfor _ in range(q):\n\tn = int(input())\n\tpipes = [input(), input()]\n\tpipes = list(map(lambda row: list(map(lambda x: conv[x], row)), pipes))\n\tdp = [[0] * n, [0] * n]\n\tdp[0][0] = 1 if pipes[0][0] == 1 else 0\n\tdp[1][0] = 1 if pipes[0][0] == 2 and pipes[1][0] == 2 else 0\n\tfor i in range(1, n):\n\t\tdp[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\n\t\tdp[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\n\tprint('YES' if dp[1][n - 1] == 1 else 'NO')\n", "import sys\ninput = sys.stdin.readline\n\ndef canForm(rows):\n\tn = len(rows[0])\n\tcur = ['2', (0, -1)]\n\twhile True:\n\t\t(shape, loc) = cur\n\t\tif loc == (1, n - 1) and (shape == '2' or shape == '6'):\n\t\t\treturn True\n\t\tnxt = None\n\t\tif shape == '1':\n\t\t\treturn False\n\t\telif shape == '2' or shape == '3' or shape == '6':\n\t\t\tif loc[1] == n - 1:\n\t\t\t\treturn False\n\t\t\telif rows[loc[0]][loc[1] + 1] in '3456':\n\t\t\t\tif loc[0] == 0:\n\t\t\t\t\tnxt = ['4', (loc[0], loc[1] + 1)]\n\t\t\t\telse:\n\t\t\t\t\tnxt = ['5', (loc[0], loc[1] + 1)]\n\t\t\telse:\n\t\t\t\tnxt = ['2', (loc[0], loc[1] + 1)]\n\t\telif shape == '4':\n\t\t\tif loc[0] == 1:\n\t\t\t\treturn False\n\t\t\telif rows[1][loc[1]] in '3456':\n\t\t\t\tnxt = ['6', (1, loc[1])]\n\t\t\telse:\n\t\t\t\tnxt = ['1', (1, loc[1])]\n\t\telif shape == '5':\n\t\t\tif loc[0] == 0:\n\t\t\t\treturn False\n\t\t\telif rows[0][loc[1]] in '3456':\n\t\t\t\tnxt = ['3', (0, loc[1])]\n\t\t\telse:\n\t\t\t\tnxt = ['1', (0, loc[1])]\n\t\tcur = nxt\n\ndef main():\n\tlq = int(input())\n\tfor _ in range(lq):\n\t\tn = int(input())\n\t\trows = [input(), input()]\n\t\tif canForm(rows):\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\nmain()\n", "import sys\ninput = sys.stdin.readline\nt = int(input())\nfor _ in range(t):\n\tn = int(input())\n\tr1 = [0] + list(map(int, input().strip()))\n\tr2 = [0] + list(map(int, input().strip()))\n\tdp = [[False, False] for i in range(n + 1)]\n\tdp[0][0] = True\n\tdp[0][1] = False\n\tfor i in range(1, n + 1):\n\t\tif r1[i] in (1, 2):\n\t\t\tdp[i][0] = dp[i - 1][0]\n\t\tif r2[i] in (1, 2):\n\t\t\tdp[i][1] = dp[i - 1][1]\n\t\tif r1[i] in (3, 4, 5, 6) and r2[i] in (3, 4, 5, 6):\n\t\t\tdp[i][0] = dp[i - 1][1]\n\t\t\tdp[i][1] = dp[i - 1][0]\n\tif dp[-1][-1]:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ta = [[int(i) for i in list(input().strip())], [int(i) for i in list(input().strip())]]\n\tr = 0\n\td = 0\n\ti = 0\n\twhile i < n:\n\t\tif a[r][i] < 3:\n\t\t\ti += 1\n\t\telse:\n\t\t\tr = 1 - r\n\t\t\tif a[r][i] < 3:\n\t\t\t\tr = 0\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ti += 1\n\tif r == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tarr = []\n\tarr.append(s1)\n\tarr.append(s2)\n\ti1 = 0\n\tj1 = 0\n\tbad = False\n\twhile j1 < n:\n\t\tif arr[i1][j1] < '3':\n\t\t\tj1 += 1\n\t\telse:\n\t\t\tif i1 == 0:\n\t\t\t\ti1 += 1\n\t\t\telse:\n\t\t\t\ti1 -= 1\n\t\t\tif arr[i1][j1] > '2':\n\t\t\t\tj1 += 1\n\t\t\telse:\n\t\t\t\tbad = True\n\t\t\t\tbreak\n\tif i1 == 1 and j1 == n and (not bad):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "t = int(input())\nwhile t > 0:\n\tt -= 1\n\tn = int(input())\n\td = []\n\tf1 = 0\n\tf2 = 0\n\ta = input()\n\ta = list(a)\n\tfor i in range(n):\n\t\tif a[i] == '1' or a[i] == '2':\n\t\t\ta[i] = 0\n\t\telse:\n\t\t\ta[i] = 1\n\tb = input()\n\tb = list(b)\n\tfor i in range(n):\n\t\tif b[i] == '1' or b[i] == '2':\n\t\t\tb[i] = 0\n\t\telse:\n\t\t\tb[i] = 1\n\tfor i in range(n):\n\t\tif i == 0:\n\t\t\tc = a\n\t\t\tf1 = 1\n\t\t\tf2 = 0\n\t\tif a[i] == 1 and b[i] == 0 and (f1 == 1):\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif a[i] == 0 and b[i] == 1 and (f2 == 1):\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif i == n - 1 and f1 == 1:\n\t\t\tif a[n - 1] == 1 and b[n - 1] == 1:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif i == n - 1 and f2 == 1:\n\t\t\tif b[n - 1] == 0:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\tif c[i] == 1:\n\t\t\tif f1 == 1:\n\t\t\t\tc = b\n\t\t\t\tf2 = 1\n\t\t\t\tf1 = 0\n\t\t\telse:\n\t\t\t\tc = a\n\t\t\t\tf1 = 1\n\t\t\t\tf2 = 0\n", "T = int(input())\nfor _ in range(T):\n\tx = int(input())\n\ty1 = list(map(int, input()))\n\ty1.insert(0, 0)\n\ty2 = list(map(int, input()))\n\ty2.insert(0, 0)\n\txpos = 1\n\typos = 1\n\txdir = 1\n\tydir = 0\n\twhile xpos <= x:\n\t\tif ypos == 1:\n\t\t\tif y1[xpos] == 1 or y1[xpos] == 2:\n\t\t\t\tif xdir == 1:\n\t\t\t\t\txpos += 1\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\t\t\telif xdir == 1:\n\t\t\t\txdir = 0\n\t\t\t\tydir = -1\n\t\t\t\typos = 2\n\t\t\telse:\n\t\t\t\txdir = 1\n\t\t\t\tydir = 0\n\t\t\t\txpos += 1\n\t\tif ypos == 2:\n\t\t\tif y2[xpos] == 1 or y2[xpos] == 2:\n\t\t\t\tif xdir == 1:\n\t\t\t\t\txpos += 1\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\t\t\telif xdir == 1:\n\t\t\t\txdir = 0\n\t\t\t\tydir = 1\n\t\t\t\typos = 1\n\t\t\telse:\n\t\t\t\txdir = 1\n\t\t\t\tydir = 0\n\t\t\t\txpos += 1\n\tif xpos == x + 1 and ypos == 2:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n", "t = int(input())\nwhile t > 0:\n\tn = int(input())\n\tu = input()\n\td = input()\n\tc = 1\n\tflag = 1\n\tfor i in range(n):\n\t\tif c == 1:\n\t\t\tif i == n - 1 and (u[i] == '1' or u[i] == '2'):\n\t\t\t\tflag = -1\n\t\t\t\tbreak\n\t\t\telif i == n - 1 and u[i] != '1' and (u[i] != '2') and (d[i] == '1' or d[i] == '2'):\n\t\t\t\tflag = -1\n\t\t\t\tbreak\n\t\t\telif (u[i] != '1' and u[i] != '2') and (d[i] == '2' or d[i] == '1'):\n\t\t\t\tflag = -1\n\t\t\t\tbreak\n\t\t\telif (u[i] != '1' and u[i] != '2') and (d[i] != '1' and d[i] != '2'):\n\t\t\t\tc = 0\n\t\telif i == n - 1 and d[i] != '1' and (d[i] != '2'):\n\t\t\tflag = -1\n\t\t\tbreak\n\t\telif (d[i] != '1' and d[i] != '2') and (u[i] == '2' or u[i] == '1'):\n\t\t\tflag = -1\n\t\t\tbreak\n\t\telif (u[i] != '1' and u[i] != '2') and (d[i] != '1' and d[i] != '2'):\n\t\t\tc = 1\n\tif flag == -1:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n\tt -= 1\n", "for _ in range(int(input())):\n\tn = int(input())\n\tr = [[], []]\n\tr[0] = input()\n\tr[1] = input()\n\tstck = [[1, n - 1, -1]]\n\tflag = True\n\twhile stck:\n\t\t(x, y, direc) = stck.pop()\n\t\tif x < 0 or y < 0:\n\t\t\tbreak\n\t\tif direc == -1:\n\t\t\tif r[x][y] == '1' or r[x][y] == '2':\n\t\t\t\tstck.append([x, y - 1, -1])\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tstck.append([1 - x, y, 1])\n\t\t\t\tcontinue\n\t\telif r[x][y] == '1' or r[x][y] == '2':\n\t\t\tflag = False\n\t\t\tbreak\n\t\telse:\n\t\t\tstck.append([x, y - 1, -1])\n\t\t\tcontinue\n\tif flag and x == 0 and (y == -1):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def f(c1, c2):\n\tflag = True\n\ti = 0\n\twhile i < len(c1):\n\t\tif i == len(c1) - 1 and flag == True:\n\t\t\tif c1[i] in [1, 2] or c2[i] in [1, 2]:\n\t\t\t\treturn 'NO'\n\t\telif i == len(c1) - 1 and flag == False:\n\t\t\tif c2[i] not in [1, 2]:\n\t\t\t\treturn 'NO'\n\t\tif flag == True:\n\t\t\tif c1[i] in [1, 2]:\n\t\t\t\ti = i + 1\n\t\t\telse:\n\t\t\t\tif c2[i] in [1, 2]:\n\t\t\t\t\treturn 'NO'\n\t\t\t\tflag = False\n\t\t\t\ti = i + 1\n\t\telif flag == False:\n\t\t\tif c2[i] in [1, 2]:\n\t\t\t\ti = i + 1\n\t\t\telse:\n\t\t\t\tif c1[i] in [1, 2]:\n\t\t\t\t\treturn 'NO'\n\t\t\t\tflag = True\n\t\t\t\ti = i + 1\n\treturn 'YES'\na = int(input())\nfor tc in range(a):\n\tb = input()\n\tc1 = list(map(int, input()))\n\tc2 = list(map(int, input()))\n\tprint(f(c1, c2))\n", "q = int(input())\ni = 0\nz = []\nwhile i < q:\n\tb = []\n\tc = int(input())\n\tb.append(input())\n\tb.append(input())\n\t(y, x) = (0, 0)\n\tp = 0\n\twhile True:\n\t\tif b[y][x] == '1' or b[y][x] == '2':\n\t\t\tif p == y:\n\t\t\t\tp = y\n\t\t\t\tx += 1\n\t\t\telse:\n\t\t\t\tz.append(False)\n\t\t\t\tbreak\n\t\telif p == y:\n\t\t\tp = y\n\t\t\ty = -y + 1\n\t\telse:\n\t\t\tp = y\n\t\t\tx += 1\n\t\tif x == c:\n\t\t\tif y == 1:\n\t\t\t\tz.append(True)\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tz.append(False)\n\t\t\t\tbreak\n\ti += 1\nfor a in z:\n\tprint('YES') if a is True else print('NO')\n", "q = int(input())\nfor query in range(q):\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tswitch = 0\n\ts1 = ['1', '2']\n\ts2 = ['3', '4', '5', '6']\n\tturns = 0\n\tflag = 0\n\tfor i in range(n):\n\t\tif switch == 0:\n\t\t\tif a[i] in s1:\n\t\t\t\tcontinue\n\t\t\telif a[i] in s2:\n\t\t\t\tif b[i] in s1:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tflag = 1\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tswitch = 1\n\t\t\t\t\tturns += 1\n\t\telif b[i] in s1:\n\t\t\tcontinue\n\t\telif b[i] in s2:\n\t\t\tif a[i] in s1:\n\t\t\t\tprint('NO')\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tswitch = 0\n\t\t\t\tturns += 1\n\tif flag == 1:\n\t\tcontinue\n\telif switch == 0:\n\t\tprint('NO')\n\t\tcontinue\n\telif turns % 2 == 0:\n\t\tprint('NO')\n\t\tcontinue\n\telse:\n\t\tprint('YES')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ts = input()\n\tr = input()\n\tl = [[0, 0] for _ in range(n + 1)]\n\tfor i in range(n):\n\t\tl[i][0] = int(s[i])\n\t\tl[i][1] = int(r[i])\n\ts1 = set([1, 2])\n\ts2 = set([3, 4, 5, 6])\n\ttx = 0\n\tty = 0\n\tif int(s[0]) in s2:\n\t\tx = 0\n\t\ty = 1\n\telse:\n\t\tx = 1\n\t\ty = 0\n\twhile 1:\n\t\tif x == n:\n\t\t\tif y == 1:\n\t\t\t\ttf = True\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ttf = False\n\t\t\t\tbreak\n\t\tif l[x][y] in s1:\n\t\t\tif tx == x - 1 and ty == y:\n\t\t\t\ttx = x\n\t\t\t\tty = y\n\t\t\t\tx += 1\n\t\t\telse:\n\t\t\t\ttf = False\n\t\t\t\tbreak\n\t\telif tx == x - 1 and ty == y:\n\t\t\ttx = x\n\t\t\tty = y\n\t\t\ty += 1\n\t\t\ty %= 2\n\t\telse:\n\t\t\tty = y\n\t\t\tx += 1\n\tif tf:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\t(p1, p2) = (input(), input())\n\ts1 = set(['1', '2'])\n\ts2 = set(['3', '4', '5', '6'])\n\tin_ = 1\n\ti = 1\n\twhile in_ != 0 and i <= n:\n\t\ti_ = i - 1\n\t\tif in_ == 1:\n\t\t\tif p1[i_] in s2 and p2[i_] not in s2:\n\t\t\t\tin_ = 0\n\t\t\telif p1[i_] in s2 and p2[i_] in s2:\n\t\t\t\tin_ = 2\n\t\telif in_ == 2:\n\t\t\tif p2[i_] in s2 and p1[i_] not in s2:\n\t\t\t\tin_ = 0\n\t\t\telif p2[i_] in s2 and p1[i_] in s2:\n\t\t\t\tin_ = 1\n\t\ti += 1\n\tif in_ == 2:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nTube = list()\nline = set('12')\nsqr = set('3456')\nfor i in range(q):\n\tn = int(input())\n\tTube.clear()\n\tmyX = 2\n\tmyY = n - 1\n\tbackX = 2\n\tbackY = n\n\tbackTube = '1'\n\tTube.append('0')\n\tTube.append(input())\n\tTube.append(input())\n\tflag = True\n\twhile flag:\n\t\tmyTube = Tube[myX][myY]\n\t\tif myTube in line:\n\t\t\tc = myX\n\t\t\tmyX = myX - (backX - myX)\n\t\t\tbackX = c\n\t\t\tc = myY\n\t\t\tmyY = myY * 2 - backY\n\t\t\tbackY = c\n\t\telif backY == myY:\n\t\t\tmyY -= 1\n\t\t\tif backX == 2:\n\t\t\t\tbackX -= 1\n\t\t\telse:\n\t\t\t\tbackX += 1\n\t\telif myX == backX:\n\t\t\tif myX == 1:\n\t\t\t\tmyX += 1\n\t\t\t\tbackY -= 1\n\t\t\telse:\n\t\t\t\tmyX -= 1\n\t\t\t\tbackY -= 1\n\t\tbackTube = myTube\n\t\tif myX == 1 and myY == -1:\n\t\t\tflag = True\n\t\t\tbreak\n\t\tif myY > backY or myY <= -1:\n\t\t\tflag = False\n\t\t\tbreak\n\t\tif myX > 2 or myX < 1:\n\t\t\tflag = False\n\t\t\tbreak\n\tif flag:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for i in range(int(input())):\n\tn = int(input())\n\tstr1 = input()\n\tstr2 = input()\n\tm = 'd'\n\ts = 0\n\twhile True:\n\t\tif s == n:\n\t\t\tbreak\n\t\telif m[0] == 'd':\n\t\t\tif len(m) == 1:\n\t\t\t\tif int(str1[s]) < 3:\n\t\t\t\t\ts += 1\n\t\t\t\telif int(str1[s]) > 2:\n\t\t\t\t\tm = 'ur'\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\t\t\telif int(str1[s]) > 2:\n\t\t\t\ts += 1\n\t\t\t\tm = 'd'\n\t\t\telse:\n\t\t\t\tbreak\n\t\telif len(m) == 1:\n\t\t\tif int(str2[s]) < 3:\n\t\t\t\ts += 1\n\t\t\telif int(str2[s]) > 2:\n\t\t\t\tm = 'dr'\n\t\t\telse:\n\t\t\t\tbreak\n\t\telif int(str2[s]) > 2:\n\t\t\ts += 1\n\t\t\tm = 'u'\n\t\telse:\n\t\t\tbreak\n\tif m == 'u':\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor asdga in range(q):\n\tn = int(input())\n\tlines = []\n\tlines.append(input())\n\tlines.append(input())\n\tdp = []\n\tdp.append(list(lines[0]))\n\tdp.append(list(lines[1]))\n\tcurrentLine = 0\n\tprevWasTurned = False\n\tans = 'YES'\n\ti = 0\n\twhile i < n:\n\t\tif dp[currentLine][i] >= '3' and (not prevWasTurned):\n\t\t\tcurrentLine = (currentLine + 1) % 2\n\t\t\tprevWasTurned = True\n\t\t\ti -= 1\n\t\telif dp[currentLine][i] >= '3' and prevWasTurned:\n\t\t\tprevWasTurned = False\n\t\telif prevWasTurned:\n\t\t\tans = 'NO'\n\t\t\tbreak\n\t\ti += 1\n\tif currentLine == 1 and dp[1][n - 1] < '3' and prevWasTurned:\n\t\tans = 'NO'\n\tif currentLine == 0:\n\t\tans = 'NO'\n\tprint(ans)\n", "import sys\nimport math\nmapp = {'1': 'line', '2': 'line', '3': 'angle', '4': 'angle', '5': 'angle', '6': 'angle'}\n\ndef gr(x):\n\treturn fr if x == 0 else sc\n\ndef solve(fr, sc, n):\n\tcompleted = False\n\tprev_row = 0\n\tcur_row = 0\n\tcur_col = 0\n\twhile not completed:\n\t\tif cur_col == n:\n\t\t\treturn cur_row == 1\n\t\tif mapp[gr(cur_row)[cur_col]] == 'line':\n\t\t\tif prev_row != cur_row:\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tcur_col += 1\n\t\telif prev_row == cur_row:\n\t\t\t(prev_row, cur_row) = (cur_row, 0 if prev_row == 1 else 1)\n\t\telse:\n\t\t\tcur_col += 1\n\t\t\tprev_row = cur_row\n\treturn completed\nt = int(sys.stdin.readline())\nfor _ in range(t):\n\tn = int(sys.stdin.readline())\n\tfr = sys.stdin.readline().strip()\n\tsc = sys.stdin.readline().strip()\n\tprint('YES' if solve(fr, sc, n) else 'NO')\n", "x = int(input())\nfor a in range(0, x):\n\ty = int(input())\n\tarr = [input()]\n\tarr.append(input())\n\ti = 0\n\tf = True\n\tfor b in range(0, len(arr[0])):\n\t\tif int(arr[i][b]) > 2:\n\t\t\tif i == 1:\n\t\t\t\ti = 0\n\t\t\telse:\n\t\t\t\ti = 1\n\t\t\tp = [i, b]\n\t\t\tif int(arr[i][b]) < 3:\n\t\t\t\tf = False\n\tif i == 1 and b == y - 1 and f:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "t = int(input())\nfor _ in range(t):\n\tn = int(input())\n\tp1 = [int(i) for i in input()]\n\tp2 = [int(i) for i in input()]\n\ttop = True\n\tok = True\n\tfor i in range(n):\n\t\tif p1[i] == 2:\n\t\t\tp1[i] = 1\n\t\tif p1[i] == 4 or p1[i] == 5 or p1[i] == 6:\n\t\t\tp1[i] = 3\n\t\tif p2[i] == 2:\n\t\t\tp2[i] = 1\n\t\tif p2[i] == 4 or p2[i] == 5 or p2[i] == 6:\n\t\t\tp2[i] = 3\n\tfor i in range(n - 1):\n\t\tif not ok:\n\t\t\tbreak\n\t\tif top:\n\t\t\tif p1[i] == 3:\n\t\t\t\ttop = False\n\t\t\t\tif p2[i] == 1:\n\t\t\t\t\tok = False\n\t\telif p2[i] == 3:\n\t\t\ttop = True\n\t\t\tif p1[i] == 1:\n\t\t\t\tok = False\n\tif top:\n\t\tif p1[-1] == 1 or p2[-1] == 1:\n\t\t\tok = False\n\telif p2[-1] == 3:\n\t\tok = False\n\tif ok:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "t = int(input())\nfor i in range(t):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\ta = [s1, s2]\n\t(x, y) = (0, 0)\n\tq = True\n\tbad = False\n\twhile q:\n\t\tif y > 1 or x > n - 1:\n\t\t\tbreak\n\t\tif a[y][x] == '1' or a[y][x] == '2':\n\t\t\tx += 1\n\t\telif 6 >= int(a[y][x]) >= 3 and y == 0:\n\t\t\tif 6 >= int(a[y + 1][x]) >= 3:\n\t\t\t\tx += 1\n\t\t\t\ty += 1\n\t\t\telse:\n\t\t\t\tbad = True\n\t\t\t\tq = False\n\t\telif 6 >= int(a[y][x]) >= 3 and y == 1:\n\t\t\tif 6 >= int(a[y - 1][x]) >= 3:\n\t\t\t\tx += 1\n\t\t\t\ty -= 1\n\t\t\telse:\n\t\t\t\tbad = True\n\t\t\t\tq = False\n\t\telse:\n\t\t\tq = False\n\tif bad:\n\t\tprint('NO')\n\telif x != n or y != 1:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tarr = input()\n\tbrr = input()\n\trow = 0\n\ta = [1, 2]\n\tb = [3, 4, 5, 6]\n\tf = 0\n\tfor i in range(n):\n\t\t(x, y) = (int(arr[i]), int(brr[i]))\n\t\tif row == 0 and x in a:\n\t\t\trow = 0\n\t\telif row == 0 and x in b:\n\t\t\trow = 1\n\t\t\tif y in a:\n\t\t\t\tf = 1\n\t\t\t\tbreak\n\t\telif row == 1 and y in a:\n\t\t\trow = 1\n\t\telif row == 1 and y in b:\n\t\t\trow = 0\n\t\t\tif x in a:\n\t\t\t\tf = 1\n\t\t\t\tbreak\n\tif f == 1 or row == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "import sys\nimport itertools\nimport math\nimport collections\nfrom collections import Counter\n\ndef pow(x, y, mod):\n\tr = 1\n\tx = x % mod\n\twhile y > 0:\n\t\tif y & 1:\n\t\t\tr = r * x % mod\n\t\ty = y >> 1\n\t\tx = x * x % mod\n\treturn r\n\ndef sieve(n):\n\tprime = [True for i in range(n + 1)]\n\tp = 2\n\twhile p * p <= n:\n\t\tif prime[p] == True:\n\t\t\tfor i in range(p * 2, n + 1, p):\n\t\t\t\tprime[i] = False\n\t\tp += 1\n\tprime[0] = prime[1] = False\n\tr = [p for p in range(n + 1) if prime[p]]\n\treturn r\n\ndef divs(n, start=1):\n\tr = []\n\tfor i in range(start, int(math.sqrt(n) + 1)):\n\t\tif n % i == 0:\n\t\t\tif n / i == i:\n\t\t\t\tr.append(i)\n\t\t\telse:\n\t\t\t\tr.extend([i, n // i])\n\treturn r\n\ndef cdiv(n, k):\n\treturn n // k + (n % k != 0)\n\ndef ii():\n\treturn int(input())\n\ndef mi():\n\treturn map(int, input().split())\n\ndef li():\n\treturn list(map(int, input().split()))\n\ndef lcm(a, b):\n\treturn abs(a * b) // math.gcd(a, b)\n\ndef prr(a, sep=' '):\n\tprint(sep.join(map(str, a)))\n\ndef dd():\n\treturn collections.defaultdict(int)\nq = ii()\nfor _ in range(q):\n\tn = ii()\n\td = []\n\td.append(input())\n\td.append(input())\n\ts1 = {'1', '2'}\n\ts2 = {'3', '4', '5', '6'}\n\tcr = 0\n\tf = False\n\tprev = i = 0\n\twhile i < n:\n\t\tif d[cr][i] in s2 and d[1 - cr][i] in s2:\n\t\t\tcr = 1 - cr\n\t\t\ti += 1\n\t\telif d[cr][i] in s1:\n\t\t\ti += 1\n\t\tif i == prev:\n\t\t\tbreak\n\t\tprev = i\n\t\tif i == n and cr == 1:\n\t\t\tf = True\n\t\t\tbreak\n\tprint('YES') if f else print('NO')\n", "def main():\n\tn = int(input())\n\tarr = []\n\tarr.append(list(input()))\n\tarr.append(list(input()))\n\trow = 0\n\tcol = 0\n\twhile col < n:\n\t\tif arr[row][col] >= '3':\n\t\t\tif arr[row ^ 1][col] < '3':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\trow = row ^ 1\n\t\tcol += 1\n\tif col == n and row == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n\ndef test():\n\tt = int(input())\n\twhile t:\n\t\tmain()\n\t\tt -= 1\n\treturn\ntest()\n", "q = int(input())\nx = 0\nwhile x < q:\n\tx += 1\n\tn = int(input())\n\tfirst = input()\n\tsecond = input()\n\t(rows, cols) = (2, n)\n\tarr = [[0 for i in range(cols)] for j in range(rows)]\n\tarr[0][0] = 1\n\tarr[1][0] = 2 if first[0] > '2' else 0\n\tfor col in range(1, n):\n\t\tarr[0][col] = arr[0][col] | 1 if arr[0][col - 1] & 1 and first[col - 1] <= '2' else arr[0][col]\n\t\tarr[1][col] = arr[1][col] | 1 if arr[1][col - 1] & 1 and second[col - 1] <= '2' else arr[1][col]\n\t\tarr[0][col] = arr[0][col] | 1 if arr[0][col - 1] & 2 and first[col - 1] > '2' else arr[0][col]\n\t\tarr[1][col] = arr[1][col] | 1 if arr[1][col - 1] & 2 and second[col - 1] > '2' else arr[1][col]\n\t\tarr[0][col] = arr[0][col] | 2 if arr[1][col] & 1 and second[col] > '2' else arr[0][col]\n\t\tarr[1][col] = arr[1][col] | 2 if arr[0][col] & 1 and first[col] > '2' else arr[1][col]\n\tif arr[1][n - 1] & 1 and second[n - 1] <= '2':\n\t\tprint('YES')\n\telif arr[1][n - 1] & 2 and second[n - 1] > '2':\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "I = lambda : int(input())\n\ndef is_possible():\n\tcr = 0\n\tn = I()\n\ts1 = list(map(lambda x: 0 if x < 3 else 1, map(int, list(input()))))\n\ts2 = list(map(lambda x: 0 if x < 3 else 1, map(int, list(input()))))\n\tfor i in range(n):\n\t\tif not cr:\n\t\t\tif s1[i]:\n\t\t\t\tif not s2[i]:\n\t\t\t\t\treturn False\n\t\t\t\telse:\n\t\t\t\t\tcr = 1\n\t\telif s2[i]:\n\t\t\tif not s1[i]:\n\t\t\t\treturn False\n\t\t\telse:\n\t\t\t\tcr = 0\n\treturn not not cr\nfor _ in range(I()):\n\tprint('YES' if is_possible() else 'NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tl1 = list(input())\n\tl2 = list(input())\n\to = ('1', '2')\n\tt = ('3', '4', '5', '6')\n\tturn = False\n\tfor (i, j) in zip(l1, l2):\n\t\tif turn == False:\n\t\t\tif i not in o:\n\t\t\t\tturn = not turn\n\t\t\t\tif j not in t:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\telif j not in o:\n\t\t\tturn = not turn\n\t\t\tif i not in t:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\telse:\n\t\tif turn:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "def solve(n):\n\trow = [0, 0]\n\trow[0] = input()\n\trow[1] = input()\n\tcrow = 0\n\ti = 0\n\twhile i < n - 1:\n\t\tif row[crow][i] in '12':\n\t\t\ti += 1\n\t\t\tcontinue\n\t\tif crow == 0:\n\t\t\tif row[1][i] in '12':\n\t\t\t\treturn 'NO'\n\t\t\telse:\n\t\t\t\tcrow = 1\n\t\t\t\ti += 1\n\t\telif row[0][i] in '12':\n\t\t\treturn 'NO'\n\t\telse:\n\t\t\tcrow = 0\n\t\t\ti += 1\n\tif crow == 0 and row[0][i] not in '12' and (row[1][i] not in '12'):\n\t\treturn 'YES'\n\tif crow == 1 and row[1][i] in '12':\n\t\treturn 'YES'\n\treturn 'NO'\nfor _ in range(int(input())):\n\tprint(solve(int(input())))\n", "import os\nfrom collections import Counter, defaultdict\nfrom io import BytesIO, IOBase\nimport sys\nfrom math import inf, ceil\n\ndef main():\n\tfor i in range(int(input())):\n\t\tn = int(input())\n\t\ta = [int(x) for x in input().strip()]\n\t\tb = [int(x) for x in input().strip()]\n\t\tfor j in range(n):\n\t\t\tif a[j] <= 2:\n\t\t\t\ta[j] = 1\n\t\t\telse:\n\t\t\t\ta[j] = 2\n\t\t\tif b[j] <= 2:\n\t\t\t\tb[j] = 1\n\t\t\telse:\n\t\t\t\tb[j] = 2\n\t\tfg = 1\n\t\tp = 1\n\t\tfor j in range(n):\n\t\t\tif p == 1:\n\t\t\t\tif a[j] == 2 and b[j] == 1:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tfg = 0\n\t\t\t\t\tbreak\n\t\t\t\telif a[j] == 2:\n\t\t\t\t\tp = 0\n\t\t\telif a[j] == 1 and b[j] == 2:\n\t\t\t\tprint('NO')\n\t\t\t\tfg = 0\n\t\t\t\tbreak\n\t\t\telif b[j] == 2:\n\t\t\t\tp = 1\n\t\tif p and fg:\n\t\t\tprint('NO')\n\t\telif not p and fg:\n\t\t\tprint('YES')\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nmain()\n", "n = int(input())\nfor i in range(n):\n\ta = int(input())\n\td = input()\n\tf = input()\n\te = 0\n\te1 = 0\n\tre = 0\n\ttr = False\n\twhile re <= a - 1:\n\t\tif re == a - 1:\n\t\t\tif e1 == 0 and (d[re] == '1' or d[re] == '2' or f[re] == '1' or (f[re] == '2')):\n\t\t\t\ttr = True\n\t\t\telif e1 == 1 and (f[re] == '3' or f[re] == '4' or f[re] == '5' or (f[re] == '6')):\n\t\t\t\ttr = True\n\t\t\tre += 1\n\t\telif e == 0:\n\t\t\tif d[re] == '1' or d[re] == '2':\n\t\t\t\tif e1 != 0:\n\t\t\t\t\ttr = True\n\t\t\t\t\tbreak\n\t\t\t\tre += 1\n\t\t\tif d[re] == '3' or d[re] == '4' or d[re] == '5' or (d[re] == '6'):\n\t\t\t\tif e1 == 0:\n\t\t\t\t\te = 1\n\t\t\t\telse:\n\t\t\t\t\tre += 1\n\t\t\te1 = 0\n\t\telse:\n\t\t\tif f[re] == '1' or f[re] == '2':\n\t\t\t\tif e1 != 1:\n\t\t\t\t\ttr = True\n\t\t\t\t\tbreak\n\t\t\t\tre += 1\n\t\t\tif f[re] == '3' or f[re] == '4' or f[re] == '5' or (f[re] == '6'):\n\t\t\t\tif e1 == 1:\n\t\t\t\t\te = 0\n\t\t\t\telse:\n\t\t\t\t\tre += 1\n\t\t\te1 = 1\n\tif tr:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "for _ in range(int(input())):\n\tn = int(input())\n\ta = list(input())\n\tb = list(input())\n\tfl = 1\n\tpre = 0\n\tpfl = 1\n\ti = 0\n\tans = 0\n\twhile True:\n\t\tif fl == 1:\n\t\t\tif pfl == 1:\n\t\t\t\tif a[i] == '1' or a[i] == '2':\n\t\t\t\t\tpre = 1\n\t\t\t\t\ti += 1\n\t\t\t\telse:\n\t\t\t\t\tfl = 0\n\t\t\telif a[i] == '1' or a[i] == '2':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ti += 1\n\t\t\t\tpfl = 1\n\t\telif pfl == 1:\n\t\t\tif b[i] == '1' or b[i] == '2':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ti += 1\n\t\t\t\tpfl = 0\n\t\telif b[i] == '1' or b[i] == '2':\n\t\t\ti += 1\n\t\telse:\n\t\t\tfl = 1\n\t\tif i == n:\n\t\t\tif fl == 0:\n\t\t\t\tans = 1\n\t\t\tbreak\n\tif ans:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "t = int(input())\nfor case in range(t):\n\tn = int(input())\n\tg = []\n\tfor _ in range(2):\n\t\tg.append(list(input()))\n\tx = 0\n\ty = 0\n\tstate = 'x'\n\twhile True:\n\t\tif g[y][x] == '1' or g[y][x] == '2':\n\t\t\tif state == 'x':\n\t\t\t\tx += 1\n\t\t\telse:\n\t\t\t\ty = 999\n\t\t\t\tbreak\n\t\telif state == 'x':\n\t\t\tif y == 1:\n\t\t\t\ty -= 1\n\t\t\t\tstate = 'y'\n\t\t\telse:\n\t\t\t\ty += 1\n\t\t\t\tstate = 'y'\n\t\telse:\n\t\t\tx += 1\n\t\t\tstate = 'x'\n\t\tif x >= n:\n\t\t\tbreak\n\tif y == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tmat = [list(map(int, input())), list(map(int, input()))]\n\tx = y = cnt = 0\n\twhile x < n:\n\t\tif mat[y][x] in [1, 2] and cnt % 2 == 0:\n\t\t\tx += 1\n\t\telif mat[y][x] in [1, 2] and cnt % 2 != 0:\n\t\t\tbreak\n\t\telse:\n\t\t\tif cnt % 4 == 0:\n\t\t\t\ty += 1\n\t\t\telif cnt % 4 == 2:\n\t\t\t\ty -= 1\n\t\t\telse:\n\t\t\t\tx += 1\n\t\t\tcnt += 1\n\tprint(['NO', 'YES'][x == n and (cnt - 2) % 4 == 0])\n", "for _ in range(int(input())):\n\tn = int(input())\n\ts = [input(), input()]\n\tcur = 0\n\t(x, y) = (0, 0)\n\tb = False\n\twhile 1:\n\t\tif x == 1 and y == n:\n\t\t\tb = True\n\t\t\tbreak\n\t\telif y >= n:\n\t\t\tbreak\n\t\telif cur == 1 and s[x][y] < '3':\n\t\t\tbreak\n\t\telif cur == 0 and s[x][y] < '3':\n\t\t\ty += 1\n\t\telif cur == 0 and s[x][y] > '2':\n\t\t\tx = 1 - x\n\t\t\tcur = 1 - cur\n\t\telif cur == 1 and s[x][y] > '2':\n\t\t\ty += 1\n\t\t\tcur = 1 - cur\n\tprint('YNEOS'[not b::2])\n", "for _ in range(int(input())):\n\tn = int(input())\n\tarr = []\n\tfor i in range(2):\n\t\tarr.append(list(input()))\n\trow = 0\n\tposition = 0\n\twhile position < n:\n\t\tif arr[row][position] >= '3':\n\t\t\tif arr[row ^ 1][position] < '3':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\trow ^= 1\n\t\tposition += 1\n\tif position == n and row == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor rer in range(q):\n\tn = int(input())\n\ttop = input()\n\tbottom = input()\n\tt = list(top)\n\tb = list(bottom)\n\tmat = [t, b]\n\tprev = [1, n]\n\tpos = [1, n - 1]\n\twhile True:\n\t\tif pos == [0, -1]:\n\t\t\tprint('YES')\n\t\t\tbreak\n\t\tif pos[0] not in [0, 1] or pos[1] < 0 or pos[1] > n - 1:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif mat[pos[0]][pos[1]] == '1' or mat[pos[0]][pos[1]] == '2':\n\t\t\tif prev[0] != pos[0]:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tprev = pos\n\t\t\t\tpos = [prev[0], prev[1] - 1]\n\t\telif prev[0] != pos[0]:\n\t\t\tprev = pos\n\t\t\tpos = [prev[0], prev[1] - 1]\n\t\telse:\n\t\t\tprev = pos\n\t\t\tpos = [(prev[0] + 1) % 2, prev[1]]\n", "for _ in range(int(input())):\n\tn = int(input())\n\ta1 = list(input())\n\ta2 = list(input())\n\trow = 1\n\tflag = True\n\tfor i in range(n):\n\t\tif row == 1:\n\t\t\tif a1[i] == '1' or a1[i] == '2':\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\trow = 2\n\t\t\t\tif a2[i] == '1' or a2[i] == '2':\n\t\t\t\t\tflag = False\n\t\t\t\t\tbreak\n\t\telif row == 2:\n\t\t\tif a2[i] == '1' or a2[i] == '2':\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\trow = 1\n\t\t\t\tif a1[i] == '1' or a1[i] == '2':\n\t\t\t\t\tflag = False\n\t\t\t\t\tbreak\n\tif flag and row == 2:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\n\ndef rint():\n\treturn map(int, sys.stdin.readline().split())\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tt0 = input()\n\tt1 = input()\n\tr0 = []\n\tr1 = []\n\tr = [[0 for i in range(n)] for j in range(2)]\n\tfor i in range(n):\n\t\ttmp = int(t0[i])\n\t\tif tmp > 2:\n\t\t\ttmp = 1\n\t\telse:\n\t\t\ttmp = 0\n\t\tr[0][i] = tmp\n\tfor i in range(n):\n\t\ttmp = int(t1[i])\n\t\tif tmp > 2:\n\t\t\ttmp = 1\n\t\telse:\n\t\t\ttmp = 0\n\t\tr[1][i] = tmp\n\tpos = (0, 0)\n\tprev = 'h'\n\tnot_ok = 0\n\twhile pos[1] < n:\n\t\trr = pos[0]\n\t\tcc = pos[1]\n\t\tif prev == 'h':\n\t\t\tif r[rr][cc] == 0:\n\t\t\t\tpos = (rr, cc + 1)\n\t\t\telse:\n\t\t\t\tpos = ((rr + 1) % 2, cc)\n\t\t\t\tprev = 'v'\n\t\telif r[rr][cc] == 0:\n\t\t\tnot_ok = 1\n\t\t\tbreak\n\t\telse:\n\t\t\tpos = (rr, cc + 1)\n\t\t\tprev = 'h'\n\tif not_ok or pos[0] != 1:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "a = int(input())\nfor i in range(a):\n\tb = int(input())\n\tc = input()\n\td = input()\n\tl = [c, d]\n\tk = 0\n\tans = 1\n\tfor i in range(b):\n\t\tif l[k][i] == '1' or l[k][i] == '2':\n\t\t\tpass\n\t\telif l[1 - k][i] == '3' or l[1 - k][i] == '4' or l[1 - k][i] == '5' or (l[1 - k][i] == '6'):\n\t\t\tk = 1 - k\n\t\telse:\n\t\t\tans = 0\n\tif k == 1 and ans == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nwhile q > 0:\n\tq -= 1\n\tn = int(input())\n\ta = input()\n\tb = input()\n\ts = []\n\ts.append([0, 0, 'ul'])\n\tdone = False\n\twhile s:\n\t\tc = s.pop(0)\n\t\tif c[0] == 1 and c[1] == n:\n\t\t\tdone = True\n\t\t\tbreak\n\t\tif c[1] == n:\n\t\t\tbreak\n\t\tif c[0] == 0:\n\t\t\tl = int(a[c[1]])\n\t\telse:\n\t\t\tl = int(b[c[1]])\n\t\tif l == 1 or l == 2:\n\t\t\tif c[2] == 'ul' or c[2] == 'bl':\n\t\t\t\ts.append([c[0], c[1] + 1, c[2]])\n\t\telif c[2] == 'ul':\n\t\t\ts.append([c[0] + 1, c[1], 'bu'])\n\t\telif c[2] == 'bl':\n\t\t\ts.append([c[0] - 1, c[1], 'ub'])\n\t\telif c[2] == 'bu':\n\t\t\ts.append([c[0], c[1] + 1, 'bl'])\n\t\telif c[2] == 'ub':\n\t\t\ts.append([c[0], c[1] + 1, 'ul'])\n\tif done:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor qi in range(q):\n\tn = int(input())\n\tm = [[int(x) for x in input()], [int(x) for x in input()]]\n\tyi = 0\n\tr = True\n\tfor xi in range(n):\n\t\tif m[yi][xi] >= 3:\n\t\t\tyi = abs(yi - 1)\n\t\t\tif m[yi][xi] <= 2:\n\t\t\t\tr = False\n\t\t\t\tbreak\n\telse:\n\t\tr = yi == 1\n\tprint('YES' if r else 'NO')\n", "q = int(input())\nfor _ in range(q):\n\ti = 0\n\tup = 1\n\tdown = 0\n\tc = 0\n\tn = int(input())\n\tl1 = list(map(int, input()))\n\tl2 = list(map(int, input()))\n\twhile i < n:\n\t\tif down == 1:\n\t\t\tif l2[i] > 2:\n\t\t\t\tif l1[i] <= 2:\n\t\t\t\t\tc += 1\n\t\t\t\t\tbreak\n\t\t\t\tup = 1\n\t\t\t\tdown = 0\n\t\telif up == 1:\n\t\t\tif l1[i] > 2:\n\t\t\t\tif l2[i] <= 2:\n\t\t\t\t\tc += 1\n\t\t\t\t\tbreak\n\t\t\t\tup = 0\n\t\t\t\tdown = 1\n\t\ti += 1\n\tif down == 1 and c == 0:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\ntypes = {'1': False, '2': False, '3': True, '4': True, '5': True, '6': True}\nfor i in range(q):\n\tn = int(input())\n\trows = [[types[ch] for ch in input()] for j in range(2)]\n\tcur_row = 0\n\tvalid = True\n\tfor j in range(n):\n\t\tif not rows[cur_row][j]:\n\t\t\tcontinue\n\t\tcur_row = (cur_row + 1) % 2\n\t\tif rows[cur_row][j]:\n\t\t\tcontinue\n\t\telse:\n\t\t\tvalid = False\n\t\t\tbreak\n\tvalid = valid and cur_row == 1\n\tif valid:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def checkPipe(upList, downList, n):\n\tcheckUp = True\n\tfor i in range(n):\n\t\tif checkUp:\n\t\t\tif upList[i] != 1 and upList[i] != 2:\n\t\t\t\tif downList[i] == 1 or downList[i] == 2:\n\t\t\t\t\treturn False\n\t\t\t\tcheckUp = False\n\t\telif downList[i] != 1 and downList[i] != 2:\n\t\t\tif upList[i] == 1 or upList[i] == 2:\n\t\t\t\treturn False\n\t\t\tcheckUp = True\n\tif checkUp:\n\t\treturn False\n\telse:\n\t\treturn True\nq = int(input())\nfor i in range(q):\n\tn = int(input())\n\tup = list(map(int, input()))\n\tdown = list(map(int, input()))\n\tif checkPipe(up, down, n):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "from collections import deque\nfor _ in range(int(input())):\n\tn = int(input())\n\tg = []\n\tg.append(list(input()))\n\tg.append(list(input()))\n\tf = 0\n\ti = 0\n\tx = 0\n\twhile i < n:\n\t\tif f == 0:\n\t\t\tif g[f][i] in '12':\n\t\t\t\tif x == 1:\n\t\t\t\t\tbreak\n\t\t\t\ti += 1\n\t\t\telif x == 0:\n\t\t\t\t(x, f) = (1, 1)\n\t\t\telse:\n\t\t\t\t(x, f) = (0, 0)\n\t\t\t\ti += 1\n\t\telif g[f][i] in '12':\n\t\t\tif x == 1:\n\t\t\t\tbreak\n\t\t\ti += 1\n\t\telif x == 0:\n\t\t\t(x, f) = (1, 0)\n\t\telse:\n\t\t\t(x, f) = (0, 1)\n\t\t\ti += 1\n\tif i == n and f == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor it in range(q):\n\tn = int(input())\n\ta = []\n\ta.append(list(map(int, list(input()))))\n\ta.append(list(map(int, list(input()))))\n\ti = j = 0\n\tfor i in range(n):\n\t\tif a[j][i] < 3:\n\t\t\tcontinue\n\t\telif a[j][i] >= 3 and a[1 - j][i] >= 3:\n\t\t\tj = 1 - j\n\t\telse:\n\t\t\tj = 0\n\t\t\tbreak\n\tprint('YES' if j == 1 else 'NO')\n", "import os\nfrom io import BytesIO, IOBase\nimport sys\nfrom collections import defaultdict, deque, Counter\nfrom math import sqrt, pi, ceil, log, inf, gcd, floor\nfrom itertools import combinations, permutations\nfrom bisect import *\nfrom fractions import Fraction\nfrom heapq import *\nfrom random import randint\n\ndef main():\n\tfor _ in range(int(input())):\n\t\tn = int(input())\n\t\ta = list(map(int, input().rstrip()))\n\t\tb = list(map(int, input().rstrip()))\n\t\tfor i in range(n):\n\t\t\tif a[i] < 3:\n\t\t\t\ta[i] = 1\n\t\t\telse:\n\t\t\t\ta[i] = 2\n\t\t\tif b[i] < 3:\n\t\t\t\tb[i] = 1\n\t\t\telse:\n\t\t\t\tb[i] = 2\n\t\tdp = [[0, 0] for _ in range(n)]\n\t\tif a[0] == 1:\n\t\t\tdp[0][0] = 1\n\t\tif b[0] == 2 and a[0] == 2:\n\t\t\tdp[0][1] = 1\n\t\tfor i in range(1, n):\n\t\t\tif dp[i - 1][0] and a[i] == 1 or (dp[i - 1][1] and b[i] == 2 and (a[i] == 2)):\n\t\t\t\tdp[i][0] = 1\n\t\t\tif dp[i - 1][1] and b[i] == 1 or (dp[i - 1][0] and b[i] == 2 and (a[i] == 2)):\n\t\t\t\tdp[i][1] = 1\n\t\tif dp[-1][1]:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nmain()\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ta = [[], []]\n\ta[0] = input()\n\ta[1] = input()\n\tr = 0\n\tw = 1\n\tflag = False\n\ti = 0\n\twhile i < n:\n\t\tif r == 0:\n\t\t\tif w == 1:\n\t\t\t\tif int(a[r][i]) <= 2:\n\t\t\t\t\tt = 1\n\t\t\t\telse:\n\t\t\t\t\tt = 2\n\t\t\t\tif t == 1:\n\t\t\t\t\ti += 1\n\t\t\t\t\tcontinue\n\t\t\t\telse:\n\t\t\t\t\tr = 1\n\t\t\t\t\tw = 2\n\t\t\telif w == 3:\n\t\t\t\tif int(a[r][i]) <= 2:\n\t\t\t\t\tt = 1\n\t\t\t\telse:\n\t\t\t\t\tt = 2\n\t\t\t\tif t == 1:\n\t\t\t\t\tflag = True\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\ti += 1\n\t\t\t\t\tw = 1\n\t\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tflag = True\n\t\t\t\tbreak\n\t\telif w == 1:\n\t\t\tif int(a[r][i]) <= 2:\n\t\t\t\tt = 1\n\t\t\telse:\n\t\t\t\tt = 2\n\t\t\tif t == 1:\n\t\t\t\ti += 1\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tr = 0\n\t\t\t\tw = 3\n\t\telif w == 2:\n\t\t\tif int(a[r][i]) <= 2:\n\t\t\t\tt = 1\n\t\t\telse:\n\t\t\t\tt = 2\n\t\t\tif t == 2:\n\t\t\t\ti += 1\n\t\t\t\tw = 1\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tflag = True\n\t\t\t\tbreak\n\t\telse:\n\t\t\tflag = True\n\t\t\tbreak\n\tif flag:\n\t\tprint('NO')\n\telif i == n and r == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\nimport os\nfrom io import IOBase, BytesIO\nimport math\nimport collections\nmod = 10 ** 9 + 7\npie = 3.1415926536\n\ndef modinv(n, p):\n\treturn pow(n, p - 2, p)\n\ndef ncr(n, r, p):\n\tt = fact[n] * (ifact[r] * ifact[n - r] % p) % p\n\treturn t\n\ndef ain():\n\treturn list(map(int, sin().split()))\n\ndef sin():\n\treturn input().strip()\n\ndef GCD(x, y):\n\twhile y:\n\t\t(x, y) = (y, x % y)\n\treturn x\n\ndef read2DIntArray(row, col):\n\tarr = []\n\tfor i in range(0, row):\n\t\ttemp = list(map(int, sin().split()))\n\t\tarr.append(temp)\n\treturn arr\n\ndef read2DCharArray(row, col):\n\tarr = []\n\tfor i in range(0, row):\n\t\ttemp = str(sin())\n\t\tarr.append(temp)\n\treturn arr\n\ndef smallestNumber(n):\n\tlst = list(str(n))\n\tlst.sort()\n\ttmp = ''\n\tfor (i, n) in enumerate(lst):\n\t\tif n != '0':\n\t\t\ttmp = lst.pop(i)\n\t\t\tbreak\n\treturn str(tmp) + ''.join(lst)\n\ndef SieveOfEratosthenes(n):\n\tprime = [True for i in range(n + 1)]\n\tp = 2\n\twhile p * p <= n:\n\t\tif prime[p] == True:\n\t\t\tfor i in range(p * 2, n + 1, p):\n\t\t\t\tprime[i] = False\n\t\tp += 1\n\tprime[0] = False\n\tprime[1] = False\n\tlst = []\n\tfor p in range(n + 1):\n\t\tif prime[p]:\n\t\t\tlst.append(p)\n\treturn lst\n\ndef nCr(n, r):\n\ta = 1\n\tb = 1\n\tc = 1\n\tfor i in range(1, n + 1):\n\t\tc *= i\n\tfor i in range(1, r + 1):\n\t\tb *= i\n\tfor i in range(1, n - r + 1):\n\t\ta *= i\n\treturn c // (a * b)\n\ndef sieveOfEratosthenes1(N, s):\n\tprime = [False] * (N + 1)\n\tfor i in range(2, N + 1, 2):\n\t\ts[i] = 2\n\tfor i in range(3, N + 1, 2):\n\t\tif prime[i] == False:\n\t\t\ts[i] = i\n\t\t\tfor j in range(i, int(N / i) + 1, 2):\n\t\t\t\tif prime[i * j] == False:\n\t\t\t\t\tprime[i * j] = True\n\t\t\t\t\ts[i * j] = i\n\ndef generatePrimeFactors(N):\n\ts = [0] * (N + 1)\n\tsieveOfEratosthenes1(N, s)\n\tcurr = s[N]\n\tcnt = 1\n\tfactors = []\n\tpower = []\n\twhile N > 1:\n\t\tN //= s[N]\n\t\tif curr == s[N]:\n\t\t\tcnt += 1\n\t\t\tcontinue\n\t\tfactors.append(curr)\n\t\tpower.append(cnt)\n\t\tcurr = s[N]\n\t\tcnt = 1\n\treturn (factors, power)\n\ndef main():\n\tfor _ in range(int(sin())):\n\t\tn = int(sin())\n\t\ts1 = sin()\n\t\ts2 = sin()\n\t\tlst = []\n\t\tlst.append(s1)\n\t\tlst.append(s2)\n\t\ti = 0\n\t\tj = 0\n\t\tst = 'R'\n\t\twhile i != n:\n\t\t\tpipe = lst[j][i]\n\t\t\tif st == 'R':\n\t\t\t\tif pipe == '1' or pipe == '2':\n\t\t\t\t\ti += 1\n\t\t\t\telif j == 0:\n\t\t\t\t\tst = 'D'\n\t\t\t\t\tj = 1\n\t\t\t\telse:\n\t\t\t\t\tst = 'U'\n\t\t\t\t\tj = 0\n\t\t\telif pipe == '1' or pipe == '2':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tst = 'R'\n\t\t\t\ti += 1\n\t\tif i == n and j == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\npy2 = round(0.5)\nif py2:\n\tfrom future_builtins import ascii, filter, hex, map, oct, zip\n\trange = xrange\nBUFSIZE = 8192\n\nclass FastIO(BytesIO):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._file = file\n\t\tself._fd = file.fileno()\n\t\tself.writable = 'x' in file.mode or 'w' in file.mode\n\t\tself.write = super(FastIO, self).write if self.writable else None\n\n\tdef _fill(self):\n\t\ts = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\tself.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])\n\t\treturn s\n\n\tdef read(self):\n\t\twhile self._fill():\n\t\t\tpass\n\t\treturn super(FastIO, self).read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\ts = self._fill()\n\t\t\tself.newlines = s.count(b'\\n') + (not s)\n\t\tself.newlines -= 1\n\t\treturn super(FastIO, self).readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.getvalue())\n\t\t\t(self.truncate(0), self.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tif py2:\n\t\t\tself.write = self.buffer.write\n\t\t\tself.read = self.buffer.read\n\t\t\tself.readline = self.buffer.readline\n\t\telse:\n\t\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\n\ndef input():\n\treturn sys.stdin.readline().rstrip('\\r\\n')\nmain()\n", "ans = []\nfor _ in range(int(input())):\n\tn = int(input())\n\ts = list(input())\n\tt = list(input())\n\tlvl = 0\n\tX = [s, t]\n\tf = 1\n\tfor i in range(n):\n\t\tif s[i] in '3456' and t[i] in '3456':\n\t\t\tlvl = 1 - lvl\n\t\telif X[lvl][i] in '3456':\n\t\t\tf = 0\n\t\t\tans.append('NO')\n\t\t\tbreak\n\tif f and lvl == 1:\n\t\tans.append('YES')\n\telif f:\n\t\tans.append('NO')\nprint('\\n'.join(ans))\n", "for _ in range(int(input())):\n\tn = int(input())\n\ta = list(input())\n\ts = list(input())\n\tnormal = {'1', '2'}\n\tcurved = {'3', '4', '5', '6'}\n\tarr = []\n\tarr.append(a)\n\tarr.append(s)\n\trow = 0\n\twhere = 0\n\ti = 0\n\twhile i < n:\n\t\tif arr[row][i] in normal:\n\t\t\tif where == row:\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\telif where != row:\n\t\t\twhere = row\n\t\t\ti += 1\n\t\telse:\n\t\t\twhere = row\n\t\t\trow ^= 1\n\telse:\n\t\tif row == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "q = int(input())\ncorners = {3, 4, 5, 6}\nedges = {1, 2}\nfor _ in range(q):\n\tn = int(input())\n\tl = [[int(x) for x in input()], [int(x) for x in input()]]\n\ti = 0\n\tj = 0\n\twhile True:\n\t\tif i == n:\n\t\t\tprint('YES' if j == 1 else 'NO')\n\t\t\tbreak\n\t\tif l[j][i] in corners:\n\t\t\tj ^= 1\n\t\t\tif l[j][i] in edges:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\ti += 1\n\t\telse:\n\t\t\ti += 1\n", "t = int(input())\nwhile t:\n\tn = int(input())\n\tstr1 = input()\n\tstr2 = input()\n\tarr = [0, str1, str2]\n\tj = 1\n\tfor i in range(n):\n\t\tif int(arr[j][i]) == 1 or int(arr[j][i]) == 2:\n\t\t\tj = j\n\t\telse:\n\t\t\tif j == 1:\n\t\t\t\tj = 2\n\t\t\telse:\n\t\t\t\tj = 1\n\t\t\tif int(arr[j][i]) == 1 or int(arr[j][i]) == 2:\n\t\t\t\tj = 0\n\t\t\t\tbreak\n\tif j == 2 and i == n - 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n\tt -= 1\n", "for i in range(int(input())):\n\tn = int(input())\n\ts1 = list(map(int, list(input())))\n\ts2 = list(map(int, list(input())))\n\tdp = [s1, s2]\n\tx = 0\n\ty = 0\n\t(d, u, s) = (0, 0, 0)\n\tans = 'YES'\n\twhile x < n:\n\t\tif x == 0 and y == 0:\n\t\t\tif dp[y][x] == 1 or dp[y][x] == 2:\n\t\t\t\ts = 1\n\t\t\t\tx += 1\n\t\t\telse:\n\t\t\t\t(s, u) = (0, 0)\n\t\t\t\t(d, y) = (1, 1)\n\t\telif s == 1:\n\t\t\tif y == 0:\n\t\t\t\tif dp[y][x] == 1 or dp[y][x] == 2:\n\t\t\t\t\tx += 1\n\t\t\t\t\ts = 1\n\t\t\t\t\t(y, d, u) = (0, 0, 0)\n\t\t\t\telse:\n\t\t\t\t\ty = 1\n\t\t\t\t\td = 1\n\t\t\t\t\t(s, u) = (0, 0)\n\t\t\telif dp[y][x] == 1 or dp[y][x] == 2:\n\t\t\t\tx += 1\n\t\t\t\ts = 1\n\t\t\t\t(d, u) = (0, 0)\n\t\t\telse:\n\t\t\t\ty = 0\n\t\t\t\tu = 1\n\t\t\t\t(s, d) = (0, 0)\n\t\telif u == 1:\n\t\t\tif dp[y][x] == 1 or dp[y][x] == 2:\n\t\t\t\tans = 'NO'\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tx += 1\n\t\t\t\ts = 1\n\t\t\t\t(d, u) = (0, 0)\n\t\telif d == 1:\n\t\t\tif dp[y][x] == 1 or dp[y][x] == 2:\n\t\t\t\tans = 'NO'\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tx += 1\n\t\t\t\ts = 1\n\t\t\t\t(d, u) = (0, 0)\n\tif x == n and y == 1:\n\t\tprint(ans)\n\telse:\n\t\tprint('NO')\n", "q = int(input())\ntype1 = '12'\ntype2 = '3456'\nfor i in range(q):\n\tn = int(input())\n\trow1 = list(input())\n\trow2 = list(input())\n\trows = [row1, row2]\n\tcolumn = 0\n\trow = 0\n\twhile column < n:\n\t\tif rows[row][column] in type1:\n\t\t\tcolumn += 1\n\t\telif rows[1 - row][column] in type2:\n\t\t\tcolumn += 1\n\t\t\trow = 1 - row\n\t\telse:\n\t\t\tbreak\n\tif column == n and row == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\n\ndef switch(x):\n\tif x == 1:\n\t\treturn 0\n\treturn 1\nfor _ in range(q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tr1 = [1 if x == '1' or x == '2' else 0 for x in s1]\n\tr2 = [1 if x == '1' or x == '2' else 0 for x in s2]\n\tr1.append(1)\n\tr2.append(1)\n\tA = [r1, r2]\n\ttemp = 0\n\tcheck = False\n\tfor i in range(n):\n\t\tif A[temp][i] == 1:\n\t\t\tcontinue\n\t\telif A[temp][i] == 0 and A[switch(temp)][i] == 1:\n\t\t\tcheck = True\n\t\t\tbreak\n\t\telse:\n\t\t\ttemp = switch(temp)\n\tif check:\n\t\tprint('NO')\n\telif temp == 0:\n\t\tif A[switch(temp)][n] == 1:\n\t\t\tprint('NO')\n\t\telse:\n\t\t\tprint('YES')\n\telif A[temp][n] == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor case in range(q):\n\tn = int(input())\n\tr1 = input()\n\tr2 = input()\n\t(r, c, s, f) = (1, 1, 'i', True)\n\tif r1[0] == '3' or r1[0] == '4' or r1[0] == '5' or (r1[0] == '6'):\n\t\ts = 'd'\n\telif r1[0] == '1' or r1[0] == '2':\n\t\ts = 'r'\n\twhile c < n:\n\t\tif s == 'u' and (r1[c - 1] == '1' or r1[c - 1] == '2'):\n\t\t\tf = False\n\t\t\tbreak\n\t\telif s == 'd' and (r2[c - 1] == '1' or r2[c - 1] == '2'):\n\t\t\tf = False\n\t\t\tbreak\n\t\telif s == 'u':\n\t\t\t(r, s) = (1, 'r')\n\t\telif s == 'd':\n\t\t\t(r, s) = (2, 'r')\n\t\telif s == 'r' and r == 1:\n\t\t\tc += 1\n\t\t\tif r1[c - 1] == '3' or r1[c - 1] == '4' or r1[c - 1] == '5' or (r1[c - 1] == '6'):\n\t\t\t\ts = 'd'\n\t\telif s == 'r' and r == 2:\n\t\t\tc += 1\n\t\t\tif r2[c - 1] == '3' or r2[c - 1] == '4' or r2[c - 1] == '5' or (r2[c - 1] == '6'):\n\t\t\t\ts = 'u'\n\tif r == 1 and (s != 'd' or r2[n - 1] == '1' or r2[n - 1] == '2'):\n\t\tf = False\n\telif r == 2 and s != 'r':\n\t\tf = False\n\tif f:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor q in range(q):\n\tn = int(input())\n\tstr1 = input()\n\tstr2 = input()\n\tcurr = 0\n\tconc = []\n\tflag = True\n\tfor i in range(n):\n\t\tconc.append((str1[i], str2[i]))\n\tfor i in range(n):\n\t\tif conc[i][curr] == '1' or conc[i][curr] == '2':\n\t\t\tcontinue\n\t\telse:\n\t\t\tif conc[i][1 - curr] not in ['3', '4', '5', '6']:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\tcurr = 1 - curr\n\tif not flag or curr != 1:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "Q = int(input())\nfor q in range(Q):\n\tn = int(input())\n\tarr = []\n\tarr.append(list(input()))\n\tarr.append(list(input()))\n\t(x, y) = (0, 0)\n\td = 0\n\tpos = 1\n\twhile pos:\n\t\tp = arr[y][x]\n\t\tif p == '1' or p == '2':\n\t\t\tif d == 0:\n\t\t\t\tx += 1\n\t\t\telse:\n\t\t\t\tpos = 0\n\t\t\t\tbreak\n\t\telif y == 0:\n\t\t\tif d == 0:\n\t\t\t\ty = 1\n\t\t\t\td = 1\n\t\t\telse:\n\t\t\t\tx += 1\n\t\t\t\td = 0\n\t\telif d == 0:\n\t\t\ty = 0\n\t\t\td = -1\n\t\telse:\n\t\t\tx += 1\n\t\t\td = 0\n\t\tif x == n and y == 1:\n\t\t\tpos = 1\n\t\t\tbreak\n\t\tif x > n - 1 or y > 1:\n\t\t\tpos = 0\n\t\t\tbreak\n\tif pos:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nans = []\ntrubi = {1: 1, 2: 1, 3: 2, 4: 2, 5: 2, 6: 2}\nfor i in range(q):\n\tn = int(input())\n\trow1 = list(map(int, input()))\n\trow2 = list(map(int, input()))\n\trow = row1 + row2\n\tif not (1 in row or 2 in row):\n\t\tif n % 2 == 0:\n\t\t\tans.append('NO')\n\t\telse:\n\t\t\tans.append('YES')\n\telif not (3 in row1 or 4 in row1 or 5 in row1 or (6 in row1)):\n\t\tans.append('NO')\n\telse:\n\t\tcount = 0\n\t\tfor j in range(n):\n\t\t\tif count % 2 == 0:\n\t\t\t\tif trubi[row1[j]] == 2:\n\t\t\t\t\tif trubi[row2[j]] != 2:\n\t\t\t\t\t\tans.append('NO')\n\t\t\t\t\t\tbreak\n\t\t\t\t\telse:\n\t\t\t\t\t\tcount += 1\n\t\t\telif trubi[row2[j]] == 2:\n\t\t\t\tif trubi[row1[j]] != 2:\n\t\t\t\t\tans.append('NO')\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tcount += 1\n\t\t\tif j == n - 1:\n\t\t\t\tif count % 2 == 0:\n\t\t\t\t\tans.append('NO')\n\t\t\t\telse:\n\t\t\t\t\tans.append('YES')\nprint(*ans, sep='\\n')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ta = list(map(int, list(input())))\n\tb = list(map(int, list(input())))\n\tc = [[0 for i in range(n)] for i in range(2)]\n\tfor i in range(n):\n\t\tif a[i] < 3:\n\t\t\tc[0][i] = 1\n\t\telse:\n\t\t\tc[0][i] = 2\n\t\tif b[i] < 3:\n\t\t\tc[1][i] = 1\n\t\telse:\n\t\t\tc[1][i] = 2\n\tlast = True\n\tnow = 0\n\tind = 0\n\tlast_now = 0\n\tflag = True\n\twhile ind < n and flag:\n\t\tif c[now][ind] == 1:\n\t\t\tif now != last_now:\n\t\t\t\tflag = False\n\t\t\telse:\n\t\t\t\tind += 1\n\t\t\t\tlast_now = now\n\t\telif last_now != now:\n\t\t\tind += 1\n\t\t\tlast_now = now\n\t\telse:\n\t\t\tlast_now = now\n\t\t\tnow ^= 1\n\tif now == 1 and ind == n and flag:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\nsys.setrecursionlimit(10 ** 9)\ninput = sys.stdin.readline\n\ndef solve():\n\tN = int(input())\n\tL = [[v for v in input()[:-1]] for _ in range(2)]\n\tcur_x = 0\n\tcur_y = 0\n\tprev_flow_from = 'L'\n\tans = 'YES'\n\twhile True:\n\t\tcur_pipe = L[cur_y][cur_x]\n\t\tif cur_pipe == '1' or cur_pipe == '2':\n\t\t\tif prev_flow_from == 'L':\n\t\t\t\tnext_x = cur_x + 1\n\t\t\t\tnext_y = cur_y\n\t\t\telif prev_flow_from == 'D':\n\t\t\t\tans = 'NO'\n\t\t\t\tbreak\n\t\t\telif prev_flow_from == 'U':\n\t\t\t\tans = 'NO'\n\t\t\t\tbreak\n\t\telif prev_flow_from == 'L':\n\t\t\tif cur_y == 0:\n\t\t\t\tnext_x = cur_x\n\t\t\t\tnext_y = cur_y + 1\n\t\t\t\tprev_flow_from = 'D'\n\t\t\telif cur_y == 1:\n\t\t\t\tnext_x = cur_x\n\t\t\t\tnext_y = cur_y - 1\n\t\t\t\tprev_flow_from = 'U'\n\t\telif prev_flow_from == 'D':\n\t\t\tnext_x = cur_x + 1\n\t\t\tnext_y = cur_y\n\t\t\tprev_flow_from = 'L'\n\t\telif prev_flow_from == 'U':\n\t\t\tnext_x = cur_x + 1\n\t\t\tnext_y = cur_y\n\t\t\tprev_flow_from = 'L'\n\t\tif next_x == N and next_y == 1:\n\t\t\tif prev_flow_from == 'L':\n\t\t\t\tans = 'YES'\n\t\t\telse:\n\t\t\t\tans = 'NO'\n\t\t\tbreak\n\t\telif 0 <= next_x < N and 0 <= next_y < 2:\n\t\t\tcur_x = next_x\n\t\t\tcur_y = next_y\n\t\t\tcontinue\n\t\telse:\n\t\t\tans = 'NO'\n\t\t\tbreak\n\tprint(ans)\nN = int(input())\nfor _ in range(N):\n\tsolve()\n", "t = int(input())\nfor _ in range(t):\n\tn = int(input())\n\ta = list(input())\n\tb = list(input())\n\tf = 0\n\tc = 0\n\tfor i in range(n):\n\t\tif c == 0:\n\t\t\tif a[i] == '1' or a[i] == '2':\n\t\t\t\tpass\n\t\t\telse:\n\t\t\t\tc = 1\n\t\t\t\tif b[i] == '1' or b[i] == '2':\n\t\t\t\t\tf = 1\n\t\t\t\t\tbreak\n\t\telif b[i] == '1' or b[i] == '2':\n\t\t\tpass\n\t\telse:\n\t\t\tc = 0\n\t\t\tif a[i] == '1' or a[i] == '2':\n\t\t\t\tf = 1\n\t\t\t\tbreak\n\tif f == 0 and c == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "num = int(input())\nfor i in range(num):\n\tnumPipes = int(input())\n\trow1 = input()\n\trow1 = [int(x) for x in row1]\n\trow2 = input()\n\trow2 = [int(x) for x in row2]\n\trow1Bool = True\n\trow2Bool = False\n\tfor j in range(numPipes):\n\t\ttemp1 = row1Bool and row1[j] < 3 or (row2Bool and row1[j] > 2 and (row2[j] > 2))\n\t\ttemp2 = row2Bool and row2[j] < 3 or (row1Bool and row1[j] > 2 and (row2[j] > 2))\n\t\trow1Bool = temp1\n\t\trow2Bool = temp2\n\tprint('YES' if row2Bool else 'NO')\n", "import sys\ninput = lambda : sys.stdin.readline().strip()\nipnut = input\nfor i in range(int(input())):\n\tn = int(ipnut())\n\tfield = [list(map(int, ipnut())), list(map(int, input()))]\n\t(x, y) = (0, 0)\n\tfr = 0\n\tflag = True\n\tfor i in range(2 * n):\n\t\tif y == n:\n\t\t\tbreak\n\t\tif fr:\n\t\t\tif fr == 1:\n\t\t\t\tif field[x][y] in [1, 2]:\n\t\t\t\t\ty += 1\n\t\t\t\telse:\n\t\t\t\t\tx = (x + 1) % 2\n\t\t\t\t\tfr = 2\n\t\t\telif field[x][y] in [1, 2]:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ty += 1\n\t\t\t\tfr = 1\n\t\telif field[x][y] in [1, 2]:\n\t\t\ty += 1\n\t\t\tfr = 1\n\t\telse:\n\t\t\tx = (x + 1) % 2\n\t\t\tfr = 2\n\tif flag and x:\n\t\tprint('Yes')\n\telse:\n\t\tprint('NO')\n", "def is_A(x):\n\treturn x == '1' or x == '2'\n\ndef is_B(x):\n\treturn x == '3' or x == '4' or x == '5' or (x == '6')\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\ts = [s1, s2]\n\t(res, p, j, i) = (True, 0, 0, 0)\n\twhile i < n:\n\t\tif p == 0 and is_A(s[j][i]):\n\t\t\tp = 0\n\t\telif p == 1 and is_B(s[j][i]):\n\t\t\tp = 0\n\t\telif p == 0 and is_B(s[j][i]):\n\t\t\tif j == 0:\n\t\t\t\tp = 1\n\t\t\telse:\n\t\t\t\tp = 2\n\t\t\tj = 1 - j\n\t\t\ti -= 1\n\t\telif p == 2 and is_B(s[j][i]):\n\t\t\tp = 0\n\t\telse:\n\t\t\tres = False\n\t\ti += 1\n\tprint('YES' if res and j == 1 else 'NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ta = []\n\ta.append([int(i) for i in list(input())])\n\ta.append([int(i) for i in list(input())])\n\tpos = 0\n\tfor i in range(n):\n\t\tif a[pos][i] > 2:\n\t\t\tif a[abs(pos - 1)][i] > 2:\n\t\t\t\tpos = abs(pos - 1)\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\telse:\n\t\tif pos == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tr = 1\n\tch = 1\n\tfor i in range(n):\n\t\tif r == 1:\n\t\t\tif s1[i] == '1' or s1[i] == '2':\n\t\t\t\tch = ch\n\t\t\t\tr = 1\n\t\t\telse:\n\t\t\t\tr = 2\n\t\t\t\tif s2[i] == '1' or s2[i] == '2':\n\t\t\t\t\tch = 0\n\t\telif s2[i] == '1' or s2[i] == '2':\n\t\t\tch = ch\n\t\t\tr = 2\n\t\telse:\n\t\t\tr = 1\n\t\t\tif s1[i] == '1' or s1[i] == '2':\n\t\t\t\tch = 0\n\tif ch == 0 or r == 1:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "for i in range(int(input())):\n\ts = int(input())\n\tp = [[int(i) for i in input()], [int(i) for i in input()]]\n\td = 3\n\tq = [0, 0]\n\twhile q != [1, s]:\n\t\tif 0 <= q[0] < 2 and 0 <= q[1] < s:\n\t\t\tr = p[q[0]][q[1]]\n\t\t\tif r < 3:\n\t\t\t\tif d == 3:\n\t\t\t\t\tq = [q[0], q[1] + 1]\n\t\t\t\telse:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\telif q[0] == 1 and d == 0:\n\t\t\t\tq = [1, q[1] + 1]\n\t\t\t\td = 3\n\t\t\telif q[0] == 1 and d == 3:\n\t\t\t\tq = [0, q[1]]\n\t\t\t\td = 2\n\t\t\telif q[0] == 0 and d == 3:\n\t\t\t\tq = [1, q[1]]\n\t\t\t\td = 0\n\t\t\telif q[0] == 0 and d == 2:\n\t\t\t\tq = [0, q[1] + 1]\n\t\t\t\td = 3\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\telse:\n\t\t\tprint('NO')\n\t\t\tbreak\n\telse:\n\t\tif d == 3:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "test = int(input())\nfor _ in range(test):\n\tn = int(input())\n\tarr = [[int(el) for el in str(input())] for i in range(2)]\n\tmatrix = [[0 for y in range(n + 1)] for i in range(2)]\n\tmatrix[0][0] = True\n\tis_ok = [1, 2]\n\tis_not_ok = [3, 4, 5, 6]\n\tfor i in range(1, n + 1):\n\t\tif arr[0][i - 1] in is_ok:\n\t\t\tmatrix[0][i] = matrix[0][i - 1]\n\t\tif arr[1][i - 1] in is_ok:\n\t\t\tmatrix[1][i] = matrix[1][i - 1]\n\t\tif arr[0][i - 1] in is_not_ok and arr[1][i - 1] in is_not_ok:\n\t\t\tmatrix[0][i] = matrix[0][i] or matrix[1][i - 1]\n\t\t\tmatrix[1][i] = matrix[1][i] or matrix[0][i - 1]\n\tprint('YES' if bool(matrix[1][n]) else 'NO')\n", "t = int(input())\nfor _ in range(t):\n\tn = int(input())\n\tarr = [int(i) for i in input()]\n\tbrr = [int(i) for i in input()]\n\tgrid = list(zip(arr, brr))\n\tway = 0\n\tflag = 0\n\trule1 = [1, 2]\n\trule2 = [3, 4, 5, 6]\n\tfor i in grid:\n\t\tif i[way] == 1 or i[way] == 2:\n\t\t\tpass\n\t\telif i[1] in rule1 or i[0] in rule1:\n\t\t\tflag = 1\n\t\t\tbreak\n\t\telif way == 1:\n\t\t\tway = 0\n\t\telse:\n\t\t\tway = 1\n\tif flag == 1 or way == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "cases = int(input())\nfor _ in range(cases):\n\tnumPipes = int(input())\n\tpipesTop = input()\n\tpipesBot = input()\n\trow = 0\n\tcol = 0\n\ttopTurn = 2\n\tbotTurn = 2\n\tlastPipe = -1\n\twhile col < numPipes:\n\t\tif row == 0:\n\t\t\tpipe = int(pipesTop[col])\n\t\t\tif pipe <= 2:\n\t\t\t\tcol += 1\n\t\t\t\tif topTurn == 1:\n\t\t\t\t\tcol = -1\n\t\t\t\t\tbreak\n\t\t\telif topTurn == 2:\n\t\t\t\trow = 1\n\t\t\t\ttopTurn = 1\n\t\t\t\tbotTurn = 1\n\t\t\telse:\n\t\t\t\ttopTurn = 2\n\t\t\t\tcol += 1\n\t\telse:\n\t\t\tpipe = int(pipesBot[col])\n\t\t\tif pipe <= 2:\n\t\t\t\tcol += 1\n\t\t\t\tif botTurn == 1:\n\t\t\t\t\tcol = -1\n\t\t\t\t\tbreak\n\t\t\telif botTurn == 2:\n\t\t\t\trow = 0\n\t\t\t\ttopTurn = 1\n\t\t\t\tbotTurn = 1\n\t\t\telse:\n\t\t\t\tbotTurn = 2\n\t\t\t\tcol += 1\n\tif row == 1 and col == numPipes:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "dx = [0, 1, 0, -1]\ndy = [-1, 0, 1, 0]\n\ndef next_xy(x, y, d):\n\treturn (x + dx[d], y + dy[d])\n\ndef ok_xy(x, y, n):\n\treturn 0 <= x < n and 0 <= y < 2\n\ndef solve():\n\tn = int(input())\n\ta = [0, 0]\n\ta[0] = list(map(int, input()))\n\ta[1] = list(map(int, input()))\n\tx = -1\n\ty = 0\n\td = 1\n\twhile True:\n\t\t(nx, ny) = next_xy(x, y, d)\n\t\tassert ok_xy(nx, ny, n)\n\t\tif a[ny][nx] in (1, 2):\n\t\t\tnd = d\n\t\telif d in (0, 2):\n\t\t\tnd = 1\n\t\telif ny == 0:\n\t\t\tnd = 2\n\t\telse:\n\t\t\tnd = 0\n\t\t(x, y, d) = (nx, ny, nd)\n\t\tif x == n - 1 and y == 1 and (d == 1):\n\t\t\treturn\n\ndef main():\n\tq = int(input())\n\tfor _ in range(q):\n\t\ttry:\n\t\t\tsolve()\n\t\texcept AssertionError:\n\t\t\tprint('NO')\n\t\telse:\n\t\t\tprint('YES')\nmain()\n", "for _ in range(int(input())):\n\tn = int(input())\n\tl1 = list(map(int, input()))\n\tl2 = list(map(int, input()))\n\trow = 1\n\tent = 10\n\text = 10\n\ti = 0\n\tflag = 1\n\twhile i < n and flag:\n\t\tif l1[i] in [1, 2] and row == 1 and (ent in [-1, 10]):\n\t\t\tent = -1\n\t\t\text = 1\n\t\telif l2[i] in [1, 2] and row == 0 and (ent in [-1, 10]):\n\t\t\tent = -1\n\t\t\text = 1\n\t\telif l1[i] in [3, 4, 5, 6] and ent in [-1, 10] and (row == 1):\n\t\t\tent = 2\n\t\t\text = 0\n\t\t\trow = 0\n\t\telif l2[i] in [3, 4, 5, 6] and row == 0 and (ent in [2, 10]):\n\t\t\tent = -1\n\t\t\text = 1\n\t\t\trow = 0\n\t\telif l2[i] in [3, 4, 5, 6] and ent in [-1, 10] and (row == 0):\n\t\t\tent = 0\n\t\t\text = 2\n\t\t\trow = 1\n\t\telif l1[i] in [3, 4, 5, 6] and row == 1 and (ent in [0, 10]):\n\t\t\tent = -1\n\t\t\text = 1\n\t\telse:\n\t\t\tflag = 0\n\t\t\tbreak\n\t\tif ext == 1:\n\t\t\ti += 1\n\tif row == 0 and ext == 1 and flag:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "t = int(input())\nfor k in range(1, t + 1):\n\tn = int(input())\n\tupper = input()\n\tlower = input()\n\ti = 0\n\tj = 0\n\twhile (i == 0 or i == 1) and (j >= 0 and j < n):\n\t\tif i == 0:\n\t\t\tif int(upper[j]) == 1 or int(upper[j]) == 2:\n\t\t\t\tj = j + 1\n\t\t\telif int(lower[j]) == 1 or int(lower[j]) == 2:\n\t\t\t\ti = 3\n\t\t\telse:\n\t\t\t\ti = 1\n\t\t\t\tj = j + 1\n\t\telif int(lower[j]) == 1 or int(lower[j]) == 2:\n\t\t\tj = j + 1\n\t\telif int(upper[j]) == 1 or int(upper[j]) == 2:\n\t\t\ti = 3\n\t\telse:\n\t\t\tj = j + 1\n\t\t\ti = 0\n\tif i == 1 and j == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tmatrix = []\n\tmatrix.append(list(input()))\n\tmatrix.append(list(input()))\n\t(pi, pj) = (0, -1)\n\t(i, j) = (0, 0)\n\tvisited = [[0 for i in range(n)] for i in range(2)]\n\twhile i < 2 and j < n:\n\t\tif visited[i][j] == 1:\n\t\t\tbreak\n\t\tvisited[i][j] = 1\n\t\tif matrix[i][j] == '1' or matrix[i][j] == '2':\n\t\t\tif pi == i:\n\t\t\t\tj += 1\n\t\t\t\tpj += 1\n\t\t\telse:\n\t\t\t\tbreak\n\t\telif pi == i:\n\t\t\t(pi, pj) = (i, j)\n\t\t\tif j < pj:\n\t\t\t\tbreak\n\t\t\tif i == 0:\n\t\t\t\ti = 1\n\t\t\telse:\n\t\t\t\ti = 0\n\t\telse:\n\t\t\t(pi, pj) = (i, j)\n\t\t\tj += 1\n\tif i == 1 and j == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def trub(path: list, n):\n\tF = [[0] * n for z in range(2)]\n\ti = j = corner = 0\n\twhile j < n:\n\t\tif 1 <= int(path[i][j]) <= 2:\n\t\t\tj += 1\n\t\telif 3 <= int(path[i][j]) <= 6:\n\t\t\tif int(path[1 - i % 2][j]) < 3:\n\t\t\t\treturn 'NO'\n\t\t\telse:\n\t\t\t\tj += 1\n\t\t\t\ti = 1 - i % 2\n\treturn 'YES' if i > 0 else 'NO'\nfor k in range(int(input())):\n\tn = int(input())\n\tr0 = input()\n\tr1 = input()\n\tpath = [r0, r1]\n\tprint(trub(path, n))\n", "from math import *\nm = int(input())\n\ndef func(a):\n\tif a == '1' or a == '2':\n\t\treturn 0\n\telse:\n\t\treturn 1\nfor _ in range(m):\n\ttmp = 0\n\tn = int(input())\n\tt = []\n\tt.append(input())\n\tt.append(input())\n\tk = 0\n\tfor i in range(n):\n\t\tif func(t[tmp][i]) == 1 and func(t[0][i]) == func(t[1][i]):\n\t\t\ttmp = 1 - tmp\n\t\telif func(t[tmp][i]) != 0:\n\t\t\tbreak\n\t\tk += 1\n\tif tmp == 1 and k == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "queries = []\nnb_queries = int(input())\nfor i in range(nb_queries):\n\tquery = dict()\n\tquery['taille_pipe'] = int(input())\n\tquery['firt_pipe'] = input()\n\tquery['second_pipe'] = input()\n\tqueries.append(query)\nfor query in queries:\n\tprevious = True\n\tpipe_dict = {True: query['firt_pipe'], False: query['second_pipe']}\n\tfor i in range(query['taille_pipe']):\n\t\tif pipe_dict[previous][i] <= str(2):\n\t\t\tcontinue\n\t\telif int(query['firt_pipe'][i]) > 2 and int(query['second_pipe'][i]) > 2:\n\t\t\tprevious = not previous\n\t\telse:\n\t\t\tprevious = None\n\t\t\tbreak\n\tif previous == False:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\nfrom sys import stdin, stdout\nfrom collections import defaultdict\nfrom collections import deque\nimport math\nimport copy\nT = int(input())\nfor i in range(T):\n\tN = int(input())\n\ts = input()\n\ts2 = input()\n\ts = [int(x) for x in list(s)]\n\ts2 = [int(x) for x in list(s2)]\n\tpipe = [s, s2]\n\trow = 0\n\tcol = 0\n\tlast = 1\n\tif pipe[row][col] <= 2:\n\t\tcol += 1\n\t\tlast = 3\n\telif pipe[row][col] >= 3:\n\t\trow += 1\n\t\tlast = 4\n\twhile col < N:\n\t\tflag = 0\n\t\tif row == 0 and last == 3:\n\t\t\tif pipe[row][col] <= 2:\n\t\t\t\tcol += 1\n\t\t\t\tlast = 3\n\t\t\telse:\n\t\t\t\trow += 1\n\t\t\t\tlast = 4\n\t\telif row == 0 and last == 2:\n\t\t\tif pipe[row][col] >= 3:\n\t\t\t\tcol += 1\n\t\t\t\tlast = 3\n\t\t\telse:\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\t\telif row == 1 and last == 3:\n\t\t\tif pipe[row][col] <= 2:\n\t\t\t\tcol += 1\n\t\t\t\tlast = 3\n\t\t\telse:\n\t\t\t\trow -= 1\n\t\t\t\tlast = 2\n\t\telif row == 1 and last == 4:\n\t\t\tif pipe[row][col] >= 3:\n\t\t\t\tcol += 1\n\t\t\t\tlast = 3\n\t\t\telse:\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\tif flag == 1:\n\t\tprint('NO')\n\telif row == 1 and col == N:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nn = [None] * q\np = [[]] * q\nfor i in range(q):\n\tn[i] = int(input())\n\tp1 = list(map(int, [i for i in input()]))\n\tp2 = list(map(int, [i for i in input()]))\n\tp1 = [0] + p1\n\tp2 = [0] + p2\n\tp[i] = (p1, p2)\n(ver, hor) = (0, 1)\na = (1, 2)\nb = (3, 4, 5, 6)\n\ndef next_pos(cur, d, pipe):\n\t(x, y) = cur\n\tif d == hor and pipe in a:\n\t\treturn ((x, y + 1), hor)\n\telif d == hor and pipe in b:\n\t\tif x == 1:\n\t\t\treturn ((x + 1, y), ver)\n\t\tif x == 2:\n\t\t\treturn ((x - 1, y), ver)\n\telif d == ver and pipe in b:\n\t\treturn ((x, y + 1), hor)\n\telse:\n\t\treturn ((-1, -1), -1)\nfor i in range(q):\n\ts = (1, 1)\n\te = (2, n[i] + 1)\n\td = hor\n\tpipe = p[i][0][1]\n\twhile True:\n\t\t(s, d) = next_pos(s, d, pipe)\n\t\tif s == e:\n\t\t\tprint('YES')\n\t\t\tbreak\n\t\tif d == -1 or (s[0] == 1 and s[1] == n[i] + 1):\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tpipe = p[i][s[0] - 1][s[1]]\n", "for _ in range(int(input())):\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tz = 0\n\tans = 0\n\tfor i in range(n):\n\t\tif z == 0:\n\t\t\tif a[i] == '1' or a[i] == '2':\n\t\t\t\tcontinue\n\t\t\telif a[i] in '3456' and b[i] in '3546':\n\t\t\t\tz = 1\n\t\t\telse:\n\t\t\t\tans = 1\n\t\telif b[i] == '1' or b[i] == '2':\n\t\t\tcontinue\n\t\telif a[i] in '3456' and b[i] in '4356':\n\t\t\tz = 0\n\t\telse:\n\t\t\tans = 1\n\t\tif ans == 1:\n\t\t\tbreak\n\tif ans == 0 and z == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def checkPipeSystem(pipeSystem, flowIn):\n\tif len(pipeSystem) == 1:\n\t\tif flowIn == 'Up':\n\t\t\tif pipeSystem[0][0] > 2 and pipeSystem[0][1] > 2:\n\t\t\t\treturn 'YES'\n\t\t\treturn 'NO'\n\t\tif flowIn == 'Down':\n\t\t\tif pipeSystem[0][0] < 3:\n\t\t\t\treturn 'YES'\n\t\t\treturn 'NO'\n\tif flowIn == 'Up':\n\t\tif pipeSystem[0][0] > 2 and pipeSystem[0][1] > 2:\n\t\t\treturn checkPipeSystem(pipeSystem[1:], 'Down')\n\t\tif pipeSystem[0][0] < 3:\n\t\t\treturn checkPipeSystem(pipeSystem[1:], 'Up')\n\t\treturn 'NO'\n\tif flowIn == 'Down':\n\t\tif pipeSystem[0][0] > 2 and pipeSystem[0][1] > 2:\n\t\t\treturn checkPipeSystem(pipeSystem[1:], 'Up')\n\t\tif pipeSystem[0][1] < 3:\n\t\t\treturn checkPipeSystem(pipeSystem[1:], 'Down')\n\t\treturn 'NO'\nqueries = int(input())\nresult = ''\ntype1 = ['1', '2']\ntype2 = ['3', '4', '5', '6']\nfor i in range(queries):\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tflowIn = 'Up'\n\tcheck = 'YES'\n\tfor j in range(n - 1):\n\t\tif flowIn == 'Up':\n\t\t\tif a[j] in type2 and b[j] in type2:\n\t\t\t\tflowIn = 'Down'\n\t\t\tif a[j] in type2 and b[j] in type1:\n\t\t\t\tcheck = 'NO'\n\t\t\t\tbreak\n\t\telse:\n\t\t\tif a[j] in type2 and b[j] in type2:\n\t\t\t\tflowIn = 'Up'\n\t\t\tif a[j] in type1 and b[j] in type2:\n\t\t\t\tcheck = 'NO'\n\t\t\t\tbreak\n\tif check == 'YES':\n\t\tif flowIn == 'Up':\n\t\t\tif a[n - 1] in type1 or b[n - 1] in type1:\n\t\t\t\tcheck = 'NO'\n\t\telif b[n - 1] in type2:\n\t\t\tcheck = 'NO'\n\tresult = result + check + '\\n'\nprint(result, end='')\n", "t = int(input())\nfor i in range(t):\n\tn = int(input())\n\tl1 = list(input())\n\tl2 = list(input())\n\ts = 0\n\tfor j in range(n):\n\t\tif (l1[j] == '4' or l1[j] == '3' or l1[j] == '5' or (l1[j] == '6')) and s == 0:\n\t\t\ts = 1\n\t\t\tif l2[j] == '1' or l2[j] == '2':\n\t\t\t\tprint('NO')\n\t\t\t\ts = 4\n\t\t\t\tbreak\n\t\telif (l2[j] == '4' or l2[j] == '3' or l2[j] == '5' or (l2[j] == '6')) and s == 1:\n\t\t\ts = 0\n\t\t\tif l1[j] == '1' or l1[j] == '2':\n\t\t\t\tprint('NO')\n\t\t\t\ts = 4\n\t\t\t\tbreak\n\tif s == 1:\n\t\tprint('YES')\n\telif s == 0:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\ts1 = list(input())\n\ts2 = list(input())\n\tx = False\n\tt = False\n\tchet = 0\n\twhile chet != n:\n\t\tif not x:\n\t\t\tif s1[chet] in '3456':\n\t\t\t\tif t:\n\t\t\t\t\tt = False\n\t\t\t\t\tchet += 1\n\t\t\t\telse:\n\t\t\t\t\tt = True\n\t\t\t\t\tx = True\n\t\t\telif t:\n\t\t\t\tx = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tchet += 1\n\t\tif x:\n\t\t\tif s2[chet] in '3456':\n\t\t\t\tif t:\n\t\t\t\t\tt = False\n\t\t\t\t\tchet += 1\n\t\t\t\telse:\n\t\t\t\t\tt = True\n\t\t\t\t\tx = False\n\t\t\telif t:\n\t\t\t\tx = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tchet += 1\n\tif x:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import array\nimport math\nimport os\nimport sys\n\ndef main():\n\tQ = read_int()\n\tfor _ in range(Q):\n\t\tN = read_int()\n\t\tA = inp()\n\t\tB = inp()\n\t\tprint('YES' if solve(N, A, B) else 'NO')\n\ndef solve(N, A, B):\n\tw = 0\n\tfor i in range(N):\n\t\ta = 1 if A[i] in ('1', '2') else 2\n\t\tb = 1 if B[i] in ('1', '2') else 2\n\t\tif w == 0:\n\t\t\tif a == 2 and b == 1:\n\t\t\t\treturn False\n\t\t\tif a == 2:\n\t\t\t\tw = 1\n\t\telse:\n\t\t\tif b == 2 and a == 1:\n\t\t\t\treturn False\n\t\t\tif b == 2:\n\t\t\t\tw = 0\n\treturn w == 1\nDEBUG = 'DEBUG' in os.environ\n\ndef inp():\n\treturn sys.stdin.readline().rstrip()\n\ndef read_int():\n\treturn int(inp())\n\ndef read_ints():\n\treturn [int(e) for e in inp().split()]\n\ndef dprint(*value, sep=' ', end='\\n'):\n\tif DEBUG:\n\t\tprint(*value, sep=sep, end=end)\nmain()\n", "import math as mt\nimport sys, string, bisect\ninput = sys.stdin.readline\nimport random\nfrom collections import deque, defaultdict\nL = lambda : list(map(int, input().split()))\nLs = lambda : list(input().split())\nM = lambda : map(int, input().split())\nI = lambda : int(input())\nd = defaultdict(int)\nt = I()\nfor _ in range(t):\n\tn = I()\n\ts = input().strip()\n\tp = input().strip()\n\tp = list(p)\n\ts = list(s)\n\tfor i in range(n):\n\t\tif s[i] == '2':\n\t\t\ts[i] = '1'\n\t\tif s[i] == '3' or s[i] == '4' or s[i] == '5' or (s[i] == '6'):\n\t\t\ts[i] = '2'\n\t\tif p[i] == '2':\n\t\t\tp[i] = '1'\n\t\tif p[i] == '3' or p[i] == '4' or p[i] == '5' or (p[i] == '6'):\n\t\t\tp[i] = '2'\n\tdone = 0\n\tf = 0\n\tfor i in range(n - 1):\n\t\tif f == 0 and s[i] != '1':\n\t\t\tif s[i] == p[i] and p[i] == '2':\n\t\t\t\tf = 1\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tdone = 1\n\t\t\t\tbreak\n\t\telif f == 1 and p[i] != '1':\n\t\t\tif s[i] == p[i] and p[i] == '2':\n\t\t\t\tf = 0\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tdone = 1\n\t\t\t\tbreak\n\tif not done:\n\t\tif f == 0:\n\t\t\tif s[n - 1] == p[n - 1] and p[n - 1] == '2':\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\tif f == 1:\n\t\t\tif p[n - 1] == '1':\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n", "import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools\ninf = 10 ** 20\neps = 1.0 / 10 ** 10\nmod = 10 ** 9 + 7\nmod2 = 998244353\ndd = [(-1, 0), (0, 1), (1, 0), (0, -1)]\nddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]\n\ndef LI():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef LLI():\n\treturn [list(map(int, l.split())) for l in sys.stdin.readlines()]\n\ndef LI_():\n\treturn [int(x) - 1 for x in sys.stdin.readline().split()]\n\ndef LF():\n\treturn [float(x) for x in sys.stdin.readline().split()]\n\ndef LS():\n\treturn sys.stdin.readline().split()\n\ndef I():\n\treturn int(sys.stdin.readline())\n\ndef F():\n\treturn float(sys.stdin.readline())\n\ndef S():\n\treturn input()\n\ndef pf(s):\n\treturn print(s, flush=True)\n\ndef pe(s):\n\treturn print(str(s), file=sys.stderr)\n\ndef JA(a, sep):\n\treturn sep.join(map(str, a))\n\ndef JAA(a, s, t):\n\treturn s.join((t.join(map(str, b)) for b in a))\n\ndef IF(c, t, f):\n\treturn t if c else f\n\ndef YES(c):\n\treturn IF(c, 'YES', 'NO')\n\ndef Yes(c):\n\treturn IF(c, 'Yes', 'No')\n\ndef main():\n\tt = I()\n\trr = []\n\tfor _ in range(t):\n\t\tn = I()\n\t\ts = [S() for _ in range(2)]\n\t\tt = [[int(c) for c in l] for l in s]\n\t\tok = 1\n\t\tk = 0\n\t\tfor i in range(n):\n\t\t\tif t[k][i] < 3:\n\t\t\t\tcontinue\n\t\t\tk ^= 1\n\t\t\tif t[k][i] < 3:\n\t\t\t\tok = 0\n\t\t\t\tbreak\n\t\trr.append(YES(ok and k == 1))\n\treturn JA(rr, '\\n')\nprint(main())\n", "import os, sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nfrom math import ceil\nmod = 10 ** 9 + 7\nfor _ in range(1):\n\tfor q in range(int(input())):\n\t\tn = int(input())\n\t\tmatrix = []\n\t\tmatrix.append(input())\n\t\tmatrix.append(input())\n\t\ti = 0\n\t\tj = 0\n\t\tat = 1\n\t\tfirst_time_1 = 0\n\t\tfirst_time_2 = 0\n\t\tfound = 0\n\t\twhile i <= 1 and j <= n - 1:\n\t\t\tif at == 1:\n\t\t\t\tif int(matrix[i][j]) <= 2:\n\t\t\t\t\tif first_time_1:\n\t\t\t\t\t\tbreak\n\t\t\t\t\telse:\n\t\t\t\t\t\tj += 1\n\t\t\t\telse:\n\t\t\t\t\tif first_time_1:\n\t\t\t\t\t\tj += 1\n\t\t\t\t\t\tfirst_time_1 = 0\n\t\t\t\t\telse:\n\t\t\t\t\t\ti += 1\n\t\t\t\t\t\tfirst_time_2 = 1\n\t\t\t\t\t\tat = 2\n\t\t\t\t\tif i == 1 and j == n - 1 and (int(matrix[i][j]) > 2):\n\t\t\t\t\t\tfound = 1\n\t\t\t\t\t\tbreak\n\t\t\telif int(matrix[i][j]) <= 2:\n\t\t\t\tif first_time_2:\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tif i == 1 and j == n - 1 and (int(matrix[i][j]) <= 2):\n\t\t\t\t\t\tfound = 1\n\t\t\t\t\t\tbreak\n\t\t\t\t\tj += 1\n\t\t\t\t\tif i == 1 and j == n - 1 and (int(matrix[i][j]) <= 2):\n\t\t\t\t\t\tfound = 1\n\t\t\t\t\t\tbreak\n\t\t\telif first_time_2:\n\t\t\t\tfirst_time_2 = 0\n\t\t\t\tj += 1\n\t\t\telse:\n\t\t\t\tfirst_time_1 = 1\n\t\t\t\ti -= 1\n\t\t\t\tat = 1\n\t\tif found:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "from typing import List\nTOP = 0\nBOTTOM = 1\nSTRAIGHT = 0\nCURVED = 1\n\ndef pipes(n: int, pipes_system: List[List[int]]) -> bool:\n\tswitch = []\n\tfor i in range(n):\n\t\tif determine_pipe(pipes_system[TOP][i]) == CURVED and determine_pipe(pipes_system[BOTTOM][i]) == CURVED:\n\t\t\tswitch.append(i)\n\tif len(switch) % 2 != 1:\n\t\treturn False\n\tcur_row = TOP\n\tswitch = set(switch)\n\tfor i in range(n):\n\t\tif i in switch:\n\t\t\tcur_row = BOTTOM if cur_row == TOP else TOP\n\t\telif determine_pipe(pipes_system[cur_row][i]) != STRAIGHT:\n\t\t\treturn False\n\treturn True\n\ndef determine_pipe(type: int) -> int:\n\tif 1 <= type <= 2:\n\t\treturn STRAIGHT\n\treturn CURVED\n\ndef test():\n\tassert pipes(7, [[2, 3, 2, 3, 2, 1, 6], [1, 6, 1, 5, 1, 2, 4]])\n\tassert pipes(1, [[3], [4]])\n\tassert pipes(2, [[1, 3], [2, 4]])\n\tassert not pipes(2, [[1, 2], [3, 4]])\n\tassert pipes(3, [[5, 3, 6], [3, 4, 5]])\n\tassert not pipes(2, [[4, 6], [5, 4]])\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tfirst_row = [int(c) for c in input()]\n\tsecond_row = [int(c) for c in input()]\n\tresult = pipes(n, [first_row, second_row])\n\tif result:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nimport math\n\ndef main():\n\tpass\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\nimport os\nimport sys\nfrom io import BytesIO, IOBase\n\ndef main():\n\tpass\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nfor xyz in range(0, int(input())):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tt1 = ['1', '2']\n\tt2 = ['3', '4', '5', '6']\n\ts = [s1, s2]\n\tcr = 0\n\tf = True\n\tfor i in range(0, n + 1):\n\t\tif i == n:\n\t\t\tif cr == 1:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\telif s[cr][i] in t2:\n\t\t\tif s[cr ^ 1][i] in t2:\n\t\t\t\tcr ^= 1\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n", "import io, sys, atexit, os\nimport math as ma\nfrom sys import exit\nfrom decimal import Decimal as dec\nfrom itertools import permutations\nfrom itertools import combinations\n\ndef li():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef num():\n\treturn map(int, sys.stdin.readline().split())\n\ndef nu():\n\treturn int(input())\n\ndef find_gcd(x, y):\n\twhile y:\n\t\t(x, y) = (y, x % y)\n\treturn x\n\ndef lcm(x, y):\n\tgg = find_gcd(x, y)\n\treturn x * y // gg\nmm = 1000000007\n\ndef solve():\n\tt = nu()\n\tfor tt in range(t):\n\t\tn = nu()\n\t\ta = [0] * 2\n\t\tfor i in range(2):\n\t\t\top = input()\n\t\t\ta[i] = [0] * n\n\t\t\tfor j in range(len(op)):\n\t\t\t\ta[i][j] = int(op[j])\n\t\ti = 0\n\t\trow = 0\n\t\tlast = 0\n\t\tfl = True\n\t\twhile i < n:\n\t\t\top = a[row][i]\n\t\t\tif row == 0 and last == 0:\n\t\t\t\tif a[row][i] == 1 or a[row][i] == 2:\n\t\t\t\t\ti += 1\n\t\t\t\t\tcontinue\n\t\t\t\tif op == 4 or op == 5 or op == 3 or (op == 6):\n\t\t\t\t\trow = 1\n\t\t\t\t\tcontinue\n\t\t\t\tfl = False\n\t\t\t\tbreak\n\t\t\tif row == 1 and last == 0:\n\t\t\t\tif op == 4 or op == 5 or op == 3 or (op == 6):\n\t\t\t\t\ti += 1\n\t\t\t\t\tlast = 1\n\t\t\t\t\tcontinue\n\t\t\t\tfl = False\n\t\t\t\tbreak\n\t\t\tif row == 1 and last == 1:\n\t\t\t\tif op == 1 or op == 2:\n\t\t\t\t\ti += 1\n\t\t\t\t\tcontinue\n\t\t\t\tif op == 4 or op == 5 or op == 3 or (op == 6):\n\t\t\t\t\trow = 0\n\t\t\t\t\tcontinue\n\t\t\t\tfl = False\n\t\t\t\tbreak\n\t\t\tif row == 0 and last == 1:\n\t\t\t\tif op == 4 or op == 5 or op == 3 or (op == 6):\n\t\t\t\t\tlast = 0\n\t\t\t\t\ti += 1\n\t\t\t\t\tcontinue\n\t\t\t\tfl = False\n\t\t\t\tbreak\n\t\tif fl:\n\t\t\tif row == 1 and last == 1:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\telse:\n\t\t\tprint('NO')\nsolve()\n", "for i in range(int(input())):\n\tn = int(input())\n\tA = list(input())\n\tB = list(input())\n\tj = 0\n\tk = 1\n\twhile True:\n\t\tif k == 1:\n\t\t\tif A[j] in ['1', '2']:\n\t\t\t\tj += 1\n\t\t\telif B[j] in ['3', '4', '5', '6']:\n\t\t\t\tk = 2\n\t\t\t\tj += 1\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\telif B[j] in ['1', '2']:\n\t\t\tj += 1\n\t\telif A[j] in ['3', '4', '5', '6']:\n\t\t\tk = 1\n\t\t\tj += 1\n\t\telse:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif j == n and k == 2:\n\t\t\tprint('YES')\n\t\t\tbreak\n\t\telif j == n and k == 1:\n\t\t\tprint('NO')\n\t\t\tbreak\n", "from sys import stdin\ninput = stdin.readline\nfor _ in range(int(input())):\n\tn = int(input())\n\tswap = [1, 0]\n\tarr = []\n\tt = 0\n\tfor i in range(2):\n\t\tarr.append(input())\n\tans = True\n\tfor i in range(n):\n\t\tif arr[t][i] != '1' and arr[t][i] != '2':\n\t\t\tt = swap[t]\n\t\t\tif arr[t][i] == '1' or arr[t][i] == '2':\n\t\t\t\tans = False\n\t\t\t\tbreak\n\tprint('YES' if ans and t == 1 else 'NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tm = [list(map(int, input().strip())) for _ in range(2)]\n\ti = 0\n\tfor j in range(n):\n\t\tif m[i][j] > 2:\n\t\t\tif m[i ^ 1][j] < 3:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ti ^= 1\n\telse:\n\t\tprint('YES' if i == 1 else 'NO')\n", "t = int(input())\nfor _ in range(t):\n\tn = int(input())\n\tpath = []\n\tfor i in range(2):\n\t\tpath.append([int(p) for p in list(input())])\n\tfor i in range(2):\n\t\tfor j in range(n):\n\t\t\tif path[i][j] <= 2:\n\t\t\t\tpath[i][j] = 0\n\t\t\telse:\n\t\t\t\tpath[i][j] = 1\n\t(i, j) = (0, 0)\n\tok = False\n\twhile True:\n\t\tif i == 1 and j == n:\n\t\t\tok = True\n\t\t\tbreak\n\t\telif i > 1 or i < 0 or j < 0 or (j >= n):\n\t\t\tok = False\n\t\t\tbreak\n\t\tpipe = path[i][j]\n\t\tif pipe == 0:\n\t\t\tj += 1\n\t\telif i == 0:\n\t\t\tif path[i + 1][j] == 1:\n\t\t\t\ti += 1\n\t\t\t\tj += 1\n\t\t\telse:\n\t\t\t\tbreak\n\t\telif path[i - 1][j] == 1:\n\t\t\ti -= 1\n\t\t\tj += 1\n\t\telse:\n\t\t\tbreak\n\tif ok:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for i in range(int(input())):\n\tn = int(input())\n\ta = []\n\ta.append(input())\n\ta.append(input())\n\tt = False\n\tx = 0\n\ty = 0\n\twhile True:\n\t\tif x == n:\n\t\t\tif y == 1:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif not t:\n\t\t\tif int(a[y][x]) < 3:\n\t\t\t\tx += 1\n\t\t\t\tcontinue\n\t\t\tt = True\n\t\t\tif y == 0:\n\t\t\t\ty = 1\n\t\t\telse:\n\t\t\t\ty = 0\n\t\telse:\n\t\t\tif int(a[y][x]) < 3:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\tt = False\n\t\t\tx += 1\n", "def is_bent(i):\n\tstraight = 0\n\tbent = 1\n\tif int(i) < 3:\n\t\treturn straight\n\telse:\n\t\treturn bent\n\ndef case():\n\tn = int(input())\n\tpipes = [input(), input()]\n\trow = 0\n\tfor pos in range(n):\n\t\tif is_bent(pipes[row][pos]):\n\t\t\trow ^= 1\n\t\t\tif not is_bent(pipes[row][pos]):\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\telse:\n\t\tif row:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\nfor i in range(int(input())):\n\tcase()\n", "def A():\n\timport math\n\tq = eval(input())\n\ttemp = []\n\tfor i in range(q):\n\t\tn = eval(input())\n\t\tarr = list(map(int, input().split()))\n\t\tprint(math.ceil(sum(arr) / float(n)))\n\ndef B():\n\tfrom collections import deque\n\t(n, k) = map(int, input().split())\n\tarr = list(map(int, input().split()))\n\tq = deque(maxlen=k)\n\tfor i in arr:\n\t\tif i not in q:\n\t\t\tq.append(i)\n\tprint(len(q))\n\tfor i in range(len(q)):\n\t\tprint(q[len(q) - i - 1], end=' ')\n\ndef C():\n\tq = eval(input())\n\tfor i in range(q):\n\t\tn = eval(input())\n\t\tarr = []\n\t\tarr.append(list(input()))\n\t\tarr.append(list(input()))\n\t\t(r, c) = (0, 0)\n\t\tup = 0\n\t\tcheck = 0\n\t\twhile (c, r) != (1, n - 1):\n\t\t\ttry:\n\t\t\t\tif arr[c][r] in '12' and up == 0:\n\t\t\t\t\tr += 1\n\t\t\t\t\tup = 0\n\t\t\t\telif arr[c][r] in '12' and up == 1:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tcheck = 1\n\t\t\t\t\tbreak\n\t\t\t\telif arr[c][r] in '3456' and up == 0:\n\t\t\t\t\tc = (c + 1) % 2\n\t\t\t\t\tup = 1\n\t\t\t\telif arr[c][r] in '3456' and up == 1:\n\t\t\t\t\tr += 1\n\t\t\t\t\tup = 0\n\t\t\texcept IndexError:\n\t\t\t\tprint('NO')\n\t\t\t\tcheck = 1\n\t\t\t\tbreak\n\t\tif check == 0:\n\t\t\tif arr[1][n - 1] in '12' and up == 0:\n\t\t\t\tprint('YES')\n\t\t\telif arr[1][n - 1] in '3456' and up == 1:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\nC()\n", "import sys\ninput = sys.stdin.readline\n\ndef getInt():\n\treturn int(input())\n\ndef getVars():\n\treturn map(int, input().split())\n\ndef getList():\n\treturn list(map(int, input().split()))\n\ndef getStr():\n\treturn input().strip()\nq = getInt()\nfor _ in range(q):\n\tn = getInt()\n\ta1 = getStr()\n\ta2 = getStr()\n\tb1 = a1\n\tb2 = a2\n\tpos = 1\n\tres = 'YES'\n\tfor i in range(n):\n\t\tif b1[i] >= '3':\n\t\t\tif b2[i] < '3':\n\t\t\t\tres = 'NO'\n\t\t\t\tbreak\n\t\t\tif pos == 1:\n\t\t\t\tpos = 2\n\t\t\t\tb1 = a2\n\t\t\t\tb2 = a1\n\t\t\telse:\n\t\t\t\tpos = 1\n\t\t\t\tb1 = a1\n\t\t\t\tb2 = a2\n\tif pos == 1:\n\t\tres = 'NO'\n\tprint(res)\n", "query = int(input())\nfor i in range(query):\n\tn = int(input())\n\trows = [list(input()), list(input())]\n\trowi = 0\n\tans = True\n\tfor k in range(n):\n\t\tif rows[rowi][k] >= '3':\n\t\t\tif rows[rowi - 1][k] <= '2':\n\t\t\t\tans = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\trowi = (rowi - 1) % 2\n\tif rowi == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES' if ans else 'NO')\n", "for q in range(int(input())):\n\tn = int(input())\n\ta = [list(map(int, input())), list(map(int, input()))]\n\ti = 0\n\tj = 0\n\tpos = 0\n\twhile i < n:\n\t\tif pos == 0 and j == 0:\n\t\t\tif a[j][i] in (1, 2):\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tpos = 1\n\t\t\t\tj += 1\n\t\telif pos == 0 and j == 1:\n\t\t\tif a[j][i] in (1, 2):\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tpos = 2\n\t\t\t\tj -= 1\n\t\telif pos == 1 and j == 0:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\telif pos == 1 and j == 1:\n\t\t\tif a[j][i] in (1, 2):\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tpos = 0\n\t\t\t\ti += 1\n\t\telif pos == 2 and j == 1:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\telif pos == 2 and j == 0:\n\t\t\tif a[j][i] in (1, 2):\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tpos = 0\n\t\t\t\ti += 1\n\telse:\n\t\tif j == 1 and pos == 0:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "query = int(input())\nfor q in range(query):\n\tn = int(input())\n\tr0 = input()\n\tr1 = input()\n\tr0 = r0 + 'N'\n\tr1 = r1 + 'G'\n\tpipes = [r0, r1]\n\tcurrent = pipes[0][0]\n\tdir = 0\n\ti = 0\n\tj = 0\n\twhile i < 2 and j < n:\n\t\tif dir == 0:\n\t\t\tif current == '1' or current == '2':\n\t\t\t\tj += 1\n\t\t\t\tcurrent = pipes[i][j]\n\t\t\telse:\n\t\t\t\tif i == 0:\n\t\t\t\t\ti += 1\n\t\t\t\t\tcurrent = pipes[i][j]\n\t\t\t\telse:\n\t\t\t\t\ti -= 1\n\t\t\t\t\tcurrent = pipes[i][j]\n\t\t\t\tdir = 1\n\t\telif current == '1' or current == '2':\n\t\t\tbreak\n\t\telse:\n\t\t\tj += 1\n\t\t\tcurrent = pipes[i][j]\n\t\t\tdir = 0\n\tif current == 'G':\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def main():\n\tQ = int(input())\n\tfor query in range(Q):\n\t\tN = int(input())\n\t\tA = [input() for i in range(2)]\n\t\t(h, w) = (0, 0)\n\t\tpre = -1\n\t\tpre_h = 0\n\t\tpre_d = 'w'\n\t\twhile h != 1 or w != N:\n\t\t\tcur = A[h][w]\n\t\t\tcur_h = h\n\t\t\tif cur == '1' or cur == '2':\n\t\t\t\tif pre_d != 'w':\n\t\t\t\t\tbreak\n\t\t\t\tw += 1\n\t\t\telif h == 0:\n\t\t\t\tif 3 <= int(pre) <= 6 and pre_h != cur_h:\n\t\t\t\t\tw += 1\n\t\t\t\t\tpre_d = 'w'\n\t\t\t\telse:\n\t\t\t\t\th += 1\n\t\t\t\t\tpre_d = 'h'\n\t\t\telif 3 <= int(pre) <= 6 and pre_h != cur_h:\n\t\t\t\tw += 1\n\t\t\t\tpre_d = 'w'\n\t\t\telse:\n\t\t\t\th -= 1\n\t\t\t\tpre_d = 'h'\n\t\t\tif h < 0 or 1 < h or w < 0 or (N - 1 < w):\n\t\t\t\tbreak\n\t\t\tpre = cur\n\t\t\tpre_h = cur_h\n\t\tif h == 1 and w == N:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\nmain()\n", "q = int(input())\nang = lambda x: True if x in ('3', '4', '5', '6') else False\nstt = lambda x: True if x in ('1', '2') else False\nr = []\nfor _ in range(q):\n\tn = int(input())\n\ta = []\n\ta.append(input())\n\ta.append(input())\n\tl = 0\n\tp = 0\n\twhile p < len(a[0]):\n\t\tif stt(a[l][p]):\n\t\t\tp += 1\n\t\t\tcontinue\n\t\tif ang(a[l][p]):\n\t\t\tif ang(a[1 - l][p]):\n\t\t\t\tl = 1 - l\n\t\t\telse:\n\t\t\t\tl = 0\n\t\t\t\tbreak\n\t\tp += 1\n\tif l == 1:\n\t\tr.append('YES')\n\telse:\n\t\tr.append('NO')\nprint('\\n'.join(r))\n", "testes = int(input())\nfor t in range(testes):\n\tcanos = int(input())\n\tlinha1 = str(input())\n\tlinha2 = str(input())\n\tatual = 1\n\tlivre = True\n\tfor k in range(canos):\n\t\tif atual == 1:\n\t\t\tchave = linha1[k]\n\t\t\tif int(chave) > 2:\n\t\t\t\tatual = 2\n\t\t\t\tif int(linha2[k]) <= 2:\n\t\t\t\t\tlivre = False\n\t\t\t\t\tbreak\n\t\telse:\n\t\t\tchave = linha2[k]\n\t\t\tif int(chave) > 2:\n\t\t\t\tatual = 1\n\t\t\t\tif int(linha1[k]) <= 2:\n\t\t\t\t\tlivre = False\n\t\t\t\t\tbreak\n\tif livre and atual == 2:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\nsys.setrecursionlimit(10000000)\n\ndef input():\n\treturn sys.stdin.readline()[:-1]\nfrom bisect import *\nfrom collections import *\nfrom heapq import *\nimport itertools\nimport math\nINF = 10 ** 9\nMOD = 10 ** 9 + 7\nq = int(input())\nfor j in range(q):\n\tn = int(input())\n\ta = [input() for i in range(2)]\n\t(i, h, flg) = (0, 0, 1)\n\twhile i < n:\n\t\tif int(a[h][i]) < 3:\n\t\t\ti += 1\n\t\telse:\n\t\t\th ^= 1\n\t\t\tif int(a[h][i]) < 3:\n\t\t\t\tflg = 0\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ti += 1\n\tif flg and h == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "from sys import stdin\n\ndef solve(n, p):\n\tRIGHT = 1\n\tLEFT = 2\n\tDOWN = 3\n\tUP = 4\n\tc = RIGHT\n\t(i, j) = (0, 0)\n\tans = 'YES'\n\twhile True:\n\t\tif j == n:\n\t\t\tif i != 1:\n\t\t\t\tans = 'NO'\n\t\t\tbreak\n\t\th = p[i][j]\n\t\tif h == 1 or h == 2:\n\t\t\tif c == RIGHT:\n\t\t\t\tj += 1\n\t\t\t\tcontinue\n\t\t\tans = 'NO'\n\t\t\tbreak\n\t\telif c == DOWN or c == UP:\n\t\t\tc = RIGHT\n\t\t\tj += 1\n\t\telif c == RIGHT:\n\t\t\tif i == 0:\n\t\t\t\tc = DOWN\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tc = UP\n\t\t\t\ti -= 1\n\t\telse:\n\t\t\tans = 'NO'\n\t\t\tbreak\n\tprint(ans)\n\ndef main():\n\tinp = stdin.readline\n\tfor i in range(int(inp())):\n\t\tn = int(inp())\n\t\th1 = list(inp().strip())\n\t\th2 = list(inp().strip())\n\t\tm = list(map(int, h1))\n\t\tk = list(map(int, h2))\n\t\tp = [m, k]\n\t\tsolve(n, p)\nmain()\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ta = list()\n\ttemp = list(input())\n\ta.append(temp)\n\ttemp = list(input())\n\ta.append(temp)\n\tcur = 0\n\tdone = False\n\tfor i in range(n):\n\t\tif a[cur][i] not in ['1', '2']:\n\t\t\tcur = (cur + 1) % 2\n\t\t\tif a[cur][i] in ['1', '2']:\n\t\t\t\tprint('NO')\n\t\t\t\tdone = True\n\t\t\t\tbreak\n\t\tif done:\n\t\t\tbreak\n\tif done:\n\t\tcontinue\n\tif cur == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tpipes = [input() for _ in range(2)]\n\t(row, pos) = (0, 0)\n\tfor pow in range(n):\n\t\tif pipes[row][pos] > '2':\n\t\t\trow = 1 - row\n\t\t\tif pipes[row][pos] < '3':\n\t\t\t\tbreak\n\t\tpos += 1\n\tprint('YES' if row == 1 and pos == n else 'NO')\n", "q = int(input())\nfor i in range(q):\n\tj = int(input())\n\ts = []\n\ts.append(input())\n\ts.append(input())\n\trow = 0\n\tend = False\n\tfor k in range(j):\n\t\tif s[row][k] >= '3':\n\t\t\tif s[row ^ 1][k] < '3':\n\t\t\t\tbreak\n\t\t\trow = row ^ 1\n\telse:\n\t\tend = True\n\tif end and row == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "Q = int(input())\nfor q in range(Q):\n\tn = int(input())\n\tarr1 = [int(i) for i in input()]\n\tarr2 = [int(i) for i in input()]\n\terror = False\n\tnow_x = 0\n\tnow_y = 0\n\twas_x = -1\n\twhile now_x < n:\n\t\tif now_y == 0:\n\t\t\tnow = arr1[now_x]\n\t\telse:\n\t\t\tnow = arr2[now_x]\n\t\tif True:\n\t\t\tif now in {1, 2}:\n\t\t\t\tif was_x == now_x:\n\t\t\t\t\terror = True\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\t(was_x, now_x) = (now_x, now_x + 1)\n\t\t\telif was_x == now_x:\n\t\t\t\twas_x = now_x\n\t\t\t\tnow_x += 1\n\t\t\telse:\n\t\t\t\twas_x = now_x\n\t\t\t\tnow_y = (now_y + 1) % 2\n\tif now_y == 0:\n\t\terror = True\n\tif error:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "def Pipes():\n\tfor query in range(int(input())):\n\t\tn = int(input())\n\t\t(Row1, Row2) = (input(), input())\n\t\t(meRow1, objRow1, objCol, answer) = (True, True, 0, 'YES')\n\t\tstraights = set(['1', '2'])\n\t\twhile True:\n\t\t\tif meRow1:\n\t\t\t\tif objRow1:\n\t\t\t\t\tif Row1[objCol] in straights:\n\t\t\t\t\t\tobjCol += 1\n\t\t\t\t\t\tif objCol == n:\n\t\t\t\t\t\t\tif objRow1:\n\t\t\t\t\t\t\t\tanswer = 'NO'\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\telse:\n\t\t\t\t\t\tobjRow1 = False\n\t\t\t\telif Row2[objCol] in straights:\n\t\t\t\t\tanswer = 'NO'\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tmeRow1 = False\n\t\t\t\t\tobjCol += 1\n\t\t\t\t\tif objCol == n:\n\t\t\t\t\t\tif objRow1:\n\t\t\t\t\t\t\tanswer = 'NO'\n\t\t\t\t\t\tbreak\n\t\t\telif objRow1:\n\t\t\t\tif Row1[objCol] in straights:\n\t\t\t\t\tanswer = 'NO'\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tmeRow1 = True\n\t\t\t\t\tobjCol += 1\n\t\t\t\t\tif objCol == n:\n\t\t\t\t\t\tif objRow1:\n\t\t\t\t\t\t\tanswer = 'NO'\n\t\t\t\t\t\tbreak\n\t\t\telif Row2[objCol] in straights:\n\t\t\t\tobjCol += 1\n\t\t\t\tif objCol == n:\n\t\t\t\t\tif objRow1:\n\t\t\t\t\t\tanswer = 'NO'\n\t\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tobjRow1 = True\n\t\tprint(answer)\nPipes()\n", "for _ in range(int(input())):\n\t(n, m) = (int(input()), [input(), input()])\n\tx = 0\n\tfor i in range(n):\n\t\tif int(m[x][i]) > 2:\n\t\t\tx ^= 1\n\t\t\tif int(m[x][i]) <= 2:\n\t\t\t\tx = 0\n\t\t\t\tbreak\n\tprint('NO') if x == 0 else print('YES')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tpipes = [[int(i) for i in input().strip()] for i in range(2)]\n\t(currenti, currentj) = (0, 0)\n\tmaxIters = 0\n\twhile True:\n\t\tif pipes[currenti][currentj] in [1, 2]:\n\t\t\tcurrentj += 1\n\t\telif pipes[currenti][currentj] in [3, 4, 5, 6, 7] and pipes[(currenti + 1) % 2][currentj] in [3, 4, 5, 6, 7]:\n\t\t\tcurrenti += 1\n\t\t\tcurrenti %= 2\n\t\t\tcurrentj += 1\n\t\tmaxIters += 1\n\t\tif currentj == n or maxIters > 2 * n + 1:\n\t\t\tbreak\n\tif currenti == 1 and currentj == n:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "t = int(input())\nwhile t:\n\tans = 0\n\tn = int(input())\n\ta = []\n\ta.append(str(input()))\n\ta.append(str(input()))\n\t(i, rch, cr) = (0, 0, 0)\n\twhile i < n:\n\t\tif a[cr][i] == '1' or a[cr][i] == '2':\n\t\t\tif rch == 0:\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tbreak\n\t\telif rch == 0:\n\t\t\trch = 1\n\t\t\tif cr == 0:\n\t\t\t\tcr = 1\n\t\t\telse:\n\t\t\t\tcr = 0\n\t\telse:\n\t\t\trch = 0\n\t\t\ti += 1\n\tif i == n and cr == 1:\n\t\tprint('YES')\n\t\tans = 1\n\tif ans == 0:\n\t\tprint('NO')\n\tt -= 1\n", "N = int(input())\nfor i in range(N):\n\tn = int(input())\n\tstr1 = list(input())\n\tstr2 = list(input())\n\tx = False\n\tt = False\n\tchet = 0\n\twhile chet != n:\n\t\tif not x:\n\t\t\tif str1[chet] in '3456':\n\t\t\t\tif t:\n\t\t\t\t\tt = False\n\t\t\t\t\tchet += 1\n\t\t\t\telse:\n\t\t\t\t\tt = True\n\t\t\t\t\tx = True\n\t\t\telif t:\n\t\t\t\tx = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tchet += 1\n\t\tif x:\n\t\t\tif str2[chet] in '3456':\n\t\t\t\tif t:\n\t\t\t\t\tt = False\n\t\t\t\t\tchet += 1\n\t\t\t\telse:\n\t\t\t\t\tt = True\n\t\t\t\t\tx = False\n\t\t\telif t:\n\t\t\t\tx = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tchet += 1\n\tif x:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor i in range(q):\n\tinput()\n\ts = zip(input(), input())\n\tp = ('3', '4', '5', '6')\n\tr = 0\n\tfor x in s:\n\t\tif x[r] in ('1', '2'):\n\t\t\tcontinue\n\t\telif x[0] in p and x[1] in p:\n\t\t\tr = 1 - r\n\t\telse:\n\t\t\tr -= 1\n\t\t\tbreak\n\tif r == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def test():\n\ti = j = 0\n\tfrom_left = True\n\twhile i < n:\n\t\tpipe = G[j][i]\n\t\tif from_left:\n\t\t\tif pipe < 3:\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tj = 1 - j\n\t\t\t\tfrom_left = False\n\t\telif pipe < 3:\n\t\t\treturn False\n\t\telse:\n\t\t\ti += 1\n\t\t\tfrom_left = True\n\treturn j == 1\nfor _ in range(int(input())):\n\tn = int(input())\n\tG = [list(map(int, input())) for _ in '**']\n\tprint(['NO', 'YES'][test()])\n", "Q = int(input())\nfor _ in range(Q):\n\tN = int(input())\n\tP = [None, None]\n\t(*P[0],) = map(int, input())\n\t(*P[1],) = map(int, input())\n\tok = 1\n\tc = 0\n\tfor i in range(N):\n\t\tif P[c][i] <= 2:\n\t\t\tcontinue\n\t\tif P[c ^ 1][i] <= 2:\n\t\t\tok = 0\n\t\t\tbreak\n\t\tc ^= 1\n\tif c == 0:\n\t\tok = 0\n\tprint('YES' if ok else 'NO')\n", "q = int(input())\nfor i in range(q):\n\tinput()\n\tc = zip(input(), input())\n\tpos = 0\n\tfor i in c:\n\t\tif i[pos] in ('1', '2'):\n\t\t\tcontinue\n\t\telif i[0] in ('3', '4', '5', '6') and i[1] in ('3', '4', '5', '6'):\n\t\t\tpos = 1 - pos\n\t\telse:\n\t\t\tpos = -1\n\t\t\tbreak\n\tif pos == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for _ in range(int(input())):\n\tn = int(input())\n\tpath = []\n\tnum = list(input())\n\tpath.append(list(map(int, num)))\n\tnum = list(input())\n\tpath.append(list(map(int, num)))\n\tp = 0\n\tlevel = 0\n\tfor i in range(n):\n\t\tif path[level][i] == 1 or path[level][i] == 2:\n\t\t\tpass\n\t\telif path[level ^ 1][i] == 1 or path[level ^ 1][i] == 2:\n\t\t\tp = 1\n\t\t\tbreak\n\t\telse:\n\t\t\tlevel ^= 1\n\tif p:\n\t\tprint('NO')\n\telif level:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "cases = int(input())\nfor i in range(cases):\n\tsize = int(input())\n\tval = []\n\tval = [[int(x) for x in list(input())], [int(x) for x in list(input())]]\n\tdown = 0\n\tno = 0\n\tfor i in range(size):\n\t\tif val[down][i] > 2 and val[down ^ 1][i] <= 2:\n\t\t\tno = 1\n\t\t\tbreak\n\t\tif val[down][i] > 2:\n\t\t\tdown ^= 1\n\tprint('NO' if no == 1 or down == 0 else 'YES')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tx = 1\n\tx1 = 1\n\ty = 0\n\twhile True:\n\t\tif y == n - 1:\n\t\t\tif x == 1:\n\t\t\t\tif (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')):\n\t\t\t\t\tprint('YES')\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\telif s2[y] == '1' or s2[y] == '2':\n\t\t\t\tprint('YES')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\tif x == 1:\n\t\t\tif s1[y] == '1' or s1[y] == '2':\n\t\t\t\tif x1 == 1:\n\t\t\t\t\ty += 1\n\t\t\t\telse:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\telif x1 == 1:\n\t\t\t\tx = 2\n\t\t\telse:\n\t\t\t\ty += 1\n\t\t\t\tx1 = 1\n\t\telif s2[y] == '1' or s2[y] == '2':\n\t\t\tif x1 == 2:\n\t\t\t\ty += 1\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\telif x1 == 2:\n\t\t\tx = 1\n\t\telse:\n\t\t\ty += 1\n\t\t\tx1 = 2\n", "x = int(input())\nfor _ in range(x):\n\ts = int(input())\n\ta0 = input()\n\ta1 = input()\n\tz = [a0, a1]\n\tcurr = 0\n\tok = True\n\tfor i in range(s):\n\t\tif z[curr][i] in ['1', '2']:\n\t\t\tpass\n\t\telif z[1 - curr][i] in ['3', '4', '5', '6']:\n\t\t\tcurr = 1 - curr\n\t\telse:\n\t\t\tok = False\n\t\t\tbreak\n\tif curr == 0:\n\t\tok = False\n\tif ok:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def process(A, B):\n\tn = len(A)\n\tM = [[], []]\n\tfor i in range(n):\n\t\tif A[i] <= '2':\n\t\t\tM[0].append(0)\n\t\telse:\n\t\t\tM[0].append(1)\n\t\tif B[i] <= '2':\n\t\t\tM[1].append(0)\n\t\telse:\n\t\t\tM[1].append(1)\n\tpath = [[0, 0]]\n\twhile True:\n\t\t(x, y) = path[-1]\n\t\tif len(path) > 1:\n\t\t\t(x0, y0) = path[-2]\n\t\tif M[x][y] == 0:\n\t\t\tif len(path) > 1 and x0 != x:\n\t\t\t\treturn 'NO'\n\t\t\t(x2, y2) = (x, y + 1)\n\t\telif x == 0 and y == 0:\n\t\t\t(x2, y2) = (x + 1, y)\n\t\telse:\n\t\t\t(x0, y0) = path[-2]\n\t\t\tif y0 + 1 == y:\n\t\t\t\t(x2, y2) = (1 - x, y)\n\t\t\telse:\n\t\t\t\t(x2, y2) = (x, y + 1)\n\t\tif (x2, y2) == (1, n):\n\t\t\treturn 'YES'\n\t\tif not (0 <= x2 <= 1 and 0 <= y2 <= n - 1):\n\t\t\treturn 'NO'\n\t\t(x, y) = (x2, y2)\n\t\tpath.append([x, y])\nq = int(input())\nfor i in range(q):\n\tn = int(input())\n\tA = input()\n\tB = input()\n\tprint(process(A, B))\n", "x = int(input())\nfor __ in range(x):\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tz = 'a'\n\tf = 0\n\tfor i in range(n):\n\t\tif z == 'a':\n\t\t\tif a[i] == '3' or a[i] == '4' or a[i] == '5' or (a[i] == '6'):\n\t\t\t\tif b[i] == '3' or b[i] == '4' or b[i] == '5' or (b[i] == '6'):\n\t\t\t\t\tz = 'b'\n\t\t\t\telse:\n\t\t\t\t\tf = 1\n\t\t\t\t\tbreak\n\t\telif z == 'b':\n\t\t\tif b[i] == '3' or b[i] == '4' or b[i] == '5' or (b[i] == '6'):\n\t\t\t\tif a[i] == '3' or a[i] == '4' or a[i] == '5' or (a[i] == '6'):\n\t\t\t\t\tz = 'a'\n\t\t\t\telse:\n\t\t\t\t\tf = 1\n\t\t\t\t\tbreak\n\tif z == 'b' and f == 0:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\nimport collections\nq = int(sys.stdin.readline())\n\ndef bfs():\n\tdy = [0, 1, -1]\n\tdx = [1, 0, 0]\n\t_q = collections.deque()\n\t_q.append([0, 0, 1, 0])\n\tvisited[0][0] = 1\n\twhile _q:\n\t\t(y, x, prev, prev_y) = _q.popleft()\n\t\tif y == 1 and x == n:\n\t\t\tbreak\n\t\tfor i in range(3):\n\t\t\tay = y + dy[i]\n\t\t\tax = x + dx[i]\n\t\t\tif ay >= 0 and ay < 2 and (ax >= 0) and (ax < n + 2):\n\t\t\t\tif arr[y][x] == 1:\n\t\t\t\t\tif ay == y and ax == x + 1 and (visited[ay][ax] == 0) and (arr[ay][ax] != 0):\n\t\t\t\t\t\tvisited[ay][ax] = visited[y][x] + 1\n\t\t\t\t\t\t_q.append([ay, ax, 1, prev_y])\n\t\t\t\telif arr[y][x] == 3:\n\t\t\t\t\tif prev == 1:\n\t\t\t\t\t\tif y == 0:\n\t\t\t\t\t\t\tif ay == y + 1 and ax == x and (visited[ay][ax] == 0) and (arr[ay][ax] != 0) and (arr[ay][ax] != 1):\n\t\t\t\t\t\t\t\tvisited[ay][ax] = visited[y][x] + 1\n\t\t\t\t\t\t\t\t_q.append([ay, ax, 3, y])\n\t\t\t\t\t\telif y == 1:\n\t\t\t\t\t\t\tif ay == y - 1 and ax == x and (visited[ay][ax] == 0) and (arr[ay][ax] != 0) and (arr[ay][ax] != 1):\n\t\t\t\t\t\t\t\tvisited[ay][ax] = visited[y][x] + 1\n\t\t\t\t\t\t\t\t_q.append([ay, ax, 3, y])\n\t\t\t\t\telif prev == 3:\n\t\t\t\t\t\tif y == prev_y:\n\t\t\t\t\t\t\tif y == 0:\n\t\t\t\t\t\t\t\tif ay == y + 1 and ax == x and (visited[ay][ax] == 0) and (arr[ay][ax] != 0) and (arr[ay][ax] != 1):\n\t\t\t\t\t\t\t\t\tvisited[ay][ax] = visited[y][x] + 1\n\t\t\t\t\t\t\t\t\t_q.append([ay, ax, 3, y])\n\t\t\t\t\t\t\telif y == 1:\n\t\t\t\t\t\t\t\tif ay == y - 1 and ax == x and (visited[ay][ax] == 0) and (arr[ay][ax] != 0) and (arr[ay][ax] != 1):\n\t\t\t\t\t\t\t\t\tvisited[ay][ax] = visited[y][x] + 1\n\t\t\t\t\t\t\t\t\t_q.append([ay, ax, 3, y])\n\t\t\t\t\t\telif y != prev_y:\n\t\t\t\t\t\t\tif ay == y and ax == x + 1 and (visited[ay][ax] == 0) and (arr[ay][ax] != 0):\n\t\t\t\t\t\t\t\tvisited[ay][ax] = visited[y][x] + 1\n\t\t\t\t\t\t\t\t_q.append([ay, ax, 3, y])\nfor _ in range(q):\n\tn = int(sys.stdin.readline())\n\tarr = []\n\ttemp1 = list(sys.stdin.readline().strip()) + [0]\n\tfor i in range(n):\n\t\tif temp1[i] == '2' or temp1[i] == '1':\n\t\t\ttemp1[i] = 1\n\t\tif temp1[i] == '3' or temp1[i] == '4' or temp1[i] == '5' or (temp1[i] == '6'):\n\t\t\ttemp1[i] = 3\n\tarr.append(temp1)\n\ttemp2 = list(sys.stdin.readline().strip()) + [1]\n\tfor j in range(n):\n\t\tif temp2[j] == '2' or temp2[j] == '1':\n\t\t\ttemp2[j] = 1\n\t\tif temp2[j] == '3' or temp2[j] == '4' or temp2[j] == '5' or (temp2[j] == '6'):\n\t\t\ttemp2[j] = 3\n\tarr.append(temp2)\n\tvisited = [[0] * (n + 1) for _ in range(2)]\n\tbfs()\n\tif visited[1][n] != 0:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def is_water_flow_possible(n, top_pipe, bottom_pipe):\n\tin_flow = [0 for i in range(n)]\n\tout_flow = [0 for i in range(n)]\n\tin_flow[0] = 1\n\tfor i in range(n):\n\t\tout_flow[i] = 0\n\t\tis_dbl_curve = is_double_curve(top_pipe[i], bottom_pipe[i])\n\t\tif is_bottom_inflow(in_flow[i]) and is_dbl_curve or (is_top_inflow(in_flow[i]) and is_straight(top_pipe[i])):\n\t\t\tout_flow[i] += 1\n\t\tif is_top_inflow(in_flow[i]) and is_dbl_curve or (is_bottom_inflow(in_flow[i]) and is_straight(bottom_pipe[i])):\n\t\t\tout_flow[i] += 2\n\t\tif i < n - 1:\n\t\t\tin_flow[i + 1] = out_flow[i]\n\treturn is_bottom_inflow(out_flow[n - 1])\n\ndef is_double_curve(flow1, flow2):\n\treturn is_curve(flow1) and is_curve(flow2)\n\ndef is_curve(pipe_num):\n\treturn pipe_num in ['3', '4', '5', '6']\n\ndef is_straight(pipe_num):\n\treturn pipe_num in ['1', '2']\n\ndef is_top_inflow(flow):\n\treturn flow in [1, 3]\n\ndef is_bottom_inflow(flow):\n\treturn flow in [2, 3]\n\ndef solve():\n\tqueries_number = int(input())\n\tfor k in range(queries_number):\n\t\tn = int(input())\n\t\trow1 = input()\n\t\trow2 = input()\n\t\tprint('YES' if is_water_flow_possible(n, str(row1), str(row2)) else 'NO')\nsolve()\n", "def isValid(i, j, N):\n\tif i < 0 or i > 1 or j < 0 or (j > N - 1):\n\t\treturn False\n\treturn True\nfor _ in range(int(input())):\n\tN = int(input())\n\tTop = input()\n\tBottom = input()\n\tI = 0\n\tJ = 0\n\tif Top[0] <= '2':\n\t\ti = 0\n\t\tj = 1\n\telse:\n\t\ti = 1\n\t\tj = 0\n\tflag = 0\n\twhile True:\n\t\tif i == 0 and j == N:\n\t\t\tflag = 1\n\t\t\tbreak\n\t\tif i == 1 and j == N:\n\t\t\tbreak\n\t\tif i == 0:\n\t\t\tif Top[j] <= '2':\n\t\t\t\tif I == 0:\n\t\t\t\t\tj += 1\n\t\t\t\t\tJ += 1\n\t\t\t\telse:\n\t\t\t\t\tflag = 1\n\t\t\t\t\tbreak\n\t\t\telif I == 0:\n\t\t\t\ti += 1\n\t\t\t\tJ += 1\n\t\t\telse:\n\t\t\t\tj += 1\n\t\t\t\tI -= 1\n\t\telif Bottom[j] <= '2':\n\t\t\tif I == 1:\n\t\t\t\tj += 1\n\t\t\t\tJ += 1\n\t\t\telse:\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\t\telif I == 1:\n\t\t\ti -= 1\n\t\t\tJ += 1\n\t\telse:\n\t\t\tj += 1\n\t\t\tI += 1\n\tif flag:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "t = int(input())\nfor _ in range(t):\n\tn = int(input())\n\ta = input()\n\ta = list(a)\n\ta = [int(j) for j in a]\n\tb = input()\n\tb = list(b)\n\tb = [int(j) for j in b]\n\tans = 0\n\tansno = 0\n\tfor i in range(n):\n\t\tif ans % 2 == 0:\n\t\t\tif (a[i] == 3 or a[i] == 4 or a[i] == 5 or (a[i] == 6)) and (b[i] == 1 or b[i] == 2):\n\t\t\t\tansno += 1\n\t\t\telif (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)):\n\t\t\t\tans += 1\n\t\telif (b[i] == 3 or b[i] == 4 or b[i] == 5 or (b[i] == 6)) and (a[i] == 1 or a[i] == 2):\n\t\t\tansno += 1\n\t\telif (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)):\n\t\t\tans += 1\n\tif ansno == 0 and ans % 2 == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "from math import *\nt = int(input())\nfor y in range(t):\n\tn = int(input())\n\tl1 = list(input())\n\tl2 = list(input())\n\ts = 0\n\tfor i in range(n):\n\t\tif s == 0:\n\t\t\tif l1[i] == '1' or l1[i] == '2':\n\t\t\t\ts = 0\n\t\t\telif l2[i] == '3' or l2[i] == '4' or l2[i] == '5' or (l2[i] == '6'):\n\t\t\t\ts = 1\n\t\t\telse:\n\t\t\t\ts = 0\n\t\t\t\tbreak\n\t\telif l2[i] == '1' or l2[i] == '2':\n\t\t\ts = 1\n\t\telif l1[i] == '3' or l1[i] == '4' or l1[i] == '5' or (l1[i] == '6'):\n\t\t\ts = 0\n\t\telse:\n\t\t\ts = 0\n\t\t\tbreak\n\tif s == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\ninput = sys.stdin.readline\n\ndef solve(n, f, s):\n\tdirections = [f, s]\n\treach = [[False] * n for _ in range(2)]\n\treach[0][0] = True\n\t(row, col) = (0, 0)\n\tfor _ in range(n):\n\t\tif directions[row][col] in '12':\n\t\t\tcol += 1\n\t\telif directions[row][col] in '3456':\n\t\t\tif directions[(row + 1) % 2][col] in '3456':\n\t\t\t\trow += 1\n\t\t\t\trow %= 2\n\t\t\t\tcol += 1\n\t\t\telse:\n\t\t\t\treturn False\n\treturn row == 1\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tf = input().rstrip()\n\ts = input().rstrip()\n\tif solve(n, f, s):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "entrada = int(input())\nfor k in range(entrada):\n\tn = int(input())\n\tstring1 = input()\n\tstring2 = input()\n\tflag = True\n\ti = 0\n\tflagstring = 1\n\tflagTroca = False\n\twhile i < n:\n\t\tif flagstring == 1:\n\t\t\tif string1[i] == '1' or string1[i] == '2':\n\t\t\t\ti += 1\n\t\t\telif string2[i] != '3' and string2[i] != '4' and (string2[i] != '5') and (string2[i] != '6'):\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telif flagTroca:\n\t\t\t\ti += 1\n\t\t\t\tflagTroca = False\n\t\t\telse:\n\t\t\t\tflagstring = 2\n\t\t\t\tflagTroca = True\n\t\telif string2[i] == '1' or string2[i] == '2':\n\t\t\ti += 1\n\t\telif string1[i] != '3' and string1[i] != '4' and (string1[i] != '5') and (string1[i] != '6'):\n\t\t\tflag = False\n\t\t\tbreak\n\t\telif flagTroca:\n\t\t\ti += 1\n\t\t\tflagTroca = False\n\t\telse:\n\t\t\tflagstring = 1\n\t\t\tflagTroca = True\n\tif not flag:\n\t\tprint('NO')\n\telif flagstring == 1:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "import math\nimport sys\nfrom collections import defaultdict, Counter, deque\nimport bisect\ninput = iter(sys.stdin.buffer.read().decode().splitlines()).__next__\nilele = lambda : map(int, input().split())\nalele = lambda : list(map(int, input().split()))\n\ndef list2d(a, b, c):\n\treturn [[c] * b for i in range(a)]\nfrom itertools import accumulate, groupby\ndp = []\nfor _ in range(int(input())):\n\tN = int(input())\n\tA = input()\n\tB = input()\n\tpos = 0\n\tf = 0\n\tfor i in range(-1, N - 1):\n\t\tif pos == 0:\n\t\t\tif A[i + 1] == '1' or A[i + 1] == '2':\n\t\t\t\tpos = 0\n\t\t\telif B[i + 1] != '1' and B[i + 1] != '2':\n\t\t\t\tpos = 1\n\t\t\telse:\n\t\t\t\tf = 1\n\t\t\t\tbreak\n\t\telif B[i + 1] == '1' or B[i + 1] == '2':\n\t\t\tpos = 1\n\t\telif A[i + 1] != '1' and A[i + 1] != '2':\n\t\t\tpos = 0\n\t\telse:\n\t\t\tf = 1\n\t\t\tbreak\n\tif f == 1 or pos == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "elem = int(input())\nfor x in range(elem):\n\telem2 = int(input())\n\tone = input()\n\ttwo = input()\n\tcurr = 0\n\tcheck = 0\n\tfor y in range(elem2):\n\t\tif curr == 0:\n\t\t\tif one[y] == '1' or one[y] == '2':\n\t\t\t\tcontinue\n\t\t\telif two[y] == '3' or two[y] == '4' or two[y] == '5' or (two[y] == '6'):\n\t\t\t\tcurr = 1\n\t\t\telse:\n\t\t\t\tcheck = 1\n\t\t\t\tbreak\n\t\telif two[y] == '1' or two[y] == '2':\n\t\t\tcontinue\n\t\telif one[y] == '3' or one[y] == '4' or one[y] == '5' or (one[y] == '6'):\n\t\t\tcurr = 0\n\t\telse:\n\t\t\tcheck = 1\n\t\t\tbreak\n\tif check == 1:\n\t\tprint('NO')\n\telif curr == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "a = int(input())\nfor i in range(a):\n\ts = int(input())\n\ta1 = input()\n\ta2 = input()\n\tk1 = []\n\tk2 = []\n\tfor i in range(len(a1)):\n\t\tk1.append(str(a1[i]))\n\t\tk2.append(str(a2[i]))\n\tfor i in range(len(a1)):\n\t\tif a1[i] == '1' or a1[i] == '2':\n\t\t\tk1[i] = 'L'\n\t\telse:\n\t\t\tk1[i] = 'LD'\n\t\tif a2[i] == '1' or a2[i] == '2':\n\t\t\tk2[i] = 'L'\n\t\telse:\n\t\t\tk2[i] = 'LU'\n\tcell = [0, 0]\n\tflow = 0\n\tflag = 0\n\twhile cell[0] < s:\n\t\tr = cell[0]\n\t\ty = cell[1]\n\t\tif cell[1] == 0:\n\t\t\tif k1[r] == 'L' and flow == 0:\n\t\t\t\tcell[0] += 1\n\t\t\t\tcontinue\n\t\t\telif flow == 1 and k1[r] == 'LD':\n\t\t\t\tcell[0] += 1\n\t\t\t\tflow = 0\n\t\t\t\tcell[1] = 0\n\t\t\t\tcontinue\n\t\t\telif flow == 0 and k1[r] == 'LD':\n\t\t\t\tflow = 2\n\t\t\t\tcell[1] = 1\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\t\tif cell[1] == 1:\n\t\t\tif flow == 0 and k2[r] == 'L':\n\t\t\t\tcell[0] += 1\n\t\t\t\tcontinue\n\t\t\telif flow == 0 and k2[r] == 'LU':\n\t\t\t\tcell[1] = 0\n\t\t\t\tflow = 1\n\t\t\t\tcontinue\n\t\t\telif flow == 2 and k2[r] == 'LU':\n\t\t\t\tflow = 0\n\t\t\t\tcell[0] += 1\n\t\t\t\tcell[1] = 1\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tflag = 1\n\t\t\t\tbreak\n\tif flow == 0 and cell[1] == 1 and (flag == 0):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ts1 = '2'.join('2'.join('2'.join('2'.join('1'.join(input().split('2')).split('3')).split('4')).split('5')).split('6'))\n\ts2 = '2'.join('2'.join('2'.join('2'.join('1'.join(input().split('2')).split('3')).split('4')).split('5')).split('6'))\n\ta = 1\n\tfor j in range(n):\n\t\tif a == 1:\n\t\t\tif s1[j] == s2[j] == '2':\n\t\t\t\ta = 2\n\t\t\telif s1[j] == '2' and s2[j] == '1':\n\t\t\t\ta = 0\n\t\telif s2[j] == s1[j] == '2':\n\t\t\ta = 1\n\t\telif s2[j] == '2' and s1[j] == '1':\n\t\t\ta = 0\n\t\tif a == 0:\n\t\t\tbreak\n\tif a == 2:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys\nq = int(sys.stdin.readline())\nfor i in range(q):\n\tn = sys.stdin.readline()\n\tl1 = sys.stdin.readline().strip()\n\tr1 = sys.stdin.readline().strip()\n\tup = True\n\tdir = 'r'\n\tidx = 0\n\twhile True:\n\t\tif idx == len(l1):\n\t\t\tif not up:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\tbreak\n\t\tcl = int(l1[idx])\n\t\tcr = int(r1[idx])\n\t\tif up:\n\t\t\tif dir == 'r':\n\t\t\t\tif cl <= 2:\n\t\t\t\t\tidx += 1\n\t\t\t\t\tcontinue\n\t\t\t\tdir = 'd'\n\t\t\t\tup = False\n\t\t\telse:\n\t\t\t\tassert dir == 'u'\n\t\t\t\tif cl <= 2:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\t\tdir = 'r'\n\t\t\t\tidx += 1\n\t\telse:\n\t\t\tassert not up\n\t\t\tif dir == 'r':\n\t\t\t\tif cr <= 2:\n\t\t\t\t\tidx += 1\n\t\t\t\telse:\n\t\t\t\t\tdir = 'u'\n\t\t\t\t\tup = True\n\t\t\telse:\n\t\t\t\tassert dir == 'd'\n\t\t\t\tif cr <= 2:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\t\tdir = 'r'\n\t\t\t\tidx += 1\n", "for _ in range(int(input())):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tl = [s1, s2]\n\tcur = 0\n\tflag = 1\n\ti = 0\n\tfor _ in range(n):\n\t\tif l[cur][i] >= '3':\n\t\t\tif l[1 - cur][i] < '3':\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tcur = 1 - cur\n\t\ti += 1\n\tif i == n and cur == 1:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n", "q = int(input())\nans = [True for i in range(q)]\nfor i in range(q):\n\tn = int(input())\n\tr = [0, 0]\n\tr[0] = input()\n\tr[1] = input()\n\tk = 0\n\tfor j in range(n):\n\t\tif int(r[0][j]) > 2 and int(r[1][j]) > 2:\n\t\t\tk = 1 - k\n\t\tif int(r[k][j]) > 2 and int(r[1 - k][j]) < 3:\n\t\t\tans[i] = False\n\tif k == 0:\n\t\tans[i] = False\nfor i in range(q):\n\tif ans[i] == True:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "import sys, math, itertools\nfrom collections import Counter, deque, defaultdict\nfrom bisect import bisect_left, bisect_right\nfrom heapq import heappop, heappush, heapify\nfrom copy import deepcopy\nmod = 10 ** 9 + 7\nINF = float('inf')\n\ndef inp():\n\treturn int(sys.stdin.readline())\n\ndef inpl():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef inpl_1():\n\treturn list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))\n\ndef inps():\n\treturn sys.stdin.readline()\n\ndef inpsl(x):\n\ttmp = sys.stdin.readline()\n\treturn list(tmp[:x])\n\ndef err(x):\n\tprint(x)\n\texit()\nfor _ in range(inp()):\n\tn = inp()\n\ts = [inpsl(n) for _ in range(2)]\n\tnx = 0\n\tfor i in range(n):\n\t\tnow = int(s[nx][i])\n\t\tif now > 2:\n\t\t\tnx = 1 - nx\n\t\t\tif int(s[nx][i]) <= 2:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\telse:\n\t\tprint('YES' if nx else 'NO')\n", "dx = [-1, 0, 1, 0]\ndy = [0, 1, 0, -1]\ndreverse = {0: 2, 1: 3, 2: 0, 3: 1}\ntile1_from_to = {3: 1}\nr0_tile2_from_to = {3: 2, 2: 1}\nr1_tile2_from_to = {0: 1, 3: 0}\nfrom_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}}\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tr1 = list(map(int, list(input())))\n\tr2 = list(map(int, list(input())))\n\ta = [r1, r2]\n\t(px, py) = (0, -1)\n\td_to = 1\n\td_from = dreverse[d_to]\n\tsolved = False\n\twhile True:\n\t\tpx += dx[d_to]\n\t\tpy += dy[d_to]\n\t\tif px == 1 and py == n:\n\t\t\tsolved = True\n\t\t\tbreak\n\t\tif px < 0 or px > 1 or py < 0 or (py >= n):\n\t\t\tbreak\n\t\ttile = a[px][py]\n\t\tif d_from in from_to[px][tile]:\n\t\t\td_to = from_to[px][tile][d_from]\n\t\telse:\n\t\t\tbreak\n\t\td_from = dreverse[d_to]\n\tprint('YES' if solved else 'NO')\n", "import sys, atexit\nfrom io import BytesIO\ninp = BytesIO(sys.stdin.buffer.read())\ninput = lambda : inp.readline().decode('ascii')\nbuf = BytesIO()\natexit.register(lambda : sys.__stdout__.buffer.write(buf.getvalue()))\n\ndef f(s):\n\tout = ''\n\tfor i in s:\n\t\tif i == '1' or i == '2':\n\t\t\tout += '1'\n\t\telse:\n\t\t\tout += '3'\n\treturn out\nfor i in range(int(input())):\n\tn = int(input())\n\tp = []\n\tx = input().strip()\n\tp.append(f(x))\n\tx = input().strip()\n\tp.append(f(x))\n\tr = c = 0\n\tt = True\n\ttry:\n\t\twhile not (r == 1 and c == n):\n\t\t\tif p[r][c] == '1':\n\t\t\t\tc += 1\n\t\t\telif p[1 - r][c] == '3' and p[r][c] == '3':\n\t\t\t\tr = 1 - r\n\t\t\t\tc += 1\n\t\t\telse:\n\t\t\t\tt = False\n\t\t\t\tbreak\n\texcept:\n\t\tprint('NO')\n\t\tcontinue\n\tif t:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "t = 1\nt = int(input())\nwhile t:\n\tt -= 1\n\tn = int(input())\n\trows = []\n\trows.append(input())\n\trows.append(input())\n\tdp = [[0, 0] for _ in range(n + 1)]\n\tdp[0][0] = 1\n\tfor i in range(1, n + 1):\n\t\tif rows[0][i - 1] in ('1', '2'):\n\t\t\tdp[i][0] = dp[i - 1][0]\n\t\tif rows[1][i - 1] in ('1', '2'):\n\t\t\tdp[i][1] = dp[i - 1][1]\n\t\trot = ['3', '4', '5', '6']\n\t\tif rows[0][i - 1] in rot and rows[1][i - 1] in rot:\n\t\t\tdp[i][0] = dp[i - 1][1]\n\t\t\tdp[i][1] = dp[i - 1][0]\n\tprint('YES' if dp[-1][1] else 'NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\ty = 1\n\tj = 0\n\tc = 0\n\twhile j < n - 1 and c == 0:\n\t\tif 2 < int(s1[j]) < 7 and 2 < int(s2[j]) < 7:\n\t\t\tj += 1\n\t\t\ty = 1 - y\n\t\telif y == 0 and 0 < int(s2[j]) < 3:\n\t\t\tj += 1\n\t\telif y == 1 and 0 < int(s1[j]) < 3:\n\t\t\tj += 1\n\t\telse:\n\t\t\tc = 1\n\tif c == 0:\n\t\tif y == 0 and 0 < int(s2[n - 1]) < 3:\n\t\t\tc = 0\n\t\telif y == 1 and 2 < int(s1[n - 1]) < 7 and (2 < int(s2[n - 1]) < 7):\n\t\t\tc = 0\n\t\telse:\n\t\t\tc = 1\n\tif c == 0:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "from sys import stdin, stdout\nimport heapq\nimport cProfile\nfrom collections import Counter, defaultdict, deque\nfrom functools import reduce\nimport math\n\ndef get_int():\n\treturn int(stdin.readline().strip())\n\ndef get_tuple():\n\treturn map(int, stdin.readline().split())\n\ndef get_list():\n\treturn list(map(int, stdin.readline().split()))\n\ndef solve():\n\tn = get_int()\n\ts = []\n\ts.append(input())\n\ts.append(input())\n\tcheck = 0\n\tfor i in range(n):\n\t\tif s[check][i] >= '3':\n\t\t\tif s[check ^ 1][i] >= '3':\n\t\t\t\tcheck ^= 1\n\t\t\telse:\n\t\t\t\treturn 'NO'\n\tif check == 1:\n\t\treturn 'YES'\n\telse:\n\t\treturn 'NO'\n\ndef main():\n\tprint(solve())\nTestCases = True\nif TestCases:\n\tfor i in range(get_int()):\n\t\tmain()\nelse:\n\tmain()\n", "t = int(input())\nfor k in range(t):\n\tans = 0\n\tn = int(input())\n\tarr = []\n\tarr.append(str(input().strip()))\n\tarr.append(str(input().strip()))\n\t(i, rch, cr) = (0, 0, 0)\n\twhile i < n:\n\t\tif arr[cr][i] == '1' or arr[cr][i] == '2':\n\t\t\tif rch == 0:\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tbreak\n\t\telif rch == 0:\n\t\t\trch = 1\n\t\t\tif cr == 0:\n\t\t\t\tcr = 1\n\t\t\telse:\n\t\t\t\tcr = 0\n\t\telse:\n\t\t\trch = 0\n\t\t\ti += 1\n\tif i == n and cr == 1:\n\t\tprint('YES')\n\t\tans = 1\n\tif ans == 0:\n\t\tprint('NO')\n", "import math\nimport bisect\nfrom functools import reduce\nfrom collections import defaultdict\n\ndef inn():\n\treturn int(input())\n\ndef inl():\n\treturn list(map(int, input().split()))\nMOD = 10 ** 9 + 7\nINF = inf = 10 ** 18 + 5\nfor t in range(inn()):\n\tn = inn()\n\ta1 = list(map(int, list(input())))\n\ta2 = list(map(int, list(input())))\n\tfor i in range(n):\n\t\tif a1[i] == 1 or a1[i] == 2:\n\t\t\ta1[i] = 0\n\t\telse:\n\t\t\ta1[i] = 1\n\t\tif a2[i] == 1 or a2[i] == 2:\n\t\t\ta2[i] = 0\n\t\telse:\n\t\t\ta2[i] = 1\n\tf = 0\n\tfor i in range(n):\n\t\tif a1[i] == 1 and a2[i] == 1:\n\t\t\tf = max(0, 1 - f)\n\t\telif f == 0 and a1[i] or (f and a2[i]):\n\t\t\tf = 0\n\t\t\tbreak\n\tif f:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "from sys import stdin, stdout\nfrom collections import deque\n\ndef ip():\n\treturn [int(i) for i in stdin.readline().split()]\n\ndef sp():\n\treturn [str(i) for i in stdin.readline().split()]\n\ndef pp(A):\n\tfor i in A:\n\t\tprint(i)\n\ndef solve():\n\tn = int(input())\n\tA = []\n\tr0 = list(str(input()))\n\tr1 = list(str(input()))\n\tA.append(r0)\n\tA.append(r1)\n\t(i, j) = (0, 0)\n\tt = False\n\twhile j != n and i < 2:\n\t\tp = A[i][j]\n\t\tif i == 0:\n\t\t\tif p == '1' or p == '2':\n\t\t\t\tif t:\n\t\t\t\t\treturn 'NO'\n\t\t\t\tj += 1\n\t\t\t\tt = False\n\t\t\telif t:\n\t\t\t\tj += 1\n\t\t\t\tt = False\n\t\t\telse:\n\t\t\t\ti += 1\n\t\t\t\tt = True\n\t\telif p == '1' or p == '2':\n\t\t\tif t:\n\t\t\t\treturn 'NO'\n\t\t\tj += 1\n\t\t\tt = False\n\t\telif t:\n\t\t\tj += 1\n\t\t\tt = False\n\t\telse:\n\t\t\ti -= 1\n\t\t\tt = True\n\tif i == 1 and j == n:\n\t\treturn 'YES'\n\telse:\n\t\treturn 'NO'\nt = int(input())\nfor i in range(t):\n\tprint(solve())\n", "n = int(input())\nfor i in range(n):\n\ta = int(input())\n\tb = [[0] * a] * 2\n\tb[0] = list(input())\n\tb[1] = list(input())\n\tt = 0\n\tf = 0\n\tfor j in range(a):\n\t\tif b[t][j] in '12':\n\t\t\tcontinue\n\t\telif b[t][j] in '3456':\n\t\t\tif b[(t + 1) % 2][j] in '3456':\n\t\t\t\tt = (t + 1) % 2\n\t\t\telse:\n\t\t\t\tf = 1\n\t\t\t\tbreak\n\tif f == 1:\n\t\tprint('No')\n\telif t == 1:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n", "q = int(input())\nt1 = set({'1', '2'})\nt2 = set({'3', '4', '5', '6'})\nfor i in range(q):\n\tc = int(input())\n\ta = [list(input())]\n\ta += [list(input())]\n\trow = 0\n\texit = False\n\tfor j in range(c):\n\t\tif a[row][j] in t2:\n\t\t\tif a[1 - row][j] in t2:\n\t\t\t\trow = 1 - row\n\t\t\telse:\n\t\t\t\texit = True\n\t\t\t\tbreak\n\t\tif exit:\n\t\t\tbreak\n\tif exit or row == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ts1 = input()\n\ts2 = input()\n\tm1 = []\n\tm2 = []\n\tfor j in range(n):\n\t\tm1.append(1 if int(s1[j]) < 3 else 2)\n\t\tm2.append(1 if int(s2[j]) < 3 else 2)\n\tm = [m1, m2]\n\tx = 0\n\ty = 0\n\twhile 1:\n\t\tif m[y][x] == 1:\n\t\t\tx += 1\n\t\t\tif x == n:\n\t\t\t\tif y == 1:\n\t\t\t\t\tprint('YES')\n\t\t\t\telse:\n\t\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\telse:\n\t\t\ty = (y + 1) % 2\n\t\t\tif m[y][x] == 2:\n\t\t\t\tx += 1\n\t\t\t\tif x == n:\n\t\t\t\t\tif y == 1:\n\t\t\t\t\t\tprint('YES')\n\t\t\t\t\telse:\n\t\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n", "import os, sys\nfrom io import BytesIO, IOBase\n\ndef solve(ls, n):\n\tcurr = 1\n\tx = [0, 0]\n\twhile x[0] <= 1 and x[1] < n:\n\t\tif ls[x[0]][x[1]] in '12':\n\t\t\tif curr == 1:\n\t\t\t\tx[1] += 1\n\t\t\telse:\n\t\t\t\treturn 'NO'\n\t\telse:\n\t\t\tcurr ^= 1\n\t\t\tif curr == 1:\n\t\t\t\tx[1] += 1\n\t\t\telse:\n\t\t\t\tx[0] ^= 1\n\tif x == [1, n]:\n\t\treturn 'YES'\n\treturn 'NO'\n\ndef main():\n\tfor _ in range(int(input())):\n\t\tn = int(input())\n\t\tls = [input().strip() for _ in range(2)]\n\t\tprint(solve(ls, n))\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nmain()\n", "import math\nimport sys\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ta = []\n\tfor i in range(2):\n\t\tf = list(str(input()))\n\t\tfor j in range(n):\n\t\t\tif f[j] == '1' or f[j] == '2':\n\t\t\t\tf[j] = 1\n\t\t\telse:\n\t\t\t\tf[j] = 0\n\t\ta.append(f)\n\tx = 0\n\ty = 0\n\tdirection = 0\n\tvector = [[1, 0], [0, -1], [0, 1]]\n\tstep = 0\n\twhile True:\n\t\tif x == n or step > 2 * n or y not in [0, 1]:\n\t\t\tbreak\n\t\tstep += 1\n\t\tif a[y][x] == 1:\n\t\t\tpass\n\t\telif direction == 0:\n\t\t\tif y == 0:\n\t\t\t\tdirection = 2\n\t\t\telse:\n\t\t\t\tdirection = 1\n\t\telse:\n\t\t\tdirection = 0\n\t\tx += vector[direction][0]\n\t\ty += vector[direction][1]\n\tif x == n and y == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ta = list(input())\n\tb = list(input())\n\tk = True\n\tj = 0\n\twhile True:\n\t\tif j == n:\n\t\t\tif k:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tprint('YES')\n\t\t\t\tbreak\n\t\tif k:\n\t\t\tif int(a[j]) < 3:\n\t\t\t\tj += 1\n\t\t\telif int(b[j]) > 2:\n\t\t\t\tj += 1\n\t\t\t\tk = False\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\telif int(b[j]) < 3:\n\t\t\tj += 1\n\t\telif int(a[j]) > 2:\n\t\t\tj += 1\n\t\t\tk = True\n\t\telse:\n\t\t\tprint('NO')\n\t\t\tbreak\n", "q = int(input())\nfor r in range(q):\n\tn = int(input())\n\trows = [[0 if int(c) <= 2 else 1 for c in input()]]\n\trows.append([0 if int(c) <= 2 else 1 for c in input()])\n\tswitch = 0\n\trow = 0\n\ti = 0\n\twhile i < n - 1:\n\t\tif rows[row][i]:\n\t\t\tif switch:\n\t\t\t\tswitch = 0\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tswitch = 1\n\t\t\t\trow = 1 if row == 0 else 0\n\t\telif switch:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\telse:\n\t\t\ti += 1\n\telse:\n\t\tif row == 1 and (not rows[row][i]) or (row == 0 and rows[row][i] and rows[1][i]):\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "t = int(input())\n\ndef change(y):\n\tif y == 0:\n\t\treturn 1\n\treturn 0\nfor _ in range(t):\n\tn = int(input())\n\tp1 = list(map(int, input()))\n\tp2 = list(map(int, input()))\n\tpipes = [p1, p2]\n\t(x, y) = (0, 0)\n\tans = True\n\twhile x < n:\n\t\tif pipes[y][x] < 3:\n\t\t\tx += 1\n\t\telse:\n\t\t\ty = change(y)\n\t\t\tif pipes[y][x] < 3:\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tx += 1\n\tif x == n and y == 1:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\ts = [input() for i in range(2)]\n\ti = 0\n\tj = 0\n\tans = ['YES', 'NO']\n\twhile i < n:\n\t\tif s[j][i] != '1' and s[j][i] != '2':\n\t\t\tj ^= 1\n\t\t\tif s[j][i] == '1' or s[j][i] == '2':\n\t\t\t\tans[0] = ans[1]\n\t\t\t\tbreak\n\t\ti += 1\n\tif i != n or j != 1:\n\t\tans[0] = ans[1]\n\tprint(ans[0])\n", "for t in range(int(input())):\n\tn = int(input())\n\ttubes = [input(), input()]\n\ti = 0\n\terror = False\n\tfor j in range(n):\n\t\tif tubes[i][j] >= '3':\n\t\t\tif tubes[i ^ 1][j] < '3':\n\t\t\t\terror = True\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ti ^= 1\n\tif not error and i == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "for i in range(int(input())):\n\tn = int(input())\n\ta = [input(), input()]\n\ti = 0\n\tflag = True\n\tfor k in range(n):\n\t\tif a[i][k] >= '3':\n\t\t\tif a[i - 1][k] <= '2':\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\ti = (i - 1) % 2\n\tprint('YES' if flag and i else 'NO')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ttube = [[int(c) for c in input()] for j in range(2)]\n\tcnt = 0\n\tb = False\n\tfor i in range(n):\n\t\tif tube[0][i] <= 2 and cnt % 2 == 0:\n\t\t\tcontinue\n\t\tif tube[1][i] <= 2 and cnt % 2 == 1:\n\t\t\tcontinue\n\t\tif tube[0][i] > 2 and tube[1][i] > 2:\n\t\t\tcnt += 1\n\t\telse:\n\t\t\tb = True\n\t\t\tbreak\n\tif b or cnt % 2 == 0:\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "from sys import stdin\nfrom collections import deque\nfrom math import sqrt, floor, ceil, log, log2, log10, pi\n\ndef ii():\n\treturn int(stdin.readline())\n\ndef fi():\n\treturn float(stdin.readline())\n\ndef mi():\n\treturn map(int, stdin.readline().split())\n\ndef fmi():\n\treturn map(float, stdin.readline().split())\n\ndef li():\n\treturn list(mi())\n\ndef si():\n\treturn stdin.readline()\nans = ['YES', 'NO']\nfor _ in range(ii()):\n\tf = d = p = 0\n\tn = ii()\n\ta = list(si())\n\tb = list(si())\n\ta = list(zip(a, b))\n\ti = 0\n\twhile i < n:\n\t\tx = int(a[i][p])\n\t\tif d and x < 3:\n\t\t\tf = 1\n\t\t\tbreak\n\t\telif x > 2:\n\t\t\td = 1 - d\n\t\t\tif d:\n\t\t\t\ti -= 1\n\t\t\t\tp = 1 - p\n\t\ti += 1\n\tif not p:\n\t\tf = 1\n\tprint(ans[f])\n", "from sys import stdin\nfor _ in range(int(stdin.readline())):\n\tn = int(stdin.readline())\n\ta = stdin.readline()[:-1]\n\tb = stdin.readline()[:-1]\n\t(y, result) = (1, 'YES')\n\tfor (i, x) in enumerate(a):\n\t\tif y == 2:\n\t\t\tx = b[i]\n\t\tif '2' < x < '7':\n\t\t\tif y == 1:\n\t\t\t\tif '2' < b[i] < '7':\n\t\t\t\t\ty = 2\n\t\t\t\telse:\n\t\t\t\t\tresult = 'NO'\n\t\t\t\t\tbreak\n\t\t\telif '2' < a[i] < '7':\n\t\t\t\ty = 1\n\t\t\telse:\n\t\t\t\tresult = 'NO'\n\t\t\t\tbreak\n\tif y == 2:\n\t\tprint(result)\n\telse:\n\t\tprint('NO')\n", "import sys\nntc = int(sys.stdin.readline().rstrip())\nfor _ in range(ntc):\n\tn = int(sys.stdin.readline().rstrip())\n\tboard = list()\n\tboard.append(list(map(int, list(sys.stdin.readline().rstrip()))))\n\tboard.append(list(map(int, list(sys.stdin.readline().rstrip()))))\n\tif n == 1:\n\t\tif board[0][0] >= 3 and board[0][0] <= 6 and (board[1][0] >= 3) and (board[1][0] <= 6):\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\telse:\n\t\tx = 0\n\t\ty = 0\n\t\tpriv_x = 0\n\t\tpriv_y = 0\n\t\tif board[0][0] >= 1 and board[0][0] <= 2:\n\t\t\ty = 1\n\t\telse:\n\t\t\tx = 1\n\t\twhile True:\n\t\t\tif x < 0 or y < 0 or x >= 2 or (y >= n):\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\tif x == 1 and y == n - 1:\n\t\t\t\tdx = x - priv_x\n\t\t\t\tdy = y - priv_y\n\t\t\t\tif dx == 0 and dy == 1:\n\t\t\t\t\tif board[x][y] >= 1 and board[x][y] <= 2:\n\t\t\t\t\t\tprint('YES')\n\t\t\t\t\t\tbreak\n\t\t\t\t\telse:\n\t\t\t\t\t\tprint('NO')\n\t\t\t\t\t\tbreak\n\t\t\t\tif dx == 1 and dy == 0:\n\t\t\t\t\tif board[x][y] >= 3 and board[x][y] <= 6:\n\t\t\t\t\t\tprint('YES')\n\t\t\t\t\t\tbreak\n\t\t\t\t\telse:\n\t\t\t\t\t\tprint('NO')\n\t\t\t\t\t\tbreak\n\t\t\tif board[x][y] >= 1 and board[x][y] <= 2:\n\t\t\t\tdx = x - priv_x\n\t\t\t\tdy = y - priv_y\n\t\t\t\tpriv_x = x\n\t\t\t\tpriv_y = y\n\t\t\t\tx += dx\n\t\t\t\ty += dy\n\t\t\telse:\n\t\t\t\tdx = x - priv_x\n\t\t\t\tdy = y - priv_y\n\t\t\t\tpriv_x = x\n\t\t\t\tpriv_y = y\n\t\t\t\tif dx == 1 and dy == 0:\n\t\t\t\t\ty += 1\n\t\t\t\telif dx == 0 and dy == 1:\n\t\t\t\t\tif x == 0:\n\t\t\t\t\t\tx += 1\n\t\t\t\t\telse:\n\t\t\t\t\t\tx -= 1\n\t\t\t\telif dx == -1 and dy == 0:\n\t\t\t\t\ty += 1\n", "t = [[['h', 'v'], ['e', 'h']], [['h', 'v'], ['e', 'h']]]\n\ndef solve():\n\ta = []\n\tn = int(input())\n\tfor i in range(2):\n\t\ta.append([0] * n)\n\tfor i in range(2):\n\t\tstring = input()\n\t\tfor j in range(n):\n\t\t\ta[i][j] = int(string[j])\n\tr = 0\n\tc = 0\n\tp = 0\n\tm = 0\n\tanswer = 'NO'\n\tfor i in range(2 * n):\n\t\tp = a[r][c]\n\t\tif p >= 3:\n\t\t\tp = 1\n\t\telse:\n\t\t\tp = 0\n\t\tnext_m = t[r][m][p]\n\t\tif next_m == 'h':\n\t\t\tc += 1\n\t\telif next_m == 'v':\n\t\t\tr = (r + 1) % 2\n\t\telse:\n\t\t\tbreak\n\t\tif r == 1 and c == n:\n\t\t\tanswer = 'YES'\n\t\t\tbreak\n\t\tif c == n:\n\t\t\tbreak\n\t\tif next_m == 'h':\n\t\t\tm = 0\n\t\telse:\n\t\t\tm = 1\n\tprint(answer)\nq = int(input())\nfor i in range(q):\n\tsolve()\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tlin1 = input()\n\tlin2 = input()\n\ttub = [[], []]\n\tfor c in lin1:\n\t\tif c == '1' or c == '2':\n\t\t\ttub[0].append(0)\n\t\telse:\n\t\t\ttub[0].append(1)\n\tfor c in lin2:\n\t\tif c == '1' or c == '2':\n\t\t\ttub[1].append(0)\n\t\telse:\n\t\t\ttub[1].append(1)\n\tif tub[0][0] == 0:\n\t\tposx = 1\n\t\tposy = 0\n\telif tub[1][0] == 0:\n\t\tposx = 0\n\t\tposy = 2\n\telse:\n\t\tposx = 1\n\t\tposy = 1\n\tfor i in range(2 * n):\n\t\tif posx == n and posy == 1:\n\t\t\tprint('YES')\n\t\t\tbreak\n\t\tif posx == n and posy != 1:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif posy > 1 or posy < 0:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif tub[posy][posx] == 0:\n\t\t\tposx += 1\n\t\telif tub[posy][posx] == 1:\n\t\t\tif posy == 0:\n\t\t\t\tif tub[1][posx] == 1:\n\t\t\t\t\tposx += 1\n\t\t\t\t\tposy = 1\n\t\t\t\telse:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\telif posy == 1:\n\t\t\t\tif tub[0][posx] == 1:\n\t\t\t\t\tposx += 1\n\t\t\t\t\tposy = 0\n\t\t\t\telse:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n", "import math\ntestcase = int(input())\nfor case in range(testcase):\n\ta = int(input())\n\tm = []\n\tfor _ in range(2):\n\t\tm.append(list(input()))\n\tp = 0\n\tq = 0\n\tstate = 'p'\n\twhile True:\n\t\tif m[q][p] == '1' or m[q][p] == '2':\n\t\t\tif state == 'p':\n\t\t\t\tp += 1\n\t\t\telse:\n\t\t\t\tq = 999\n\t\t\t\tbreak\n\t\telif state == 'p':\n\t\t\tif q == 1:\n\t\t\t\tq -= 1\n\t\t\t\tstate = 'q'\n\t\t\telse:\n\t\t\t\tq += 1\n\t\t\t\tstate = 'q'\n\t\telse:\n\t\t\tp += 1\n\t\t\tstate = 'p'\n\t\tif p >= a:\n\t\t\tbreak\n\tif q == 1:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "q = int(input())\nfor _ in range(q):\n\tn = int(input())\n\tarr1 = list(map(int, input()))\n\tarr2 = list(map(int, input()))\n\tp = 0\n\tq = 0\n\tr = 0\n\tarr = [arr1, arr2]\n\ti = 0\n\twhile i < n:\n\t\tif p == 0 and arr[q][i] in [3, 4, 5, 6]:\n\t\t\tq = int(not q)\n\t\t\tp = 1\n\t\telif p == 0 and arr[q][i] in [1, 2]:\n\t\t\tp = 0\n\t\t\ti += 1\n\t\telif arr[q][i] in [1, 2]:\n\t\t\tr = 1\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\telse:\n\t\t\tp = 0\n\t\t\ti += 1\n\ti = i - 1\n\tif i == n - 1 and q == 0:\n\t\tprint('NO')\n\telif r == 0:\n\t\tprint('YES')\n", "import math\nfrom decimal import Decimal\nimport heapq\nfrom collections import deque\n\ndef na():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\treturn (n, b)\n\ndef nab():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\tc = [int(x) for x in input().split()]\n\treturn (n, b, c)\n\ndef dv():\n\t(n, m) = map(int, input().split())\n\treturn (n, m)\n\ndef dva():\n\t(n, m) = map(int, input().split())\n\ta = [int(x) for x in input().split()]\n\tb = [int(x) for x in input().split()]\n\treturn (n, m, b)\n\ndef eratosthenes(n):\n\tsieve = list(range(n + 1))\n\tfor i in sieve:\n\t\tif i > 1:\n\t\t\tfor j in range(i + i, len(sieve), i):\n\t\t\t\tsieve[j] = 0\n\treturn sorted(set(sieve))\n\ndef lol(lst, k):\n\tk = k % len(lst)\n\tret = [0] * len(lst)\n\tfor i in range(len(lst)):\n\t\tif i + k < len(lst) and i + k >= 0:\n\t\t\tret[i] = lst[i + k]\n\t\tif i + k >= len(lst):\n\t\t\tret[i] = lst[i + k - len(lst)]\n\t\tif i + k < 0:\n\t\t\tret[i] = lst[i + k + len(lst)]\n\treturn ret\n\ndef nm():\n\tn = int(input())\n\tb = [int(x) for x in input().split()]\n\tm = int(input())\n\tc = [int(x) for x in input().split()]\n\treturn (n, b, m, c)\n\ndef dvs():\n\tn = int(input())\n\tm = int(input())\n\treturn (n, m)\n\ndef Factor(n):\n\tAns = []\n\td = 2\n\twhile d * d <= n:\n\t\tif n % d == 0:\n\t\t\tAns.append(d)\n\t\t\tn //= d\n\t\telse:\n\t\t\td += 1\n\tif n > 1:\n\t\tAns.append(n)\n\treturn Ans\nq = int(input())\nfor _ in range(q):\n\tn = int(input())\n\ta = []\n\ts1 = input()\n\ts2 = input()\n\ta = [s1, s2]\n\tj = 0\n\ttc = 'YES'\n\tfor i in range(n):\n\t\tif a[j][i] in '12':\n\t\t\tcontinue\n\t\telif a[j ^ 1][i] not in '12':\n\t\t\tj ^= 1\n\t\telse:\n\t\t\ttc = 'NO'\n\t\t\tbreak\n\tif j == 0:\n\t\ttc = 'NO'\n\tprint(tc)\n", "def solve(row1, row2, ans):\n\tn = len(row1)\n\trow = 1\n\tfor i in range(n):\n\t\tif row == 1:\n\t\t\tif row1[i] not in ['1', '2']:\n\t\t\t\tif row2[i] not in ['1', '2']:\n\t\t\t\t\trow = 2\n\t\t\t\telse:\n\t\t\t\t\tans.append('NO')\n\t\t\t\t\treturn\n\t\telif row2[i] not in ['1', '2']:\n\t\t\tif row1[i] not in ['1', '2']:\n\t\t\t\trow = 1\n\t\t\telse:\n\t\t\t\tans.append('NO')\n\t\t\t\treturn\n\tif row == 2:\n\t\tans.append('YES')\n\t\treturn\n\tans.append('NO')\n\ndef main():\n\tans = []\n\tq = int(input())\n\tfor i in range(q):\n\t\tn = int(input())\n\t\trow1 = input()\n\t\trow2 = input()\n\t\tsolve(row1, row2, ans)\n\tfor i in ans:\n\t\tprint(i)\nmain()\n", "q = int(input())\nD = {'1': 0, '2': 0, '3': 1, '4': 1, '5': 1, '6': 1}\nfor _ in range(q):\n\tn = int(input())\n\tA = [[True] + [False] * n, [False] + [False] * n]\n\tB = [[D[x] for x in input()], [D[x] for x in input()]]\n\tfor i in range(1, n + 1):\n\t\tfor j in [0, 1]:\n\t\t\tA[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]))\n\tprint('YES' if A[1][n] else 'NO')\n", "def preprocess(string: str) -> str:\n\tfor r in ('1', '2'):\n\t\tstring = string.replace(r, '1')\n\tfor r in ('3', '4', '5', '6'):\n\t\tstring = string.replace(r, '2')\n\treturn string\nfor _ in range(int(input())):\n\tinput()\n\ts1 = preprocess(input())\n\ts2 = preprocess(input())\n\tline = 0\n\texit_flag = False\n\tfor c in zip(s1, s2):\n\t\tcurrent_tube = c[line]\n\t\tif current_tube == '1':\n\t\t\tpass\n\t\telif current_tube == '2':\n\t\t\tif c[1 - line] == '2':\n\t\t\t\tline = 1 - line\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\texit_flag = True\n\t\tif exit_flag:\n\t\t\tbreak\n\tif not exit_flag:\n\t\tif line == 1:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n", "import sys\n\ndef main():\n\tt = int(sys.stdin.readline())\n\tfor _ in range(t):\n\t\tn = int(sys.stdin.readline())\n\t\ta = list(sys.stdin.readline())\n\t\tb = list(sys.stdin.readline())\n\t\tchk = False\n\t\tfor i in range(n):\n\t\t\tif chk is False:\n\t\t\t\tif int(a[i]) > 2:\n\t\t\t\t\tif int(b[i]) <= 2:\n\t\t\t\t\t\tchk = False\n\t\t\t\t\t\tbreak\n\t\t\t\t\tchk = not chk\n\t\t\telif int(b[i]) > 2:\n\t\t\t\tif int(a[i]) <= 2:\n\t\t\t\t\tchk = False\n\t\t\t\t\tbreak\n\t\t\t\tchk = not chk\n\t\tprint('YES') if chk is True else print('NO')\nmain()\n", "import sys\ninput = sys.stdin.readline\nI = lambda : list(map(int, input().split()))\n(t,) = I()\nfor _ in range(t):\n\t(n,) = I()\n\tl = [input(), input()]\n\tc = [0, 0]\n\tk = 0\n\tfor i in range(2 * n):\n\t\tx = l[c[0]][c[1]]\n\t\tif x == '1' or x == '2':\n\t\t\tif k:\n\t\t\t\tc = [0, 0]\n\t\t\t\tbreak\n\t\t\tc[1] += 1\n\t\t\tk = 0\n\t\telif x in '3456':\n\t\t\tk += 1\n\t\t\tif k == 2:\n\t\t\t\tc[1] += 1\n\t\t\t\tk = 0\n\t\t\telse:\n\t\t\t\tc[0] = (c[0] + 1) % 2\n\t\tif c == [1, n]:\n\t\t\tbreak\n\tprint('YNEOS'[c != [1, n]::2])\n", "def switch(x, y):\n\tx = int(x)\n\ty = int(y)\n\treturn x in range(3, 7) and y in range(3, 7)\n\ndef parse(top, bottom):\n\tt = True\n\tx = 0\n\ti = 0\n\twhile i < len(top):\n\t\tif t:\n\t\t\tif top[i] not in ('1', '2'):\n\t\t\t\tif switch(top[i], bottom[i]):\n\t\t\t\t\tt = False\n\t\t\t\t\tx += 1\n\t\t\t\telse:\n\t\t\t\t\treturn False\n\t\telif bottom[i] not in ('1', '2'):\n\t\t\tif switch(top[i], bottom[i]):\n\t\t\t\tt = True\n\t\t\t\tx += 1\n\t\t\telse:\n\t\t\t\treturn False\n\t\ti += 1\n\treturn not t and x % 2 == 1\nn = int(input())\nfor _ in range(n):\n\tinput()\n\ttop = input()\n\tbottom = input()\n\tprint('YES' if parse(top, bottom) else 'NO')\n", "for case in range(int(input())):\n\tn = int(input())\n\tr = [[], [], []]\n\tfor i in range(1, 3):\n\t\tr[i] = [-1] + list(map(int, list(input())))\n\t\tfor j in range(1, n + 1):\n\t\t\tif 1 <= r[i][j] and r[i][j] <= 2:\n\t\t\t\tr[i][j] = 0\n\t\t\telif 3 <= r[i][j] and r[i][j] <= 6:\n\t\t\t\tr[i][j] = 1\n\tq = [('L', 1, 1)]\n\tflag = False\n\twhile len(q):\n\t\tj = q.pop(0)\n\t\tif j[1] == 2 and j[2] == n + 1:\n\t\t\tflag = True\n\t\t\tbreak\n\t\tif j[2] > n:\n\t\t\tcontinue\n\t\tif j[0] == 'L':\n\t\t\tif r[j[1]][j[2]] == 0:\n\t\t\t\tq.append(('L', j[1], j[2] + 1))\n\t\t\telif r[j[1]][j[2]] == 1:\n\t\t\t\tif j[1] == 1:\n\t\t\t\t\tq.append(('U', 2, j[2]))\n\t\t\t\telif j[1] == 2:\n\t\t\t\t\tq.append(('D', 1, j[2]))\n\t\telif j[0] == 'U' or j[0] == 'D':\n\t\t\tif r[j[1]][j[2]] == 1:\n\t\t\t\tq.append(('L', j[1], j[2] + 1))\n\tprint('YES' if flag else 'NO')\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\tl1 = input()\n\tl2 = input()\n\ts1 = {'1', '2'}\n\ts2 = {'3', '4', '5', '6'}\n\tp = 0\n\tm = 0\n\tfor z in range(n):\n\t\tif m % 2 == 1 and l2[z] in s2 and (l1[z] in s1):\n\t\t\tprint('NO')\n\t\t\tp += 1\n\t\t\tbreak\n\t\telif m % 2 == 0 and l1[z] in s2 and (l2[z] in s1):\n\t\t\tprint('NO')\n\t\t\tp += 1\n\t\t\tbreak\n\t\telif l1[z] in s2 and l2[z] in s2:\n\t\t\tm += 1\n\tif m % 2 != 0 and p != 1:\n\t\tprint('YES')\n\telif p != 1:\n\t\tprint('NO')\n", "queries = int(input())\nd = {'1': 1, '2': 1, '3': 2, '4': 2, '5': 2, '6': 2}\nfor q in range(queries):\n\tn = int(input())\n\tr = [[d[i] for i in input()], [d[i] for i in input()]]\n\tj = n - 1\n\ti = 1\n\tprev = -1\n\twhile True:\n\t\tif r[i][j] == 1:\n\t\t\tj -= 1\n\t\t\tprev = 1\n\t\telif prev == 2:\n\t\t\tj -= 1\n\t\t\tprev = 1\n\t\telse:\n\t\t\ti = i ^ 1\n\t\t\tprev = 2\n\t\t\tif r[i][j] == 1:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\tif j == -1:\n\t\t\tif i == 0:\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\tbreak\n", "q = int(input())\nfor i in range(q):\n\tn = int(input())\n\tlayer_1 = list(map(int, input()))\n\tlayer_2 = list(map(int, input()))\n\tx = 0\n\ty = 0\n\tdir = 0\n\twhile True:\n\t\tif y == 0:\n\t\t\tif layer_1[x] in [1, 2]:\n\t\t\t\tif dir == 1:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\t\telif x == n - 1:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tx = x + 1\n\t\t\telif dir == 0:\n\t\t\t\tdir = 1\n\t\t\t\ty = 1\n\t\t\telse:\n\t\t\t\tdir = 0\n\t\t\t\tif x == n - 1:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\tx = x + 1\n\t\telif layer_2[x] in [1, 2]:\n\t\t\tif dir == 1:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\t\telif x == n - 1:\n\t\t\t\tprint('YES')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tx = x + 1\n\t\telif dir == 0:\n\t\t\tdir = 1\n\t\t\ty = 0\n\t\telse:\n\t\t\tdir = 0\n\t\t\tif x == n - 1:\n\t\t\t\tprint('YES')\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tx = x + 1\n", "q = int(input())\n\ndef solve():\n\tn = int(input())\n\ta = input()\n\tb = input()\n\tx = 0\n\ty = 0\n\tfromX = True\n\twhile (y == 0 or y == 1) and x < n:\n\t\tif y == 0:\n\t\t\tif not fromX and a[x] in ['1', '2']:\n\t\t\t\treturn 'NO'\n\t\t\telif fromX and a[x] in ['1', '2']:\n\t\t\t\tx += 1\n\t\t\telif fromX:\n\t\t\t\ty += 1\n\t\t\t\tfromX = False\n\t\t\telse:\n\t\t\t\tx += 1\n\t\t\t\tfromX = True\n\t\telif not fromX and b[x] in ['1', '2']:\n\t\t\treturn 'NO'\n\t\telif fromX and b[x] in ['1', '2']:\n\t\t\tx += 1\n\t\telif fromX:\n\t\t\ty -= 1\n\t\t\tfromX = False\n\t\telse:\n\t\t\tx += 1\n\t\t\tfromX = True\n\tif x == n and y == 1:\n\t\treturn 'YES'\n\telse:\n\t\treturn 'NO'\nfor _ in range(q):\n\tprint(solve())\n", "import sys\ninput = sys.stdin.readline\nq = int(input())\nfor testcases in range(q):\n\tn = int(input())\n\tMAP = [list(map(int, list(input().strip()))) for i in range(2)]\n\tX = 0\n\tY = 0\n\tfr = 0\n\twhile True:\n\t\tif X == n and Y == 1:\n\t\t\tprint('YES')\n\t\t\tbreak\n\t\tif X == n:\n\t\t\tprint('NO')\n\t\t\tbreak\n\t\tif MAP[Y][X] <= 2:\n\t\t\tif fr == 0:\n\t\t\t\tfr = 0\n\t\t\t\tX += 1\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\t\tbreak\n\t\telif fr == 0:\n\t\t\tfr = 1\n\t\t\tY += 1\n\t\t\tY %= 2\n\t\telse:\n\t\t\tX += 1\n\t\t\tfr = 0\n"]

difficulty: MEDIUM

source: codeforces

raw_problem:
C. Pipes

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

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:
  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:
  Examples of connected pipes
Let's describe the problem using some example:
  The first example input
And its solution is below:
  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.

question:
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](1.png) 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](2.png) Examples of connected pipes Let's describe the problem using some example:
 ![image](3.png) The first example input And its solution is below:
 ![image](4.png) 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.

skill_types: ['Dynamic programming']

image_tags: Patterns Patterns Patterns Patterns

data_split: test