$n$ players are playing a game.

There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map.

You are the game master and want to organize a tournament. There will be a total of $n-1$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament.

In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of players.

The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$, $a_i \neq a_j$ for $i \neq j$), where $a_i$ is the strength of the $i$-th player on the first map.

The third line of each test case contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \leq b_i \leq 10^9$, $b_i \neq b_j$ for $i \neq j$), where $b_i$ is the strength of the $i$-th player on the second map.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.


-----Output-----

For each test case print a string of length $n$. $i$-th character should be "1" if the $i$-th player can win the tournament, or "0" otherwise.


-----Examples-----

Input
3
4
1 2 3 4
1 2 3 4
4
11 12 20 21
44 22 11 30
1
1000000000
1000000000
Output
0001
1111
1


-----Note-----

In the first test case, the $4$-th player will beat any other player on any game, so he will definitely win the tournament.

In the second test case, everyone can be a winner.

In the third test case, there is only one player. Clearly, he will win the tournament.

Difficulty: MEDIUM_HARD
Tags: Graph algorithms

Graph traversal

Amortized analysis

Greedy algorithms

Dynamic programming

Data structures
Skill types: Dynamic programming

Data structures

Amortized analysis

Greedy algorithms

Starter code:

Solutions:
def inlt():
	return list(map(int, input().split()))
import sys
from collections import defaultdict
from math import sqrt, ceil, floor, factorial, log
from bisect import bisect_left, bisect_right
from io import BytesIO, IOBase, StringIO
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
while t:
	t -= 1
	n = int(input())
	l1 = inlt()
	l2 = inlt()
	for j in range(len(l1)):
		l1[j] = [l1[j], j]
	for j in range(len(l2)):
		l2[j] = [l2[j], j]
	l1.sort()
	l2.sort()
	dic1 = defaultdict(int)
	dic2 = defaultdict(int)
	for j in range(len(l1)):
		dic1[l1[j][1]] = j
	for j in range(len(l2)):
		dic2[l2[j][1]] = j
	ans = defaultdict(bool)
	start = [l1[-1]]
	ans[l1[-1][1]] = True
	l1[-1] = []
	while len(start) > 0:
		new = []
		for j in start:
			ans[j[1]] = True
			first = dic1[j[1]] + 1
			second = dic2[j[1]] + 1
			while first < n and len(l1[first]) > 0:
				new.append(l1[first])
				l1[first] = []
				first += 1
			while second < n and len(l2[second]) > 0:
				new.append(l2[second])
				l2[second] = []
				second += 1
		start = new
	st = ''
	for j in range(0, n):
		if ans[j]:
			st = st + '1'
		else:
			st = st + '0'
	print(st)


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
sys.setrecursionlimit(3 * 10 ** 5)
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
a = []
(n, k) = (0, 0)
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07
x = 0
pref = []
lvl = []
gp = []
ans = []
f = 0
w = []

def update_it(bit, i, val):
	n = len(bit)
	while i < n:
		bit[i] += val
		i += i & -i

def get_ans(bit, i):
	n = len(bit)
	tot = 0
	while i > 0:
		tot += bit[i]
		i -= i & -i
	return tot

def dfs(i, prod, rem, n):
	if rem == 0:
		while i < len(n):
			prod *= int(n[i])
			i += 1
		return prod
	if i == len(n):
		return prod
	mx = 0
	for j in range(9 - int(n[i])):
		mx = max(dfs(i + 1, (int(n[i]) + min(j, rem)) * prod, rem - min(j, rem), n), mx)
	return mx

def hnbhai(tc):
	n = sb()
	a = sd()
	b = sd()
	mx = max(a)
	mx1 = max(b)
	temp = []
	temp1 = []
	for i in range(n):
		temp.append([a[i], i])
	for i in range(n):
		temp1.append([b[i], i])
	x = a.index(mx)
	y = b.index(mx1)
	ans = ['0'] * n
	if x == y:
		ans[x] = '1'
		print(''.join(ans))
		return
	temp.sort(reverse=True)
	temp1.sort(reverse=True)
	idx = a[temp1[0][1]]
	idx1 = b[temp[0][1]]
	i = 0
	j = 0
	while i < n and j < n:
		if temp[i][0] >= idx:
			idx1 = min(idx1, b[temp[i][1]])
			i += 1
			continue
		if temp1[j][0] >= idx1:
			idx = min(idx, a[temp1[j][1]])
			j += 1
			continue
		break
	for i in range(n):
		if temp[i][0] >= idx:
			ans[temp[i][1]] = '1'
	for i in range(n):
		if temp1[i][0] >= idx1:
			ans[temp1[i][1]] = '1'
	print(''.join(ans))
for _ in range(sb()):
	hnbhai(_ + 1)


import math
import os
import sys
sys.setrecursionlimit(2 * 10 ** 5)
from decimal import *
from io import BytesIO, IOBase
import threading
from itertools import *
from collections import *
from array import *
import random
M = 10 ** 9 + 7
import heapq
import bisect
from functools import lru_cache
from queue import PriorityQueue
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

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

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

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

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

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

def fsep():
	return map(float, inp().split())

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

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

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

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

def ternarysearch(arr, n, key):
	(l, r) = (0, n - 1)
	while l <= r:
		mid = (-l + r) // 3 + l
		mid2 = mid + (-l + r) // 3
		if arr[mid] == key:
			return mid
		if arr[mid2] == key:
			return mid2
		if arr[mid] > key:
			r = mid - 1
		elif arr[mid2] < key:
			l = mid2 + 1
		else:
			l = mid + 1
			r = mid2 - 1
	return -1

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynum(x, l, r, a):
	if x >= l and x <= r:
		a.append(x)
	if x > r:
		a.append(x)
		return a
	if x < 10000000000.0:
		luckynum(x * 10 + 4, l, r, a)
		luckynum(x * 10 + 7, l, r, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1

def solven(p, l, a, b, n, res):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def generate(st, s):
	if len(s) == 0:
		return
	if s not in st:
		st.add(s)
		for i in range(len(s)):
			t = list(s).copy()
			t.remove(s[i])
			t = ''.join(t)
			generate(st, t)
	return

def largestincreasingsubsequence(A):
	l = [1] * len(A)
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] <= A[i]:
				l[i] = max(l[i], l[k] + 1)
	return max(l)

def findOR(nums, N):
	prefix_sum = 0
	result = 0
	for i in range(N):
		result |= nums[i]
		prefix_sum += nums[i]
		result |= prefix_sum
	return result

def OR(a, n):
	ans = a[0]
	for i in range(1, n):
		ans |= a[i]
	return ans

def toString(List):
	return ''.join(List)

def permute(a, l, r, p):
	if l == r:
		p.append(toString(a))
	else:
		for i in range(l, r + 1):
			(a[l], a[i]) = (a[i], a[l])
			permute(a, l + 1, r, p)
			(a[l], a[i]) = (a[i], a[l])

def squareRoot(number, precision):
	start = 0
	(end, ans) = (number, 1)
	while start <= end:
		mid = int((start + end) / 2)
		if mid * mid == number:
			ans = mid
			break
		if mid * mid < number:
			start = mid + 1
		else:
			end = mid - 1
	increment = 0.1
	for i in range(0, precision):
		while ans * ans <= number:
			ans += increment
		ans = ans - increment
		increment = increment / 10
	return ans

def countRectangles(l, w):
	squareSide = math.gcd(l, w)
	return int(l * w / (squareSide * squareSide))

def count_same_digit(L, R):
	tmp = 0
	ans = 0
	n = int(math.log10(R) + 1)
	for i in range(0, n):
		tmp = tmp * 10 + 1
		for j in range(1, 10):
			if L <= tmp * j and tmp * j <= R:
				ans += 1
	return ans

def findCrossOver(arr, low, high, x):
	if arr[high] <= x:
		return high
	if arr[low] > x:
		return low
	mid = (low + high) // 2
	if arr[mid] <= x and arr[mid + 1] > x:
		return mid
	if arr[mid] < x:
		return findCrossOver(arr, mid + 1, high, x)
	return findCrossOver(arr, low, mid - 1, x)

def Kclosest(arr, x, k, n, ans):
	l = findCrossOver(arr, 0, n - 1, x)
	r = l + 1
	count = 0
	if arr[l] == x:
		l -= 1
	while l >= 0 and r < n and (count < k):
		if x - arr[l] < arr[r] - x:
			ans.append(arr[l])
			l -= 1
		else:
			ans.append(arr[r])
			r += 1
		count += 1
	while count < k and l >= 0:
		ans.append(arr[l])
		l -= 1
		count += 1
	while count < k and r < n:
		ans.append(arr[r])
		r += 1
		count += 1
	return ans

def dfs(root, nodeVal, nodeConnection, visited):
	leftVal = nodeVal[root][0]
	rightVal = nodeVal[root][1]
	solution = []
	if nodeConnection[root]:
		visited.add(root)
		for i in nodeConnection[root]:
			if i not in visited:
				solution.append(dfs(i, nodeVal, nodeConnection, visited))
		leftMax = 0
		rightMax = 0
		for i in solution:
			(l, r) = i
			leftMax += max(abs(leftVal - l[0]) + l[1], abs(leftVal - r[0]) + r[1])
			rightMax += max(abs(rightVal - l[0]) + l[1], abs(rightVal - r[0]) + r[1])
		return ((leftVal, leftMax), (rightVal, rightMax))
	else:
		return ((leftVal, 0), (rightVal, 0))

def luckynumber(x, n, a):
	if x > 0:
		a.append(x)
	if x > 10 ** 9:
		return a
	elif x < 1000000000000.0:
		luckynumber(x * 10 + 4, n, a)
		luckynumber(x * 10 + 7, n, a)

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

def query1(l, r):
	if l >= r:
		return -1
	print('?', l + 1, r + 1)
	sys.stdout.flush()
	return int(input()) - 1

def answer(p):
	print('!', p + 1)
	sys.stdout.flush()
	exit()

def buildPrefix(MAX, prefix):
	prime = [1] * (MAX + 1)
	p = 2
	while p * p <= MAX:
		if prime[p] == 1:
			i = p * 2
			while i <= MAX:
				prime[i] = 0
				i += p
		p += 1
	for p in range(2, MAX + 1):
		prefix[p] = prefix[p - 1]
		if prime[p] == 1:
			prefix[p] += 1

def query(L, R, prefix):
	return prefix[R] - prefix[L - 1]

def maxSubArraySum(a, size):
	max_so_far = a[0]
	curr_max = a[0]
	for i in range(1, size):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max)
	return max_so_far

def solvepp(n, k):
	if n == 1 and k == 1:
		return 0
	mid = 2 ** (n - 1) // 2
	if k <= mid:
		return solvepp(n - 1, k)
	else:
		return solvepp(n - 1, k - mid) == 0

def solvr(s, p):
	if len(s) == 0:
		print(p, end=' ')
		return
	op1 = p
	op2 = p + s[0]
	s = s[1:]
	solvr(s, op1)
	solvr(s, op2)
	return

def paranthesis(n, m, ans, l):
	if n == 0 and m == 0:
		print(ans)
		return
	if n != 0:
		op1 = ans + '('
		paranthesis(n - 1, m, op1, l)
	if m > n:
		op2 = ans + ')'
		paranthesis(n, m - 1, op2, l)

def rse(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(n)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(n)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def lse(arr, n):
	stack = []
	ans = []
	for i in range(n):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	return ans

def mah(arr):
	max1 = 0
	p = rse(arr, len(arr))
	q = lse(arr, len(arr))
	for i in range(len(arr)):
		a = (p[i] - q[i] - 1) * arr[i]
		max1 = max(a, max1)
	return max1

def lcs(s, r):
	rr = len(r)
	ss = len(s)
	l = [[0] * (rr + 1) for i in range(ss + 1)]
	for i in range(1, ss + 1):
		for j in range(1, rr + 1):
			if s[i - 1] == r[j - 1]:
				l[i][j] = l[i - 1][j - 1] + 1
			else:
				l[i][j] = max(l[i - 1][j], l[i][j - 1])
	return l[ss][rr]

def subsetsum(arr, sum, len):
	dp = [[False] * (sum + 1) for i in range(len + 1)]
	for i in range(len + 1):
		dp[i][0] = True
	for i in range(1, len + 1):
		for j in range(1, sum + 1):
			if arr[i - 1] > j:
				dp[i][j] = dp[i - 1][j]
			else:
				dp[i][j] = dp[i - 1][j] or dp[i - 1][j - arr[i - 1]]
	return dp[len][sum]

def matrixmincost(cost, n, m):
	dp = [[0 for x in range(m)] for x in range(n)]
	for i in range(n):
		for j in range(m):
			if i == 0 and j == 0:
				dp[i][j] = cost[i][j]
			elif i == 0 and j != 0:
				dp[i][j] = dp[i][j - 1] + cost[i][j]
			elif j == 0 and i != 0:
				dp[i][j] = dp[i - 1][j] + cost[i][j]
			else:
				dp[i][j] = cost[i][j] + min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1])
	return dp[n - 1][m - 1]

def coinchange(n, arr, len1):
	dp = [0] * (n + 1)
	dp[0] = 1
	for i in range(len1):
		for j in range(arr[i], n + 1):
			dp[j] += dp[j - arr[i]]
	return dp[n]

class Graph(object):

	def __init__(self, vertices):
		self.graph = defaultdict(list)
		self.V = vertices

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

	def connectedComponents(self):
		unvisited = set(range(self.V))
		queue = deque()
		count = 0
		while len(unvisited) > 0:
			count += 1
			v = next(iter(unvisited))
			unvisited.remove(v)
			queue.append(v)
			while len(queue) > 0:
				v = queue.popleft()
				for w in self.graph[v]:
					if w in unvisited:
						unvisited.remove(w)
						queue.append(w)
		return count

def maxSumIS(arr, n):
	msis = arr.copy()
	for i in range(1, n):
		for j in range(i):
			if arr[i] > arr[j] and msis[i] < msis[j] + arr[i]:
				msis[i] = msis[j] + arr[i]
	c = max(msis)
	p = 5
	return c

def binarysearch2(arr, target):
	lo = 0
	hi = len(arr) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if arr[mid] == target:
			if mid != len(arr) - 1:
				if arr[mid + 1] != target:
					return mid
				else:
					lo += 1
			else:
				return mid
			continue
		if arr[mid] > target:
			hi = mid - 1
		else:
			lo = mid + 1

def nge(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) > 0:
				if stack[-1][0] < arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def nse(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) > 0:
				if stack[-1][0] > arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def alperm(nums, path, result):
	if not nums:
		result.add(tuple(path))
		return
	for i in range(0, len(nums)):
		alperm(nums[:i] + nums[i + 1:], path + [nums[i]], result)
	return result

def minsum(arr, n, m, res, l):
	if n == 1 and m == 1:
		res += arr[0][0]
		l.append(res)
	else:
		if n != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n - 1, m, p, l)
		if m != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n, m - 1, p, l)
	return min(l)

def catalan(n):
	if n == 0 or n == 1:
		return 1
	catalan = [0] * (n + 1)
	catalan[0] = 1
	catalan[1] = 1
	for i in range(2, n + 1):
		for j in range(i):
			catalan[i] += catalan[j] * catalan[i - j - 1]
	return catalan[n]

def find_shortest_path(graph, start, end, path):
	path = path + [start]
	if start == end:
		return path
	if start not in graph:
		return None
	shortest = None
	for node in graph[start]:
		if node not in path:
			newpath = find_shortest_path(graph, node, end, path)
			if newpath:
				if not shortest or len(newpath) < len(shortest):
					shortest = newpath
	return shortest

def test(n, d):
	a = random.randint(1, n - 2)
	p = pow(a, d, n)
	if p == 1 or p == n - 1:
		return True
	while d != n - 1:
		d *= 2
		p = pow(p, 2, n)
		if p == n - 1:
			return True
	return False

def isprime(n):
	if n == 1:
		return False
	if n == 2:
		return True
	if n == 3:
		return True
	d = n - 1
	while d % 2 == 0:
		d //= 2
	for i in range(5):
		if test(n, d) == False:
			return False
	return True

def muin(a, m):
	(x, y, mo) = (1, 0, m)
	if m == 1:
		return 0
	while m > 0:
		(x, y) = (y, x - a // m * y)
		(a, m) = (m, a % m)
	if x < 0:
		return mo + x
	else:
		return x

def good(l, c):
	ch = chr(c)
	if len(l) == 1:
		return 1 if ch != l[0] else 0
	k = len(l) // 2
	lm = k - l[:k].count(ch) + good(l[k:], c + 1)
	rm = k - l[k:].count(ch) + good(l[:k], c + 1)
	return min(lm, rm)

def facto(fact):
	(fact[0], fact[1]) = (1, 1)
	for i in range(2, 10 ** 5 + 1):
		fact[i] = fact[i - 1] * i % M

def comb(n, r, fact):
	return fact[n] * pow(fact[n - r] * fact[r], M - 2, M) % M

def numberToBase(n, b):
	if n == 0:
		return 0
	digits = []
	while n:
		digits.append(n % b)
		n //= b
	return sum(digits)

def main():
	tt = 1
	tt = inpu()
	for _ in range(tt):
		n = inpu()
		a = lis()
		b = lis()
		for i in range(n):
			a[i] = [a[i], i]
			b[i] = [b[i], i]
		a.sort()
		b.sort()
		d = defaultdict(list)
		for i in range(n - 1):
			d[a[i][1]].append(a[i + 1][1])
			d[b[i][1]].append(b[i + 1][1])
		visited = [False] * n

		def dfs(curr):
			visited[curr] = True
			for i in d[curr]:
				if not visited[i]:
					dfs(i)
		dfs(a[-1][1])
		ans = ''
		for i in range(len(visited)):
			if visited[i] == True:
				ans += '1'
			else:
				ans += '0'
		print(ans)
threading.stack_size(2 * 10 ** 8)
threading.Thread(target=main).start()


import sys
import math
from itertools import accumulate

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

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

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

def solve():
	n = int(input())
	ar = read_int_arr()
	br = read_int_arr()
	powers = []
	powers = list(zip(ar, br))
	powers = [(i, a, b) for (i, (a, b)) in enumerate(powers)]
	powers.sort(key=lambda tup: tup[2])
	powers.reverse()
	max_right = []
	maxi = -1
	for i in range(n - 1, -1, -1):
		max_right.append(maxi)
		maxi = max(maxi, powers[i][1])
	max_right.reverse()
	res_indexed = []
	mini_a = -1
	for k in range(n):
		(i, a, b) = powers[k]
		if a > mini_a or max_right[k] > mini_a:
			res_indexed.append((i, True))
			mini_a = a if mini_a == -1 else min(mini_a, a)
		else:
			res_indexed.append((i, False))
	res = ['' for _ in range(n)]
	for (i, boo) in res_indexed:
		res[i] = '1' if boo else '0'
	print(''.join(res))
T = int(input())
for _ in range(T):
	solve()


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from heapq import heappush, heappop, heapify
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

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

def listStr():
	return list(input())

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

def isInt(s):
	return '0' <= s[0] <= '9'

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

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

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
num = getInt()
for _ in range(num):
	n = getInt()
	arr1 = zzz()
	arr2 = zzz()
	lst1 = []
	lst2 = []
	for i in range(n):
		lst1.append((arr1[i], i))
	for i in range(n):
		lst2.append((arr2[i], i))
	lst1.sort()
	lst2.sort()
	d = {}
	ind = -1
	for i in range(n - 1, -1, -1):
		d[lst1[i][1]] = 1
		d[lst2[i][1]] = 1
		if len(d) == n - i:
			ind = i
			break
	ans = [0] * n
	for i in range(ind, n):
		ans[lst1[i][1]] = 1
	print(*ans, sep='')
	print()


from collections import deque
for i in range(int(input())):
	a = int(input())
	b = enumerate([int(x) for x in input().split()], start=1)
	c = enumerate([int(x) for x in input().split()], start=1)
	b = [i[0] for i in sorted(b, key=lambda x: x[1])]
	c = [i[0] for i in sorted(c, key=lambda x: x[1])]
	d1 = {}
	d2 = {}
	for i in range(a):
		d1[b[i]] = i
		d2[c[i]] = i
	winners = set()
	b = deque(b)
	c = deque(c)
	temp = deque([b.pop(), c.pop()])
	while len(temp) > 0:
		q = temp.pop()
		q1 = d1[q]
		q2 = d2[q]
		if len(b) > q1:
			for i in range(q1, len(b)):
				temp.appendleft(b.pop())
		if len(c) > q2:
			for i in range(q2, len(c)):
				temp.appendleft(c.pop())
		winners.add(q)
	for i in range(a):
		if i + 1 in winners:
			print('1', end='')
		else:
			print('0', end='')
	print()


import sys, array, bisect, collections, heapq, itertools, math, functools
sys.setrecursionlimit(100000)

def _r():
	return sys.stdin.buffer.readline()

def rs():
	return _r().decode('ascii').strip()

def rn():
	return int(_r())

def rnt():
	return tuple(map(int, _r().split()))

def rnl():
	return list(rnt())

def rna():
	return array.array('q', rnt())

def pnl(l):
	print(' '.join(map(str, l)))

def solve(n, a, b):
	mi = [[0, 0] for _ in range(n)]
	abo = [sorted(((x, i) for (i, x) in enumerate(a))), sorted(((x, i) for (i, x) in enumerate(b)))]
	for (li, lo) in enumerate(abo):
		for (i, (_, oi)) in enumerate(lo):
			mi[oi][li] = i
	seen = [False] * n
	q = [(0, n - 1)]
	seen[abo[0][n - 1][1]] = True
	while q:
		(li, i) = q.pop()
		index = abo[li][i][1]
		ni = mi[index][1 - li]
		for ii in range(ni + 1, n):
			if seen[abo[1 - li][ii][1]]:
				break
			seen[abo[1 - li][ii][1]] = True
			q.append((1 - li, ii))
	return ''.join(('1' if b else '0' for b in seen))
for _ in range(rn()):
	n = rn()
	a = rnl()
	b = rnl()
	print(solve(n, a, b))


from sys import stdin
from bisect import bisect_left
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
ceil_div = lambda a, b: -(-a // b)
mod = 10 ** 9 + 7
for _ in range(rn()):
	n = rn()
	a = rl()
	b = rl()
	a_index = {a[i]: i for i in range(n)}
	b_index = {b[i]: i for i in range(n)}
	a_sort = sorted(a)
	b_sort = sorted(b)
	ans = [0 for i in range(n)]
	switch = 1
	curr = [a_index[a_sort[-1]]]
	ans[curr[0]] = 1
	while len(curr) > 0:
		new = []
		for index in curr:
			if switch == 1:
				while len(b_sort) > 0 and b_sort[-1] > b[index]:
					new.append(b_index[b_sort.pop()])
			else:
				while len(a_sort) > 0 and a_sort[-1] > a[index]:
					new.append(a_index[a_sort.pop()])
		switch = 0 if switch else 1
		for index in new:
			ans[index] = 1
		curr = new
	print(''.join(map(str, ans)))


from typing import List

def solve(a: List[int], b: List[int]) -> str:
	n = len(a)
	pairs = [(a[i], b[i], i) for i in range(n)]
	sorted_by_a = sorted(pairs)
	sorted_by_b = sorted(pairs, key=lambda p: (p[1], p[0], p[2]))
	visited = [False for _ in range(n)]
	minimal_a = max(a)
	minimal_b = max(b)
	while sorted_by_a and sorted_by_b:
		for p in [sorted_by_a[-1], sorted_by_b[-1]]:
			(a, b, i) = p
			if a >= minimal_a:
				visited[i] = True
			if b >= minimal_b:
				visited[i] = True
			if visited[i]:
				minimal_a = min(minimal_a, a)
				minimal_b = min(minimal_b, b)
		if visited[sorted_by_a[-1][2]]:
			sorted_by_a.pop()
			continue
		if visited[sorted_by_b[-1][2]]:
			sorted_by_b.pop()
			continue
		break
	return ''.join([{False: '0', True: '1'}[v] for v in visited])
T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(a, b))


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		asort = sorted(enumerate(a), key=lambda x: x[1])
		bsort = sorted(enumerate(b), key=lambda x: x[1])
		cnt = [0] * n
		ans = [1] * n
		plusSum = 0
		minusSum = 0
		for i in range(n):
			(p, _) = asort.pop()
			if cnt[p] == 0:
				plusSum += 1
				cnt[p] = 1
			else:
				minusSum -= 1
				cnt[p] = 0
			(q, _) = bsort.pop()
			if cnt[q] == 0:
				minusSum += 1
				cnt[q] = -1
			else:
				plusSum -= 1
				cnt[q] = 0
			if plusSum == 0 and minusSum == 0:
				break
		for (p, _) in asort:
			ans[p] = 0
		print(''.join(map(str, ans)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from heapq import heappush, heappop
from collections import deque
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ha = []
	hb = []
	for i in range(n):
		heappush(ha, [-a[i], i])
		heappush(hb, [-b[i], i])
	qa = deque([])
	qb = deque([])
	x = heappop(ha)
	qb.append(x[1])
	ans = ['0' for i in range(n)]
	va = [0 for i in range(n)]
	vb = [0 for i in range(n)]
	va[x[1]] = 1
	ans[x[1]] = '1'
	while True:
		if len(qb) == 0 and len(qa) == 0:
			break
		if len(qb) > 0:
			x = qb.popleft()
			if vb[x] == 1:
				continue
			while len(hb) > 0 and hb[0][1] != x:
				y = heappop(hb)
				qa.append(y[1])
				ans[y[1]] = '1'
				vb[y[1]] = 1
			heappop(hb)
		if len(qa) > 0:
			x = qa.popleft()
			if va[x] == 1:
				continue
			while len(ha) > 0 and ha[0][1] != x:
				y = heappop(ha)
				qb.append(y[1])
				ans[y[1]] = '1'
				va[y[1]] = 1
			heappop(ha)
	print(''.join(ans))


for _ in range(int(input())):
	n = int(input())
	x = [(int(i[1]), i[0]) for i in enumerate(input().split())]
	y = [(int(i[1]), i[0]) for i in enumerate(input().split())]
	x = sorted(x, reverse=True)
	y = sorted(y, reverse=True)
	q = set()
	for i in range(n):
		q.add(x[i][1])
		q.add(y[i][1])
		if len(q) == i + 1:
			break
	ans = ['0'] * n
	for i in q:
		ans[i] = '1'
	print(''.join(ans))


from sys import stdin, stdout

def solve_test(n: int, a: list, b: list):
	sorted_first = sorted([(a, i) for (i, a) in enumerate(a)])
	sorted_second = sorted([(b, i) for (i, b) in enumerate(b)])
	graph = [set() for _ in range(n)]
	for (index, (x, i)) in enumerate(sorted_first):
		if index + 1 < n:
			graph[i].add(sorted_first[index + 1][1])
	for (index, (x, i)) in enumerate(sorted_second):
		if index + 1 < n:
			graph[i].add(sorted_second[index + 1][1])
	visited = [False] * n
	stack = [sorted_first[n - 1][1]]
	while len(stack) > 0:
		index = stack.pop()
		visited[index] = True
		for neighbour in graph[index]:
			if not visited[neighbour]:
				stack.append(neighbour)
	stdout.write(''.join([str(int(value)) for value in visited]) + '\n')

def read_from_file():
	with open('input.txt') as f:
		tests = int(f.readline().strip())
		for test in range(tests):
			n = int(f.readline().strip())
			lista = [int(x) for x in f.readline().strip().split()]
			listb = [int(x) for x in f.readline().strip().split()]
			solve_test(n, lista, listb)

def read_from_input():
	tests = int(stdin.readline().strip())
	for test in range(tests):
		n = int(input())
		lista = [int(x) for x in stdin.readline().strip().split()]
		listb = [int(x) for x in stdin.readline().strip().split()]
		solve_test(n, lista, listb)
read_from_input()


t = int(input())
out = ''
for _ in range(t):
	n = int(input())
	a = [[int(x)] for x in input().split()]
	b = [[int(x)] for x in input().split()]
	order = [[a[i][0], b[i][0]] for i in range(n)]
	for i in range(n):
		a[i].append(b[i][0])
		b[i].append(a[i][0])
	a.sort()
	b.sort()
	i = n - 1
	j = n - 1
	min1 = a[i][0]
	min2 = b[i][0]
	while i >= 0 or j >= 0:
		if i >= 0 and a[i][0] >= min1:
			min2 = min(min2, a[i][1])
			i -= 1
		elif j >= 0 and b[j][0] >= min2:
			min1 = min(min1, b[j][1])
			j -= 1
		else:
			break
	for (g1, g2) in order:
		out += str(int(g1 >= min1 or g2 >= min2))
	out += '\n'
print(out)


import sys
input = sys.stdin.readline
for _ in ' ' * int(input()):
	n = int(input())
	L1 = list(map(int, input().split()))
	L2 = list(map(int, input().split()))
	Lpair = []
	for i in range(n):
		Lpair.append([L1[i], L2[i]])
	Lpair.sort()
	d1 = dict()
	mi = 10 ** 9 + 1
	for i in range(n - 1, -1, -1):
		mi = min(mi, Lpair[i][1])
		d1[Lpair[i][0]] = mi
	for i in range(n):
		(Lpair[i][0], Lpair[i][1]) = (Lpair[i][1], Lpair[i][0])
	Lpair.sort()
	d2 = dict()
	mi = 10 ** 9 + 1
	for i in range(n - 1, -1, -1):
		mi = min(mi, Lpair[i][1])
		d2[Lpair[i][0]] = mi
	amin = Lpair[-1][1]
	bmin = 10 ** 9 + 1
	while True:
		bperm = min(d1[amin], bmin)
		aperm = min(d2[bperm], amin)
		if (aperm, bperm) == (amin, bmin):
			break
		(amin, bmin) = (aperm, bperm)
	for i in range(n):
		if L1[i] >= amin or L2[i] >= bmin:
			print('1', end='')
		else:
			print('0', end='')
	print()


import sys, os, io
input = sys.stdin.readline
PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def bin32(num):
	return '{0:032b}'.format(num)

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

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

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

def ls():
	return [i for i in input().split()]
for t in range(ii()):
	t += 1
	n = ii()
	a = li()
	b = li()
	store = [[a[i], b[i], i] for i in range(n)]
	store.sort()
	dp = ['0' for i in range(n)]
	dp[store[-1][2]] = '1'
	maxi = [0 for i in range(n)]
	maxi[0] = store[0][1]
	for i in range(1, n):
		maxi[i] = max(maxi[i - 1], store[i][1])
	mini = store[-1][1]
	for i in range(n - 2, -1, -1):
		if mini < maxi[i]:
			dp[store[i][2]] = '1'
		else:
			break
		mini = min(mini, store[i][1])
	dp = ''.join(dp)
	print(dp)


from sys import stdin, stdout, setrecursionlimit
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
from heapq import heapify, heappush, heappop, heappushpop
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sumx = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7

def bfs(x):
	stk = deque([x])
	ans[x] = 1
	while stk:
		x = stk.pop()
		for i in v[x]:
			if not ans[i]:
				ans[i] = 1
				stk += (i,)
for _ in range(I()):
	n = I()
	a = L()
	b = L()
	ans = [0] * n
	v = [[] for i in range(n)]
	x = sorted(enumerate(a), key=lambda p: p[1])
	y = sorted(enumerate(b), key=lambda p: p[1])
	for i in range(n - 1):
		v[x[i][0]] += (x[i + 1][0],)
		v[y[i][0]] += (y[i + 1][0],)
	bfs(x[-1][0])
	print(*ans, sep='')


from sys import stdin, stdout, setrecursionlimit
from io import BytesIO, IOBase
from collections import Counter, deque, defaultdict
setrecursionlimit(10000)

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
input = lambda : stdin.readline().rstrip('\r\n')
inp = lambda : int(input())
st = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
int_arr = lambda : list(map(int, input().strip().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().strip().split())
get_int = lambda : map(int, input().strip().split())
get_float = lambda : map(float, input().strip().split())
mod = 1000000007

def solve():
	n = inp()
	a = int_arr()
	b = int_arr()
	vis = [False] * n
	ans = [0] * n
	a = [(a[i], i) for i in range(n)]
	b = [(b[i], i) for i in range(n)]
	a.sort(reverse=True)
	b.sort(reverse=True)
	dic = defaultdict(list)
	for i in range(n - 1):
		dic[a[i + 1][1]].append(a[i][1])
		dic[b[i + 1][1]].append(b[i][1])
	q = [a[0][1], b[0][1]]
	q = deque(q)
	for i in q:
		vis[i] = True
	while len(q) > 0:
		ind = q.popleft()
		ans[ind] = 1
		for i in dic[ind]:
			if vis[i] == True:
				continue
			q.append(i)
			vis[i] = True
	print(*ans, sep='')
for _ in range(inp()):
	solve()


import sys
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
mod = 10 ** 9 + 7
mod1 = 998244353
for _ in range(ii()):
	n = ii()
	a = il()
	b = il()
	ans = ['0' for i in range(n)]
	ind = -1
	ind1 = -1
	x = max(a)
	y = max(b)
	for i in range(n):
		if a[i] == x:
			ind = i
		if b[i] == y:
			ind1 = i
	if ind == ind1:
		ans[ind] = '1'
		print(''.join(ans))
		continue
	c = [[a[i], i] for i in range(n)]
	d = [[b[i], i] for i in range(n)]
	c.sort(reverse=True)
	d.sort(reverse=True)
	r = a[d[0][1]]
	r1 = b[c[0][1]]
	i = 0
	j = 0
	while i < n and j < n:
		fl = 0
		if c[i][0] >= r:
			r1 = min(r1, b[c[i][1]])
			i += 1
			fl = 1
		if d[j][0] >= r1:
			r = min(r, a[d[j][1]])
			j += 1
			fl = 1
		if fl == 0:
			break
	for i in range(n):
		if r <= c[i][0]:
			ans[c[i][1]] = '1'
	for i in range(n):
		if r1 <= d[i][0]:
			ans[d[i][1]] = '1'
	print(''.join(ans))


from collections import deque
from typing import DefaultDict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	asort = sorted([(a[i], i) for i in range(n)])
	b = list(map(int, input().split()))
	bsort = sorted([(b[i], i) for i in range(n)])
	ans = [0] * n
	memo = DefaultDict(lambda : set([]))
	for i in range(n - 1):
		memo[asort[i][1]].add(asort[i + 1][1])
		memo[bsort[i][1]].add(bsort[i + 1][1])
	visited = set([asort[-1][1]])
	queue = deque([asort[-1][1]])
	ans[asort[-1][1]] = 1
	while queue:
		curr = queue.popleft()
		for adj in memo[curr]:
			if not ans[adj]:
				queue.append(adj)
				ans[adj] = 1
	print(*ans, sep='')


import sys
T = int(sys.stdin.readline().strip())
for t in range(T):
	n = int(sys.stdin.readline().strip())
	a = list(map(int, sys.stdin.readline().strip().split()))
	b = list(map(int, sys.stdin.readline().strip().split()))
	ai = [(a[i], i) for i in range(0, n)]
	bi = [(b[i], i) for i in range(0, n)]
	ai.sort(reverse=True)
	bi.sort(reverse=True)
	x = 0
	y = 0
	L = [ai[0][1], bi[0][1]]
	while len(L) > 0:
		i = L.pop()
		if x == n - 1 or y == n - 1:
			L = []
			print('1' * n)
			break
		while ai[x + 1][0] >= a[i]:
			x = x + 1
			L.append(ai[x][1])
			if x == n - 1:
				break
		while bi[y + 1][0] >= b[i]:
			y = y + 1
			L.append(bi[y][1])
			if y == n - 1:
				break
	if x != n - 1 and y != n - 1:
		wina = [ai[i][1] for i in range(0, x + 1)]
		winb = [bi[i][1] for i in range(0, y + 1)]
		win = set(wina + winb)
		print(''.join([str(int(i in win)) for i in range(0, n)]))


import functools

def reader():
	a = [int(v) for v in input().split(' ')]
	unsort_a = a[:]
	a = [i for i in range(len(a))]
	cmp = lambda x, y: unsort_a[x] - unsort_a[y]
	a.sort(key=functools.cmp_to_key(cmp))
	return (unsort_a, a)

def solve(n):
	(unsort_a, a) = reader()
	(unsort_b, b) = reader()
	l = n - 1
	cnt = [0] * n
	need = 0
	ans = [False] * n
	while l >= 0:
		aidx = a[l]
		bidx = b[l]
		cnt[aidx] += 1
		cnt[bidx] -= 1
		ans[aidx] = True
		ans[bidx] = True
		if aidx != bidx:
			need += 2
			if cnt[aidx] == 0:
				need -= 2
			if cnt[bidx] == 0:
				need -= 2
		if need == 0:
			break
		l -= 1
	assert need == 0
	print(''.join(['1' if i else '0' for i in ans]))
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	solve(n)


import sys
input = sys.stdin.readline

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

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

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	a = lis()
	b = lis()
	r = []
	r1 = []
	for i in range(n):
		r.append([a[i], i])
		r1.append([b[i], i])
	r.sort(reverse=True)
	r1.sort(reverse=True)
	fi = set()
	se = set()
	vis = [0] * n
	vis[r[0][1]] = 1
	vis[r1[0][1]] = 1
	for i in range(n):
		if r[i][1] != r1[i][1]:
			vis[r[i][1]] = 1
			vis[r1[i][1]] = 1
			if r[i][1] in se:
				se.remove(r[i][1])
			else:
				fi.add(r[i][1])
			if r1[i][1] in fi:
				fi.remove(r1[i][1])
			else:
				se.add(r1[i][1])
		else:
			vis[r[i][1]] = 1
		if len(fi) == len(se) and len(fi) == 0:
			break
	print(*vis, sep='')


import sys, os, io
import math
from bisect import bisect_right
from collections import defaultdict

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

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
xx = []
pp = []
dicti = defaultdict(lambda : -1)
cnt = 0

@bootstrap
def DFSUtil(v, visited, graph):
	global xx
	visited[v] = True
	xx.append(v)
	for i in graph[v]:
		if visited[i] == False:
			yield DFSUtil(i, visited, graph)
	yield

@bootstrap
def fillOrder(v, visited, stack, graph):
	visited[v] = True
	for i in graph[v]:
		if visited[i] == False:
			yield fillOrder(i, visited, stack, graph)
	stack = stack.append(v)
	yield

def getTranspose(graph, n):
	tg = [[] for i in range(n)]
	for i in range(len(graph)):
		for j in graph[i]:
			tg[j].append(i)
	return tg

def printSCCs(n, graph):
	global xx, pp, cnt
	stack = []
	visited = [False] * n
	for i in range(n):
		if visited[i] == False:
			fillOrder(i, visited, stack, graph)
	gr = getTranspose(graph, n)
	visited = [False] * n
	cnt = 0
	while stack:
		i = stack.pop()
		if visited[i] == False:
			DFSUtil(i, visited, gr)
			pp = xx[:]
			for j in xx:
				dicti[j] = cnt
			xx = []
			cnt += 1
	newg = [[] for i in range(n)]
	for i in range(n):
		for j in gr[i]:
			newg[dicti[i]].append(dicti[j])
	for i in range(n):
		newg[i] = list(set(newg[i]))
	node = cnt - 1
	vis = [False] * n
	vis[node] = True
	st = [node]
	while st:
		node = st.pop(-1)
		for kid in newg[node]:
			if vis[kid] == False:
				vis[kid] = True
				st.append(kid)
	res = ['0'] * n
	if vis.count('False') == 0:
		for i in pp:
			res[i] = '1'
	print(''.join(res))

def solve():
	n = ii()
	a = li()
	b = li()
	first = []
	second = []
	first = a[:]
	second = b[:]
	d1 = {}
	d2 = {}
	e = defaultdict(lambda : 0)
	for i in range(n):
		d1[a[i]] = i
		d2[b[i]] = i
	first.sort()
	second.sort()
	g = [[] for i in range(n)]
	for i in range(n):
		p1 = bisect_right(first, a[i])
		if p1 < n:
			p1 = d1[first[p1]]
			if e[i, p1] == 0:
				g[i].append(p1)
				e[i, p1] = 1
		p2 = bisect_right(second, b[i])
		if p2 < n:
			p2 = d2[second[p2]]
			if e[i, p2] == 0:
				g[i].append(p2)
				e[i, p2] = 0
	printSCCs(n, g)
t = 1
t = ii()
for _ in range(t):
	solve()


import sys
printer = []
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	a = sorted([(int(s), i) for (i, s) in enumerate(sys.stdin.readline().split())], reverse=True)
	b = sorted([(int(s), i) for (i, s) in enumerate(sys.stdin.readline().split())], reverse=True)
	nodes = set()
	for i in range(n):
		nodes.add(a[i][1])
		nodes.add(b[i][1])
		if len(nodes) == i + 1:
			break
	printer.append(''.join(['1' if i in nodes else '0' for i in range(n)]))
print('\n'.join(printer))


import sys
inpu = sys.stdin.readline
prin = sys.stdout.write
t = int(inpu())
for _ in range(t):
	n = int(inpu())
	a = list(map(int, inpu().split()))
	b = list(map(int, inpu().split()))
	tups = []
	tups1 = []
	for i in range(n):
		tups.append((a[i], b[i], i))
		tups1.append((b[i], a[i], i))
	tups.sort(reverse=True)
	tups1.sort(reverse=True)
	unseen = set()
	unseen1 = set()
	for i in range(n):
		if tups[i][2] in unseen1:
			unseen1.remove(tups[i][2])
		else:
			unseen.add(tups[i][2])
		if tups1[i][2] in unseen:
			unseen.remove(tups1[i][2])
		else:
			unseen1.add(tups1[i][2])
		if len(unseen) == 0:
			break
	out = [0] * n
	for j in range(i + 1):
		out[tups[j][2]] = 1
	print(''.join((str(guy) for guy in out)))


T = int(input())
for testcase in range(1, T + 1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aa = a.copy()
	aa.sort()
	ai = [i[0] for i in sorted(enumerate(a), key=lambda x: x[1])]
	bb = b.copy()
	bb.sort()
	bi = [i[0] for i in sorted(enumerate(b), key=lambda x: x[1])]
	res = [0 for i in range(n)]
	awin = a[bi[n - 1]]
	bwin = b[ai[n - 1]]
	res[ai[n - 1]] = 1
	res[bi[n - 1]] = 1
	aindex = n - 2
	bindex = n - 2
	found = True
	while found:
		found = False
		while aa[aindex] > awin:
			res[ai[aindex]] = 1
			if b[ai[aindex]] < bwin:
				bwin = b[ai[aindex]]
				found = True
			aindex -= 1
		while bb[bindex] > bwin:
			res[bi[bindex]] = 1
			if a[bi[bindex]] < awin:
				awin = a[bi[bindex]]
				found = True
			bindex -= 1
	result = ''.join((str(i) for i in res))
	print(result)


from sys import stdin, stdout, setrecursionlimit
stdin.readline

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

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
from math import ceil, gcd, sqrt, factorial, log2, floor
from bisect import bisect_right as br, bisect_left as bl
from heapq import *
mod = 10 ** 9 + 7
inf = 1 << 60
for _ in range(it()):
	n = it()
	a = mp()
	b = mp()
	if n == 1:
		print(1)
		continue
	a = [(a[i], i) for i in range(n)]
	a.sort()
	ans = ['0'] * n
	mi = b[a[-1][1]]
	mx = [0] * n
	mx[0] = b[a[0][1]]
	for i in range(1, n):
		mx[i] = max(mx[i - 1], b[a[i][1]])
	for i in range(n - 1, -1, -1):
		if mx[i] >= mi:
			ans[a[i][1]] = '1'
			mi = min(mi, b[a[i][1]])
	print(''.join(ans))


import functools

def reader():
	a = [int(v) for v in input().split(' ')]
	unsort_a = a[:]
	a = [i for i in range(len(a))]
	cmp = lambda x, y: unsort_a[x] - unsort_a[y]
	a.sort(key=functools.cmp_to_key(cmp))
	return (unsort_a, a)

def solve(n):
	(unsort_a, a) = reader()
	(unsort_b, b) = reader()
	l = n - 1
	cnt = [0] * n
	need = 0
	ans = [False] * n
	mina = unsort_a[a[n - 1]]
	minb = unsort_b[b[n - 1]]
	(i, j) = (n - 1, n - 1)
	ans[a[i]] = ans[b[j]] = True
	while True:
		change = False
		while j >= 0 and unsort_b[b[j]] >= minb:
			mina = min(mina, unsort_a[b[j]])
			ans[b[j]] = True
			change = True
			j -= 1
		while i >= 0 and unsort_a[a[i]] >= mina:
			minb = min(minb, unsort_b[a[i]])
			ans[a[i]] = True
			change = True
			i -= 1
		if not change:
			break
	print(''.join(['1' if i else '0' for i in ans]))
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	solve(n)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	arr1 = []
	arr2 = []
	for i in range(n):
		arr1.append([a[i], i])
		arr2.append([b[i], i])
	arr1.sort()
	arr2.sort()
	d = {}
	ind = -1
	for i in range(n - 1, -1, -1):
		d[arr1[i][1]] = 1
		d[arr2[i][1]] = 1
		if len(d) == n - i:
			ind = i
			break
	ans = [0 for i in range(n)]
	for i in range(ind, n):
		ans[arr1[i][1]] = 1
	print(*ans, sep='')
t = int(input())
for tc in range(t):
	solve()


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		if n == 1:
			print(1)
			continue
		for i in range(n):
			a[i] = (a[i], i)
		a.sort()
		ans = ['0'] * n
		miw = b[a[-1][1]]
		ma = [0] * n
		ma[0] = b[a[0][1]]
		for i in range(1, n):
			ma[i] = max(ma[i - 1], b[a[i][1]])
		for i in range(n - 1, -1, -1):
			if ma[i] >= miw:
				ans[a[i][1]] = '1'
				miw = min(miw, b[a[i][1]])
		print(''.join(ans))
main()


import collections
import math
import itertools
import sys
import time
import random

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

def ints_input():
	return list((int(x) for x in input().split()))

def int_input():
	return int(input())

def solve():
	n = int_input()
	player_to_a = ints_input()
	player_to_b = ints_input()
	players_by_a = sorted(list(range(len(player_to_a))), key=lambda x: player_to_a[x])
	players_by_b = sorted(list(range(len(player_to_b))), key=lambda x: player_to_b[x])
	player_to_a = {v: k for (k, v) in enumerate(players_by_a)}
	player_to_b = {v: k for (k, v) in enumerate(players_by_b)}
	old_max_a = n
	old_max_b = n
	max_b = players_by_b[-1]
	max_a = players_by_a[-1]
	players_winning = {max_b, max_a}
	(max_a, max_b) = (player_to_a[max_b], player_to_b[max_a])
	while True:
		new_max_a = max_a
		new_max_b = max_b
		f = False
		for i in range(max_a, old_max_a):
			if players_by_a[i] not in players_winning:
				players_winning.add(players_by_a[i])
				new_max_b = min(new_max_b, player_to_b[players_by_a[i]])
				f = True
		for i in range(max_b, old_max_b):
			if players_by_b[i] not in players_winning:
				players_winning.add(players_by_b[i])
				new_max_a = min(new_max_a, player_to_a[players_by_b[i]])
				f = True
		if not f:
			break
		(old_max_a, old_max_b) = (max_a, max_b)
		(max_a, max_b) = (new_max_a, new_max_b)
	answers = [str(int(i in players_winning)) for i in range(n)]
	print(''.join(answers))
if True:
	for _ in range(int_input()):
		solve()
else:
	solve()


import sys
import pprint
import logging
from logging import getLogger

def input():
	return sys.stdin.readline().rstrip('\r\n')
logging.basicConfig(format='%(message)s', level=logging.WARNING)
logger = getLogger(__name__)
logger.setLevel(logging.INFO)

def debug(msg, *args):
	logger.info(f'{msg}={pprint.pformat(args)}')
from heapq import heapify, heappush, heappop

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	arr = list(enumerate(zip(a, b)))
	(p1, p2) = (sorted(arr, key=lambda x: x[1][0], reverse=True), sorted(arr, key=lambda x: x[1][1], reverse=True))
	gr = [set() for _ in range(n)]
	for _ in range(n - 1):
		(i, j) = (p1[_][0], p1[_ + 1][0])
		gr[i].add(j)
		(i, j) = (p2[_][0], p2[_ + 1][0])
		gr[i].add(j)
	rev_gr = [set() for _ in range(n)]
	for i in range(n):
		for j in gr[i]:
			rev_gr[j].add(i)
	vis = set()
	st = p1[0][0]
	q = [st]
	vis.add(st)
	for x in q:
		for v in rev_gr[x]:
			if v in vis:
				continue
			vis.add(v)
			q.append(v)
	for i in range(n):
		if i in vis:
			print('1', end='')
		else:
			print('0', end='')
	print()
for i in range(int(input())):
	solve()


from collections import deque, defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	pairs = [(a[i], b[i], i) for i in range(n)]
	sorta = sorted(pairs)
	sortb = sorted(pairs, key=lambda x: (x[1], x[0], x[2]))
	vis = [False] * n
	ma = max(a)
	mb = max(b)
	while sorta and sortb:
		for p in [sorta[-1], sortb[-1]]:
			(a, b, i) = p
			if a >= ma:
				vis[i] = True
			if b >= mb:
				vis[i] = True
			if vis[i]:
				ma = min(ma, a)
				mb = min(mb, b)
		if vis[sorta[-1][2]]:
			sorta.pop()
			continue
		if vis[sortb[-1][2]]:
			sortb.pop()
			continue
		break
	ans = ''
	for i in vis:
		if i:
			ans += '1'
		else:
			ans += '0'
	print(ans)