Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...

The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).

In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.

Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.

Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.

Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.


-----Input-----

The first line contains the integer $t$ ($1 \le t \le 10^4$) — the number of test cases. 

Next $2t$ lines contain test cases — one per two lines.

The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$) — the length of the string $s$.

The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.

It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.


-----Output-----

Print $t$ answers — one per test case.

The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).


-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1

Output
0001111111
001
01
0
1



-----Note-----

In the first test case, Lee can't perform any moves.

In the second test case, Lee should erase $s_2$.

In the third test case, Lee can make moves, for example, in the following order: 11001101 $\rightarrow$ 1100101 $\rightarrow$ 110101 $\rightarrow$ 10101 $\rightarrow$ 1101 $\rightarrow$ 101 $\rightarrow$ 01.

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Implementation

Greedy algorithms


Solutions:
t = int(input())
for T in range(t):
	n = int(input())
	s = input()
	p = s.find('10')
	if p == -1:
		print(s)
	else:
		odin = s.find('1')
		nol = s.rfind('0')
		s1 = s[:odin] + '0' + s[nol + 1:]
		print(s1)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	length = len(s)
	prefix_one = suffix_z = -1
	for (i, c) in enumerate(s):
		if c == '1':
			prefix_one = i
			break
	for i in range(length - 1, -1, -1):
		if s[i] == '0':
			suffix_z = i
			break
	if prefix_one == -1 or suffix_z == -1 or prefix_one == suffix_z + 1:
		print(s)
		continue
	ans = s[:prefix_one] + '0' + s[suffix_z + 1:]
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	l = 0
	while l < n and s[l] == '0':
		l += 1
	r = n - 1
	while r >= 0 and s[r] == '1':
		r -= 1
	if r < l:
		print(s)
	else:
		print(s[0:l] + ('0' if s[l:r + 1].count('0') > 0 else '1') + s[r + 1:])
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	stack = [s[n - 1]]
	i = n - 2
	zero = None
	one = None
	for i in range(n):
		if s[i] == '1':
			one = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			zero = i
			break
	if zero == None or one == None:
		print(s)
	elif zero < one:
		print(s)
	else:
		ans = ''
		for i in range(n):
			if i >= one and i < zero:
				continue
			else:
				ans += s[i]
		print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(lef, ri, sw) = (0, 0, 0)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			sw = 1
			break
	if sw == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			lef = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			ri = i
			break
	print(s[:lef] + '0' + s[ri + 1:])


T = int(input())
for _ in range(T):
	n = int(input())
	st = input()
	count = 0
	flag1 = False
	mark1 = -1
	mark2 = -1
	for i in range(n):
		if not flag1 and st[i] == '0':
			mark1 = i
		if st[i] == '0':
			mark2 = i
		if st[i] == '1' and i != n - 1 and (st[i + 1] == '0'):
			count += 1
			flag1 = True
	res = ''
	for _ in range(mark1 + 1):
		res += '0'
	if count >= 1:
		res += '0'
	for _ in range(n - (mark2 + 1)):
		res += '1'
	print(res)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if s.find('10') != -1:
		(s1, s2) = ('', '')
		for i in range(len(s)):
			if s[i] == '1':
				break
			s1 += s[i]
		for i in s[::-1]:
			s2 += i
			if i == '0':
				break
		print(s1 + s2[::-1])
	else:
		print(s)


t = int(input())
for i in range(t):
	n = int(input())
	b = input()
	a = -1
	c = 0
	if '10' in b:
		for j in range(len(b)):
			if b[j] == '1':
				if a < 0:
					a = j
			else:
				c = j
		b = b[:a] + b[c:]
		print(b)
	else:
		print(b)


for t in range(int(input())):
	n = int(input())
	s = input()
	ans = ''
	status = [True] * n
	flag = True
	for i in range(n - 1, -1, -1):
		status[i] = flag
		if s[i] == '0':
			flag = False
	flag1 = False
	for i in range(n):
		if s[i] == '1':
			flag1 = True
			if status[i] == True:
				ans += s[i]
		elif flag1 == False or status[i] == True:
			ans += s[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	k = input()
	flag = 0
	for i in range(1, len(k)):
		if k[i - 1] > k[i]:
			flag = 1
			break
	if flag == 0:
		print(k)
		continue
	zero = 0
	one = 0
	for j in range(len(k)):
		if k[j] == '0':
			zero += 1
		else:
			break
	for j in range(len(k) - 1, -1, -1):
		if k[j] == '1':
			one += 1
		else:
			break
	print('0' * zero + '0' + '1' * one)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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))
mod = 1000000007

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 graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def sieve(a):
	for i in range(3, 10 ** 6 + 1, 2):
		a[i] = 1
	for i in range(3, 10 ** 6 + 1, 2):
		for j in range(i * i, 10 ** 6 + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def solve():
	n = int(inp())
	s = list(inp())
	i = 0
	while i < len(s) - 1 and i >= 0:
		if s[i] == '1' and s[i + 1] == '0':
			j = i
			ind = [-1, -1]
			j = s.index('1')
			ind[0] = j
			j = i + 1
			new = s[::-1]
			j = new.index('0')
			j = n - 1 - j
			ind[1] = j
			s = s[:ind[0]] + s[ind[1]:]
			i = ind[0]
		else:
			i += 1
		if len(s) == 0:
			break
	ans = ''
	for i in range(0, len(s)):
		ans += s[i]
	print(ans)
testcase(int(inp()))


t = int(input())
for i in range(t):
	n = int(input())
	inp = input()
	(cnt1, cnt2) = (0, 0)
	(l, r) = (0, 0)
	initZeros = 0
	lastOnes = 0
	for m in range(len(inp)):
		if inp[m] == '0':
			initZeros = initZeros + 1
		else:
			break
	for n in range(len(inp) - 1, -1, -1):
		if inp[n] == '1':
			lastOnes = lastOnes + 1
		else:
			break
	if initZeros == len(inp) or lastOnes == len(inp) or len(inp) - initZeros == lastOnes:
		print(inp)
		continue
	else:
		for j in range(initZeros + 1):
			print('0', end='')
		for k in range(lastOnes):
			print('1', end='')
	print()


def solve(n, s):
	is_present_10 = False
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			is_present_10 = True
			break
	if not is_present_10:
		return s
	i = 0
	while i < n and s[i] == '0':
		i += 1
	leading_zeroes = i
	i = n - 1
	while i >= 0 and s[i] == '1':
		i -= 1
	trailing_ones = n - i - 1
	return '0' * leading_zeroes + '0' + '1' * trailing_ones
t = int(input())
results = list()
for _ in range(t):
	n = int(input())
	s = input()
	results.append(solve(n, s))
for result in results:
	print(result)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
ans = []
t = ini()
for _ in range(t):
	n = ini()
	s = ins()
	start = 0
	end = 0
	for i in range(n):
		if s[i] == '0':
			start += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			end += 1
		else:
			break
	if start + end == n:
		ans.append(s)
	else:
		ans.append('0' * start + '0' + '1' * end)
print('\n'.join(ans))


def solver(m, t):
	if '1' not in t:
		return t
	else:
		(ans, temp) = ('', '')
		ind = 0
		for i in range(m):
			if t[i] == '0':
				temp += t[i]
			else:
				ind = i
				break
		for i in range(n - 1, ind - 1, -1):
			if t[i] == '1':
				ans += t[i]
			else:
				ans += '0'
				break
		ans = ans[::-1]
		temp += ans
		return temp
for _ in range(int(input())):
	n = int(input())
	s = input()
	print(solver(n, s))


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

def main():
	for _ in range(int(input())):
		n = int(input())
		st = list(input())
		s = -1
		end = -1
		counter = 0
		for i in range(n):
			if st[i] == '1':
				s = i
				break
		new = st[::-1]
		for i in range(n):
			if new[i] == '0':
				end = n - i - 1
				break
		if s < end:
			res = st[0:s] + ['0'] + st[end + 1:n]
			print(''.join(res))
		else:
			print(''.join(st))
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()


cases = int(input())
for t in range(cases):
	n = int(input())
	s = input()
	l = s.find('1')
	r = s.rfind('0')
	if r > l:
		s1 = s[:l] + '0' + s[r + 1:]
		print(s1)
	else:
		print(s)


for _ in range(int(input())):
	n = int(input())
	s = str(input())
	x = s.count('10')
	if n == 1:
		print(s)
	else:
		arr = list(s)
		count1 = 0
		count2 = 0
		for j in range(n):
			if arr[j] == '0':
				count1 += 1
			else:
				break
		arr1 = arr[::-1]
		for z in range(n):
			if arr1[z] == '1':
				count2 += 1
			else:
				break
		if x > 0:
			print(count1 * '0' + '0' + count2 * '1')
		else:
			print(count1 * '0' + count2 * '1')


for _ in range(int(input())):
	n = int(input())
	s = input()
	if '10' not in s:
		print(s)
		continue
	b = s.index('1')
	for i in range(n):
		if s[i] == '0':
			e = i
	k = s[:b] + '0' + s[e + 1:]
	print(k)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	m = input()
	x = 0
	y = n - 1
	while x < n and m[x] == '0':
		x += 1
	while y >= 0 and m[y] == '1':
		y -= 1
	if x > y:
		print(m)
	else:
		for i in range(x):
			print(0, end='')
		for i in range(x, y + 1):
			if m[i] == '0':
				print(0, end='')
				break
		for i in range(y + 1, n):
			print(1, end='')
		print()


import re

def delete_from_str(str, i):
	res = ''
	for (j, el) in enumerate(str):
		if j != i:
			res += el
			res += str[j + 1:]
			break
	return res

def replace_el(str, i, replacer):
	res = ''
	for (j, el) in enumerate(str):
		if j == i:
			res += replacer
			res += str[j + 1:]
			break
		else:
			res += el
	return res

def work_once(s):
	a = 'lala'
	for (i, el) in enumerate(s):
		if el == '0':
			a = i
	if a != 'lala':
		s = replace_el(s, a, '2')
		s = re.sub('(1)(0+)', '1', s)
		s = re.sub('2', '0', s)
		s = re.sub('(1+)(0)', '0', s)
	return s
for t in range(int(input())):
	n = input()
	s = str(input())
	print(work_once(s))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if '10' not in s:
		print(s)
	else:
		a = 0
		b = 0
		for i in range(n):
			if s[i] == '0':
				a += 1
			else:
				break
		for i in range(n):
			if s[n - i - 1] == '1':
				b += 1
			else:
				break
		ans = '0' * (a + 1) + '1' * b
		print(ans)


for i in range(int(input())):
	n = int(input())
	s = input()
	num1 = num2 = 0
	for i in range(n):
		if s[i] != '0':
			break
		num1 += 1
	for i in range(n - 1, -1, -1):
		if s[i] != '1':
			break
		num2 += 1
	if num1 + num2 == n:
		answer = num1 * '0' + num2 * '1'
	else:
		answer = (num1 + 1) * '0' + num2 * '1'
	print(answer)


for _ in range(int(input())):
	n = int(input())
	s = [ch for ch in input()]
	try:
		z = n - s[::-1].index('0') - 1
		o = s.index('1')
		if z < o:
			print(''.join(s))
		else:
			print(''.join(s[0:o] + s[z:]))
	except:
		print(''.join(s))


for _ in ' ' * int(input()):
	(n, a) = (int(input()), input())
	if '10' not in a:
		print(a)
	else:
		(oner, zr, one, z) = (a.rfind('1'), a.rfind('0'), a.find('1'), a.find('0'))
		print('0' + a[zr + 1:] if one < z else a[:one] + '0' + a[zr + 1:])


for _ in range(int(input())):
	n = int(input())
	string = input()
	l = list(string)
	i = n - 1
	while i > 1:
		if len(l) - i >= 1:
			a1 = int(l[i]) - int(l[i - 1])
			a2 = int(l[i - 1]) - int(l[i - 2])
			if a1 == 1 and a2 == -1:
				l.pop(i - 2)
			elif a1 == 0 and a2 == -1:
				l.pop(i)
			elif a1 == -1 and a2 == 0:
				l.pop(i - 1)
			elif a1 == -1 and a2 == 1:
				l.pop(i - 1)
			else:
				i -= 1
		else:
			i -= 1
	if int(l[i]) - int(l[i - 1]) == -1:
		l.pop(i - 1)
	print(''.join((i for i in l)))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ans = ''
	i = 0
	j = 1
	while s[i] == '0':
		ans = ans + '0'
		i += 1
		if n == 1:
			break
		if i == n:
			break
	while s[-j] == '1':
		ans = ans + '1'
		j += 1
		if n == 1:
			break
		if j == n + 1:
			break
	if i < n - j:
		if i > 0 and j > 1:
			ans = ans[:i] + '0' + ans[-j + 1:]
		elif i > 0:
			ans = ans[:i] + '0'
		elif j > 1:
			ans = '0' + ans[-j + 1:]
		else:
			ans = '0'
	print(ans)


from sys import stdin, stdout
from collections import Counter
from collections import defaultdict

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

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

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

def op(ans):
	return stdout.write(str(ans) + '\n')
for i in range(ip()):
	n = ip()
	s = input()
	(l, r, inc) = (1, 1, 0)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			inc += 1
			break
	if inc == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			l = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			r = i + 1
			break
	print(s[:l] + '0' + s[r:])


for ii in range(int(input())):
	m = int(input())
	s = input()
	n = m - 1
	while n >= 0:
		if s[n] == '1':
			n -= 1
		else:
			break
	if n == -1:
		print(s)
	else:
		c = 0
		while c <= n:
			if s[c] == '0':
				c += 1
			else:
				break
		if c == n + 1:
			print(c * '0' + (m - n - 1) * '1')
		else:
			print((c + 1) * '0' + (m - n - 1) * '1')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	f = 0
	a = -1
	b = -1
	for i in range(n):
		if s[i] == '1':
			a = i
			break
	for i in range(n):
		if s[i] == '0':
			b = i
	if a == -1 or b == -1 or a - b == 1:
		print(s)
	else:
		print(s[:a] + '0' + s[b + 1:])


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	p = -1
	q = -1
	for i in range(n):
		if s[i] == '1':
			p = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			q = i
			break
	if q < p:
		print(''.join(s))
	else:
		print(''.join(s[:p] + s[q:]))


for t in range(int(input())):
	n = int(input())
	s = input()
	change = True
	p = n
	(i, j) = (0, n - 1)
	while i < len(s) and s[i] == '0':
		i += 1
	while j >= 0 and s[j] == '1':
		j -= 1
	if i > j:
		print(s)
	else:
		s = s[:i] + '0' + s[j + 1:]
		print(s)


from sys import stdin
input = lambda : stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	n = INT()
	h = input()
	res = ''
	if '10' not in h:
		print(h)
	else:
		for i in range(n):
			if h[i] == '1':
				res += h[:i]
				break
		res += '0'
		for i in range(n):
			if h[n - 1 - i] == '0':
				res += h[n - i:]
				break
		print(res)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	z = []
	o = []
	for j in s:
		if j == '1':
			break
		else:
			z.append('0')
	for j in reversed(s):
		if j == '0':
			break
		else:
			o.append('1')
	if len(z) + len(o) == n:
		print('0' * len(z) + '1' * len(o))
	else:
		print('0' * (1 + len(z)) + '1' * len(o))


for _ in range(int(input())):
	n = int(input())
	a = list(str(input()))
	c = []
	i = 0
	while a[i] == '0' and i < n - 1:
		c.append(a[i])
		i += 1
	d = []
	i = n - 1
	while a[i] == '1' and i > -1:
		d.append(a[i])
		i -= 1
	e = ''.join(c) + ''.join(d)
	if e == ''.join(a):
		print(e)
	else:
		c.append('0')
		print(''.join(c) + ''.join(d))


t = int(input())
for k in range(t):
	int(input())
	a = input()
	f1 = -1
	l0 = -1
	for (i, j) in enumerate(a):
		if j == '1':
			f1 = i
			break
	for (i, j) in enumerate(a):
		if j == '0':
			l0 = i
	if f1 > l0 or f1 < 0 or l0 < 0:
		print(a)
	else:
		print(a[0:f1] + '0' + a[l0 + 1:])


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input()]
	stack = []
	i = 0
	while i < n:
		if not len(stack) or l[i] == 1:
			stack.append([l[i], 0])
			i += 1
		elif stack[-1][0] == 0:
			stack.append([l[i], 0])
			i += 1
		else:
			a = stack.pop()
			if len(stack):
				if stack[-1][0] == 1:
					stack[-1][1] += 1
				else:
					stack.append([1, 1])
					i += 1
			else:
				stack.append([1, 1])
				i += 1
	for i in range(len(stack)):
		if stack[i][0] == 0:
			print('0', end='')
		elif stack[i][1] > 0:
			print('0', end='')
		else:
			print('1', end='')
	print()


def ans(n, a):
	st_zero = 0
	end_one = 0
	x = True
	for i in range(n):
		if a[i] == '1':
			break
		else:
			st_zero += 1
	for i in range(n - 1, -1, -1):
		if a[i] == '0':
			break
		else:
			end_one += 1
	for i in range(n - 1):
		if a[i] == '1' and a[i + 1] == '0':
			x = False
	if x == False:
		st_zero += 1
	st = ''
	for i in range(st_zero):
		st = st + '0'
	for i in range(end_one):
		st = st + '1'
	return st
m = int(input())
for i in range(m):
	n = int(input())
	a = input()
	print(ans(n, a))


import sys
import heapq

def main():
	t = int(input())
	for _ in range(t):
		n = int(sys.stdin.readline().strip())
		s = sys.stdin.readline().strip()
		if '1' in s and '0' not in s or ('1' not in s and '0' in s):
			print(s)
			continue
		lPoint = 0
		while s[lPoint] == '0':
			lPoint += 1
		rPoint = n - 1
		while s[rPoint] == '1':
			rPoint -= 1
		if lPoint > rPoint:
			print(s)
			continue
		if lPoint != n - 1:
			ans = s[:lPoint]
		else:
			ans = ''
		ans += '0'
		if rPoint != n - 1:
			ans += s[rPoint + 1:]
		print(ans)
	return
main()


T = int(input())
for _ in range(T):
	n = int(input())
	s = input().strip()
	j = n - 1
	while j >= 0 and s[j] == '1':
		j -= 1
	i = 0
	while i < n and s[i] == '0':
		i += 1
	if i != j + 1:
		print('0' * i + '0' + '1' * (n - j - 1))
	else:
		print('0' * i + '1' * (n - j - 1))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	x = []
	zero = 0
	one = 0
	for i in range(n):
		if s[i] == '0':
			zero += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			one += 1
		else:
			break
	if n == zero + one:
		print(s)
	else:
		for i in range(zero):
			x.append('0')
		x.append('0')
		for i in range(one):
			x.append('1')
		print(''.join(x))


for _ in range(int(input())):
	n = int(input())
	s = input()
	if ''.join(sorted(s)) == s:
		print(s)
	else:
		print('0' * (s.find('1') + 1) + '1' * (n - 1 - s.rfind('0')))


import sys
I = sys.stdin.readline
ans = ''
for _ in range(int(I())):
	n = int(I())
	s = I().strip()
	if '10' not in s:
		ans += s + '\n'
	else:
		i = 0
		while s[i] == '0':
			i += 1
		y = 0
		s = s[::-1]
		while s[y] == '1':
			y += 1
		ans += '0' * (i + 1) + '1' * y + '\n'
print(ans)


try:
	k = int(input())
	for i in range(k):
		t = input()
		lis = input()
		r = 0
		res = ''
		while r < len(lis) and int(lis[r]) == 0:
			res = res + str(0)
			r += 1
		r = len(lis) - 1
		while r > -1 and int(lis[r]) == 1:
			res = res + '1'
			r -= 1
		if res == '':
			print('0')
		elif len(res) != len(lis):
			res = '0' + res
			print(res)
		else:
			print(res)
except Exception:
	pass


t = int(input())
i = 0
while i < t:
	result = str()
	last = -1
	n = int(input())
	binary = input()
	j = n - 1
	while j >= 0:
		if binary[j] == '0':
			last = j
			break
		j -= 1
	j = 0
	while j < n:
		if binary[j] == '1':
			if last != -1 and j < last:
				j = last
		result = result + binary[j]
		j += 1
	print(result)
	i += 1


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	s1 = input()
	s = list(s1)
	zeros = 0
	ones = 0
	for j in range(n):
		if s[j] == '1':
			zeros = j
			break
		if j == n - 1:
			zeros = j + 1
	kk = 0
	for k in range(-1, -1 * (n + 1), -1):
		if s[k] == '0':
			kk = k
			ones = abs(k) - 1
			break
		if k == -n:
			kk = k
			ones = abs(k)
	if zeros + ones == n:
		ans.append(s1)
	else:
		ann = s1[:zeros] + str(0) + s1[-1:kk:-1]
		ans.append(ann)
for an in ans:
	print(an)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	i = n - 1
	cnt = []
	ct = 0
	for i in range(n):
		if s[i] == '1':
			ct += 1
		cnt.append(ct)
	ptr1 = n - 1
	ptr2 = n - 2
	while ptr2 >= 0:
		if s[ptr1] == '0' and s[ptr2] == '0' and (cnt[ptr2] > 0):
			s[ptr1] = 'a'
			ptr1 -= 1
			ptr2 -= 1
		elif s[ptr1] == '0' and s[ptr2] == '1' and (cnt[ptr2] > 0):
			s[ptr2] = 'a'
			cnt[ptr2] -= 1
			ptr2 -= 1
		elif s[ptr1] == 'a':
			ptr1 = ptr2 + 1
		else:
			ptr2 -= 1
			ptr1 -= 1
	ans = []
	for i in s:
		if i != 'a':
			ans.append(i)
	print(''.join(ans))


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = s.find('1')
	r = s.rfind('0')
	if l < r and l != -1 and (r != -1):
		s = s[:l] + s[r:]
	print(s)


from sys import stdin, stdout
readline = stdin.readline
write = stdout.write
t = int(readline())
for i in range(t):
	n = int(readline())
	s = readline().strip()
	stack = []
	lastZeroIndex = s.rfind('0')
	for (index, char) in enumerate(s):
		if char == '0' and stack and (stack[-1] == '1'):
			while stack and stack[-1] == '1':
				stack.pop()
			if lastZeroIndex > 0 and index < lastZeroIndex:
				stack.append('1')
			else:
				stack.append('0')
		else:
			stack.append(char)
	write(''.join(stack) + '\n')


for _ in range(int(input())):
	n = int(input())
	s = input()
	flag = True
	for i in range(n - 1):
		if int(s[i]) == int(s[i + 1]) or int(s[i]) + 1 == int(s[i + 1]):
			continue
		else:
			flag = False
			break
	if flag:
		print(s)
		continue
	answer = ''
	for i in range(n):
		if s[i] == '1':
			break
		answer += s[i]
	reverse = ''
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			break
		reverse = s[i] + reverse
	reverse = '0' + reverse
	print(answer + reverse)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	(left, right) = (-1, -1)
	pairPresent = False
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '0':
			pairPresent = True
	if pairPresent:
		for i in range(len(s) - 1):
			if s[i] == '1':
				left = i
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				right = i
				break
		ans = s[:left] + '0' + s[right + 1:]
	else:
		ans = s
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	l = -1
	r = -1
	for i in range(n):
		if s[i] != '0':
			l = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] != '1':
			r = i
			break
	if l == -1 or r == -1 or r <= l:
		print(s)
	else:
		ones = 0
		zeroes = 0
		for i in range(l, r + 1):
			if s[i] == '0':
				zeroes += 1
			else:
				ones += 1
		news = ['0' for i in range(l)]
		if zeroes:
			news.append('0')
		elif ones:
			news.append('1')
		for i in range(n - 1 - r):
			news.append('1')
		print(''.join(news))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input()))
	(s, e) = (-1, -1)
	for i in range(n):
		if a[i] == 1 and s == -1:
			s = i
		elif a[i] == 0 and s > -1:
			e = i
	if s == -1 or e == -1:
		for i in range(n):
			print(a[i], end='')
		print()
	else:
		for i in range(n):
			if i < s or i >= e:
				print(a[i], end='')
		print()


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	cnt = s.count('0')
	ans = ''
	cnt = 0
	ind = len(s)
	for i in range(len(s)):
		if s[i] == '1':
			ind = i
			break
		else:
			cnt += 1
	for i in range(ind, len(s)):
		if s[i] == '0':
			cnt += 1
			break
	for i in range(cnt):
		ans += '0'
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '0':
			break
		else:
			ans += '1'
	print(ans)


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		elif input_format == 6:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enum = enumerate

def solve():
	n = input(11)
	s = input(3)
	a = -1
	b = -1
	log(s)
	for i in range(0, n):
		if s[i] == '1':
			a = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			b = i
			break
	y = s[:a]
	if a < b:
		y += '0'
	y += s[b + 1:]
	if a == -1 or b == -1:
		y = s
	log(a, b)
	out(''.join(y))
	return
for i in range(input(11)):
	solve()


from sys import stdin, stdout
for test in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = stdin.readline()
	s = s[:-1]
	ind1 = s.find('1')
	if ind1 == -1:
		stdout.write(s + '\n')
	else:
		temp = s[ind1:]
		ind0 = temp.find('0')
		if ind0 == -1:
			stdout.write(s + '\n')
		elif s[-1] == '0':
			stdout.write(s[:ind1] + '0' + '\n')
		else:
			indr0 = temp.rfind('0')
			stdout.write(s[:ind1] + '0' + temp[indr0 + 1:] + '\n')


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
test_count = int(input())
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	n = inp()
	s = insr()
	lastZero = s.rfind('0')
	firstOne = s.find('1')
	if lastZero == -1 or firstOne == -1:
		print(s)
	elif lastZero > s.rfind('1'):
		print(s[0:firstOne] + '0')
	elif lastZero > firstOne:
		print(s[0:firstOne] + '0' + s[lastZero + 1:])
	else:
		print(s[0:firstOne] + s[lastZero + 1:])


t = int(input())
for u in range(t):
	n = int(input())
	s = input()
	i = 0
	s1 = 0
	s2 = 0
	while s[i] == '0' and i < len(s) - 1:
		i += 1
		s1 += 1
	j = len(s) - 1
	while s[j] == '1' and j > -1:
		j -= 1
		s2 += 1
	if i < j:
		print('0' * s1 + '0' + '1' * s2)
	else:
		print(s)


for _ in range(int(input())):
	n = int(input())
	st = list(input())
	ans = []
	if st.count('0') == 0 or st.count('1') == 0:
		print(''.join(st))
		continue
	c = 0
	for i in range(n):
		if st[i] == '1':
			c = i - 1
			ans = st[:i]
			break
	for i in range(n - 1, -1, -1):
		if st[i] == '0':
			if i != c:
				ans += st[i:]
			else:
				ans += st[i + 1:]
			break
	print(''.join(ans))


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = ''
	d = ''
	for i in range(n):
		if s[i] == '0':
			c += '0'
		else:
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			d += '1'
		else:
			break
	if i >= j:
		print(s)
	else:
		print(c + '0' + d)


t = int(input())

def fun(n, a):
	k0 = -1
	k1 = 10 ** 7
	i = 0
	while i < n:
		if a[i] == '0':
			k0 = max(k0, i)
		else:
			k1 = min(k1, i)
		i += 1
	if k0 == 10 ** 7:
		print(a)
	elif k1 == -1:
		print(a)
	elif k0 < k1:
		print(a)
	else:
		ans = ''
		for i in range(k1):
			ans += '0'
		ans += '0'
		for i in range(k0 + 1, n):
			ans += '1'
		print(ans)
while t:
	t -= 1
	n = int(input())
	a = input()
	fun(n, a)


from array import array
from math import log

def solve(s):
	if len(s) == 1:
		return s
	prefix = ''
	suffix = ''
	for i in range(0, len(s)):
		if s[i] == '1':
			for j in range(len(s) - 1, i, -1):
				if s[j] == '0':
					return prefix + '0' + suffix
				else:
					suffix = '1' + suffix
			return prefix + '1' + suffix
		else:
			prefix += '0'
	return prefix + suffix
test_cases = int(input())
for i in range(test_cases):
	_ = input()
	s = input().split(' ')
	print(str(solve(s[0])))


t = int(input())
for _ in range(0, t):
	n = int(input())
	s = input()
	c1 = 0
	c2 = 0
	for i in range(0, n):
		if s[i] == '0':
			c1 += 1
		else:
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			c2 += 1
		else:
			break
	ans = ''
	if abs(i - j) == 1 and i > j or c1 == n or c2 == n:
		ans += '0' * c1
		ans += '1' * c2
	else:
		ans += '0' * (c1 + 1)
		ans += '1' * c2
	print(ans)


t = int(input())
while t > 0:
	k = int(input())
	s = input()
	zero = s.rfind('0')
	one = s.find('1')
	if one > zero:
		print(s)
	else:
		print(s[0:one] + s[zero:])
	t -= 1


(T,) = map(int, input().split())
import re
for _ in range(T):
	(N,) = map(int, input().split())
	s = input().strip()
	x = re.match('(0*)(.*?)(1*)$', s)
	(a, b, c) = (x.group(1), x.group(2), x.group(3))
	if len(b):
		print(a + '0' + c)
	else:
		print(a + c)


for o in range(int(input())):
	n = int(input())
	s = input()
	try:
		f = s.find('1')
		r = s.rindex('0')
	except:
		print(s)
		continue
	if f > r:
		print(s)
	else:
		a = s[:f] + s[r:]
		print(a)


for _ in range(int(input())):
	n = int(input())
	S = input()
	SS = S[-1::-1]
	if '0' in SS:
		i = n - 1 - SS.index('0')
		for _ in range(i):
			if S[_] == '1':
				print(S[:_] + S[i:])
				break
		else:
			print(S)
	else:
		print(S)


for _ in range(int(input())):
	n = int(input())
	s = input()
	start = 0
	while s[start] != '1' and start < n - 1:
		start += 1
	beg = s[:start]
	end = n - 1
	while s[end] != '0' and end >= 0:
		end -= 1
	end = s[end + 1:]
	if len(beg) + len(end) == n:
		print(beg + end)
	else:
		print(beg + '0' + end)


for q in range(int(input())):
	n = int(input())
	s = input()
	cnt0 = 0
	cnt1 = 0
	check0 = False
	check1 = False
	ans = []
	i = 0
	while i < n and s[i] == '0':
		ans.append('0')
		i += 1
	ans2 = []
	j = n - 1
	while j >= 0 and s[j] == '1':
		ans2.append('1')
		j -= 1
	if len(ans) + len(ans2) == n:
		for elem in ans:
			print(elem, end='')
		for elem in ans2:
			print(elem, end='')
		print()
	else:
		for elem in ans:
			print(elem, end='')
		print(0, end='')
		for elem in ans2:
			print(elem, end='')
		print()


test = int(input())
for _ in range(test):
	n = int(input())
	string = str(input())
	flag = 0
	index = -1
	count = 0
	for s in range(n):
		if string[s] == '1':
			flag = 1
		if string[s] == '0' and flag == 1:
			index = s
		elif string[s] == '0' and flag == 0:
			count += 1
	if index != -1:
		i = '0' * (count + 1)
		new = i + string[index + 1:]
	else:
		new = string
	print(new)


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()[:-1]
	if s in ['0' * n, '1' * n]:
		print(s)
	else:
		(zero, one) = (0, 0)
		for i in range(n):
			if s[i] == '0':
				zero += 1
			else:
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				one += 1
			else:
				break
		if n - zero - one > 0:
			print('0' * zero + '0' + '1' * one)
		else:
			print('0' * zero + '1' * one)


for _ in range(int(input())):
	input()
	s = input()
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '0':
			f = i
			break
	st = []
	for i in range(len(s)):
		if s[i] == '1':
			st.append(s[i])
		if s[i] == '0' and i < f:
			if st and st[-1] == '1':
				continue
			elif st == [] or st[-1] == '0':
				st.append(s[i])
		if s[i] == '0' and i == f:
			while st and st[-1] == '1':
				st.pop()
			st.append('0')
	print(''.join(st))


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	n = inp()
	s = list(input())
	s.pop()
	prev = -1
	x = []
	for i in s:
		if i != prev:
			x.append(i)
		else:
			x[-1] += i
		prev = i
	if len(x) == 1:
		print(''.join(s))
		continue
	ans = []
	(i, j) = (-1, -1)
	if '0' in x[0]:
		i = 0
		ans.append(x[0])
	if '1' in x[-1]:
		j = len(x) - 1
		ans.append(x[-1])
	diff = j - i
	if diff != 1:
		if len(ans) > 1:
			print('0'.join(ans))
		else:
			ans.insert(0, '0')
			print(''.join(ans))
	else:
		print(''.join(ans))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	marked = [False] * n
	include = [True] * n
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '0':
			marked[i] = True
	for i in range(n):
		if marked[i]:
			include[i] = False
			j = i - 1
			j1 = i + 1
			while j >= 0 and s[j] == '1':
				include[j] = False
				j -= 1
			while j1 < n and s[j1] == '0':
				include[j1] = False
				j1 += 1
	ans = ''
	i = 0
	while i < n:
		if include[i]:
			ans += s[i]
			i += 1
		else:
			while i < n and (not include[i]):
				i += 1
			ans += '0'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans1 = ''
	for i in range(len(s)):
		if s[i] == '0':
			ans1 += s[i]
		else:
			break
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '0':
			ans1 += '0'
			break
	ans2 = ''
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			ans2 = s[i] + ans2
		else:
			break
	print(ans1 + ans2)


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

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

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

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

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

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

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		n = inp()
		s = insr()
		zero = 0
		for i in range(len(s)):
			if s[i] == '0':
				zero = zero + 1
			else:
				break
		one = 0
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				one = one + 1
			else:
				break
		if one + zero == len(s):
			print(''.join(s))
		else:
			ans = '0' * zero + '0' + '1' * one
			print(ans)
main()


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
N = 10 ** 6 + 7
for _ in range(I()):
	n = I()
	a = []
	flg = True
	s = S()
	o = s.count('1')
	for i in s[::-1]:
		if flg:
			a += (i,)
			if i == '0':
				flg = False
			else:
				o -= 1
		elif i == '0' and (not o):
			a += (i,)
		elif i == '1':
			o -= 1
	print(*a[::-1], sep='')


n_lines = int(input())
for _ in range(n_lines):
	n = int(input())
	bins = list(input().rstrip('\n'))
	i = n - 1
	while True:
		if len(bins) < 2:
			break
		while i >= 1 and (not (bins[i] == '0' and bins[i - 1] == '1')):
			i -= 1
		if i - 1 < 0:
			break
		if i == len(bins) - 1 or bins[i + 1] == '1':
			del bins[i - 1]
			i -= 1
		else:
			del bins[i]
	print(''.join(bins))


for s in [*open(0)][2::2]:
	i = (s[:-1] + '1').find('1')
	j = ('0' + s).rfind('0')
	print(s[:i] + '0' * (j - i > 1) + s[j:])


t = int(input())
for l in range(t):
	n = int(input())
	s = input()
	if '0' in s and '1' in s:
		temp = s[:s.index('1')]
		s = s[s.index('1'):]
		if '0' in s and '1' in s:
			while True:
				start = 0
				end = 0
				breaker = 0
				for x in s:
					if breaker == 1 and x == '1' or end == n:
						break
					if x == '1':
						end += 1
					elif x == '0':
						end += 1
						breaker = 1
				sub = s[end:]
				if '0' in sub:
					s = '1' + sub
				else:
					s = '0' + sub
					break
			print(temp + s)
		else:
			print(temp + s)
	else:
		print(s)


test_case = int(input())
for _ in range(test_case):
	size = int(input())
	st = input()
	zeros = 0
	ones = len(st)
	for i in range(len(st)):
		if st[i] == '0':
			zeros += 1
		else:
			break
	for i in range(len(st) - 1, -1, -1):
		if st[i] == '1':
			ones -= 1
		else:
			break
	if ones - zeros > 1:
		print('0' * zeros + '0' + '1' * (len(st) - ones))
	else:
		print(st)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

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

def solve():
	n = ri()
	s = input()
	init = 0
	end = 0
	for c in s:
		if c == '0':
			init += 1
		else:
			break
	for c in s[::-1]:
		if c == '1':
			end += 1
		else:
			break
	if init + end < len(s):
		print('0' * init + '0' + '1' * end)
	else:
		print('0' * init + '1' * end)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


p = []
for i in range(int(input())):
	n = int(input())
	k = list(input())
	r = 0
	s = 1
	o = []
	if ('0' in k) == True and ('1' in k) == True:
		while k[r] == '0':
			r = r + 1
		while k[-s] == '1':
			s = s + 1
		if s + r - 1 == len(k):
			p.append(k)
		else:
			for i in range(r + 1):
				o.append('0')
			for i in range(s - 1):
				o.append('1')
			p.append(o)
	else:
		p.append(k)
for i in p:
	print(''.join(i))


import sys
from collections import deque
pprint = lambda s: print(''.join(map(str, s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
for i in range(int(input())):
	n = int(input())
	s = list(map(int, input()))
	ans0 = []
	ans1 = []
	if 1 not in s or 0 not in s:
		pprint(s)
		continue
	for i in range(n):
		stop = i
		if s[i] == 1:
			break
		else:
			ans0.append(0)
	for i in range(n - 1, stop - 1, -1):
		if s[i] == 0:
			if i != stop:
				ans0.append(0)
			break
		else:
			ans1.append(1)
	pprint(ans0 + ans1)


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	s = input()
	r = 1
	flag = 0
	ans = ''
	for j in s:
		if j == '0':
			ans = ans + '0'
		else:
			break
	while r <= len(s):
		if s[-r] == '1':
			r = r + 1
		else:
			break
	t = r - 1
	while r <= len(s):
		if s[-r] == '0':
			r = r + 1
		else:
			flag = 1
			break
	if flag == 1:
		print(ans + '0' + t * '1')
	else:
		print((r - t - 1) * '0' + t * '1')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	first = -1
	for i in range(n):
		if s[i] == '1':
			first = i
			break
	last = -1
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			last = i
			break
	if last == -1 or first == -1:
		print(s)
	elif first > last:
		print(s)
	else:
		ans = ''
		if first != -1:
			ans += s[:first]
		ans += '0'
		if last != n - 1:
			ans += s[last + 1:]
		print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = list(s)
	i = 0
	f = 0
	f2 = 0
	c = []
	for i in range(len(a)):
		if a[i] == '1':
			f = 1
		if f == 0:
			c.append(a[i])
		if f == 1 and a[i] == '0' and (f2 == 0):
			c.append('0')
			f2 = 1
	i = len(a) - 1
	while a[i] != '0' and i >= 0:
		c.append('1')
		i -= 1
	print(''.join(c))


import math
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

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

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

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def longestsubarray(arr, n, k):
	current_count = 0
	max_count = 0
	for i in range(0, n, 1):
		if arr[i] % k != 0:
			current_count += 1
		else:
			current_count = 0
		max_count = max(current_count, max_count)
	return max_count

def main():
	n = int(input())
	s = input()
	s1 = ''
	c1 = 0
	for j in range(0, n):
		if s[j] == '0':
			s1 += '0'
			c1 += 1
		else:
			break
	s2 = ''
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			s2 += '1'
			c1 += 1
		else:
			break
	if c1 == n:
		print(s)
	else:
		print(s1 + '0' + s2)
t = int(input())
for i in range(0, t):
	main()


def solve(n, s):
	zeros = 0
	ones = 0
	for c in reversed(s):
		if c == '1':
			if not zeros:
				ones += 1
			else:
				zeros = 1
		else:
			zeros += 1
	return ''.join(['0'] * zeros + ['1'] * ones)
t = int(input())
for i_t in range(t):
	n = int(input())
	s = input()
	print(solve(n, s))


import os
import sys
from io import BytesIO, IOBase

def solution(s, n):
	if '10' in s:
		res = ''
		for i in range(n):
			if s[i] == '1':
				res += s[:i] + '0'
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				res += s[i + 1:]
				break
		write(res)
	else:
		write(s)

def main():
	for _ in range(r_int()):
		n = r_int()
		s = input()
		solution(s, n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

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

def r_int():
	return int(input())
main()


def cleaner(s):
	initial_add = ''
	final_list = []
	last_add = ''
	if s[0] == '0':
		if '1' not in s:
			return s
		initial_add = s[:s.index('1')]
		s = s[s.index('1'):]
	if s[-1] == '1':
		reverse = s[::-1]
		if '0' not in s:
			return initial_add + s
		last_add = reverse[:reverse.index('0')]
		s = s[:len(s) - 1 - reverse.index('0')]
	short_string = initial_add + '0' + last_add
	return short_string
test_cases = int(input())
while test_cases:
	n = int(input())
	print(cleaner(input()))
	test_cases -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	while i < len(s) - 1 and i >= 0:
		if s[i] == '1' and s[i + 1] == '0':
			j = i
			ind = [-1, -1]
			j = s.index('1')
			ind[0] = j
			j = i + 1
			new = s[::-1]
			j = new.index('0')
			j = n - 1 - j
			ind[1] = j
			s = s[:ind[0]] + s[ind[1]:]
			i = ind[0]
		else:
			i += 1
		if len(s) == 0:
			break
	print(s)


for ii in range(int(input())):
	n = int(input())
	s = input()
	if not s.count('1'):
		print(s)
		continue
	i = int(s)
	print(s.replace(str(i), ''), end='')
	s = str(i)
	f = True
	for i in reversed(range(len(s))):
		if s[i] == '0':
			print(s[i:])
			f = False
			break
	if f:
		print(s)


for _ in [0] * int(input()):
	n = int(input())
	s = input()
	cs = s
	if '10' in s:
		x = s.index('1')
		cs = s[:x]
		s = s[::-1]
		y = s.index('0')
		s = s[:y]
		cs = cs + '0' + s[::-1]
	print(cs)


tc = int(input())
result = []
for i in range(tc):
	size = int(input())
	number = input()
	i1 = ''
	i1f = 0
	i0 = ''
	i0f = 0
	for t in range(size):
		if not i1f:
			if number[t] == '1':
				i1 = t
				i1f = 1
		if not i0f:
			if number[-t - 1] == '0':
				i0 = size - t - 1
				i0f = 1
	if not i0f or not i1f:
		result.append(number)
		continue
	if i0 < i1:
		i0 += 1
	result.append(number[:i1] + number[i0:])
for z in result:
	print(z)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	if s.count('1') > 0:
		a = s.index('1')
		ans = ''
		ans += s[:a]
		if s.count('0', a) > 0:
			r = s[::-1]
			b = n - 1 - r.index('0')
			ans += '0'
			ans += s[b + 1:]
		elif s.count('0', a) == 0:
			ans += s[a:]
		print(ans)
	else:
		print(s)


def remove(s, i):
	return s[0:i] + s[i + 1:]

def solution():
	for t in range(int(input())):
		n = int(input())
		s = input()
		l1 = s.find('1')
		r0 = s.rfind('0')
		if l1 != -1 and r0 != -1 and (l1 < r0):
			print(s[:l1] + s[r0:])
		else:
			print(s)
solution()


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

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

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

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

def solve():
	n = get_int()
	st = input()
	(i, j) = (0, n - 1)
	c0 = 0
	for i in range(n):
		if st[i] != '0':
			break
		c0 += 1
	c1 = 0
	for j in range(n - 1, -1, -1):
		if st[j] != '1':
			break
		c1 += 1
	if st.count('0') == n or st.count('1') == n:
		return st
	if i == 0 and j == n - 1:
		return '0'
	if st[-1] == '0':
		return '0' * (c0 + 1)
	if st[-1] == '1':
		if i < j:
			return '0' * (c0 + 1) + '1' * c1
		else:
			return '0' * c0 + '1' * c1

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


for t in range(int(input())):
	n = int(input())
	s = input()
	try:
		init = s.index('1')
		end = n - s[::-1].index('0')
		if init - end:
			print(s[:init] + '0' + s[end:])
		else:
			print(s)
	except:
		print(s)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, s):
	leading_zeros = 0
	for item in s:
		if item == 1:
			break
		leading_zeros += 1
	trailing_ones = 0
	for item in reversed(s):
		if item == 0:
			break
		trailing_ones += 1
	if leading_zeros + trailing_ones < n:
		leading_zeros += 1
	return '0' * leading_zeros + '1' * trailing_ones
for i in tests():
	n = int_in()
	s = [int(x) for x in str_in()]
	out(solve(n, s))


from sys import stdin, stdout

class SOLVE:

	def solve(self):
		r = stdin.readline
		w = stdout.write
		ans = []
		for i in range(int(input())):
			n = int(input())
			s = r()
			(lstr_pos, rstr_pos) = (-1, n)
			lstr = rstr = ''
			for j in range(n):
				if s[j] == '0':
					lstr += '0'
					lstr_pos = j
				else:
					break
			for j in range(n - 1, -1, -1):
				if s[j] == '1':
					rstr += '1'
					rstr_pos = j
				else:
					break
			if rstr_pos - lstr_pos == 1:
				ans.append(s)
			else:
				ans.append(lstr + '0' + rstr)
		w('\n'.join(ans))

def main():
	s = SOLVE()
	s.solve()
main()


def gns():
	return list(map(int, input().split()))
t = int(input())
for _ in range(t):
	n = int(input())
	ns = input()
	(l, r) = (0, 0)
	for i in range(n):
		if ns[i] == '0':
			l += 1
		else:
			break
	for i in reversed(range(n)):
		if ns[i] == '1':
			r += 1
		else:
			break
	if l + r < n:
		l += 1
	print('0' * l + '1' * r)


for _ in range(int(input())):
	n = int(input())
	ar = list(input())
	zers = 0
	ons = 0
	for i in range(n):
		if ar[i] == '0':
			zers += 1
		else:
			break
	i -= 1
	for j in range(n):
		if ar[n - j - 1] == '1':
			ons += 1
		else:
			break
	j -= 1
	if n - j - 1 - i == 1 or list(set(ar)) == ['0'] or list(set(ar)) == ['1']:
		kk = 0
	else:
		kk = 1
	ans = '0' * zers + '0' * kk + '1' * ons
	print(ans)


def main():
	import sys
	input = sys.stdin.readline
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input().strip()
		first1 = s.find('1')
		last0 = s.rfind('0')
		if first1 >= 0 and last0 >= 0:
			if last0 < first1:
				print(s)
			else:
				print(s[:first1] + s[last0:])
		else:
			print(s)
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = 0
	r = 0
	for i in range(n):
		if s[i] == '0':
			l += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			r += 1
		else:
			break
	if r + l != n:
		l += 1
	ans = '0' * l + '1' * r
	print(ans)


t = int(input())
while t:
	n = int(input())
	s = input()
	check = 1
	final = ''
	temp = ''
	alt = ''
	count1 = 0
	count0 = 0
	for i in range(0, n):
		if s[i] == '0':
			final = final + s[i]
		else:
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			final = final + s[i]
		else:
			break
	if final == '':
		final = '0'
	elif final == s:
		pass
	else:
		final = '0' + final
	print(final)
	t = t - 1


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	sA = list(s)
	first1 = -1
	last0 = -1
	for i in range(n):
		if sA[i] == '1':
			first1 = i
			break
	for i in range(n - 1, -1, -1):
		if sA[i] == '0':
			last0 = i
			break
	if first1 != -1 and last0 != -1 and (first1 < last0):
		sA2 = sA[:first1 + 1] + sA[last0:]
		first1 = -1
		for i in range(len(sA2)):
			if sA2[i] == '1':
				first1 = i
				break
		sA2.pop(first1)
		print(''.join(sA2))
	else:
		print(s)


import sys
input = lambda : sys.stdin.readline().rstrip()
from collections import deque
from queue import LifoQueue
for _ in range(int(input())):
	n = int(input())
	s = input()
	pp = 0
	if s[0] == '0':
		pp = 0
		for i in range(1, n):
			if s[i] == '1':
				pp = i
				break
		for i in range(n):
			if s[-i - 1] == '0':
				pps = -i - 1
				break
		if pp == 0:
			print(s)
		elif pp < pps + n:
			print(s[:pp] + s[pps:])
		else:
			print(s)
	else:
		pps = 0
		for i in range(n):
			if s[-i - 1] == '0':
				pps = -i - 1
				break
		if pps == 0:
			print(s)
		else:
			print(s[pps:])


def run():
	import sys
	sys.stdin = open('/home/puneet/Documents/Cpp Programs/input.txt', 'r')
	sys.stdout = open('/home/puneet/Documents/Cpp Programs/output.txt', 'w')
	from math import ceil, sqrt, floor
for _ in range(int(input())):
	n = int(input())
	s = input()
	if '1' not in s:
		print(s)
	else:
		ans = ''
		temp = ''
		index = 0
		for i in range(n):
			if s[i] == '0':
				temp += s[i]
			else:
				index = i
				break
		for i in range(n - 1, index - 1, -1):
			if s[i] == '1':
				ans += s[i]
			else:
				ans += '0'
				break
		ans = ans[::-1]
		temp += ans
		print(temp)


from functools import reduce
import collections
import math
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(delimiter=' '):
		return input().split(delimiter)

	@staticmethod
	def list_int(delimiter=' '):
		return list(map(int, input().split(delimiter)))

def main():
	t = Read.int()
	for _ in range(t):
		n = Read.int()
		a = Read.string()
		res = ''
		f = a.rfind('10')
		while f != -1:
			if f - 1 > -1:
				if a[f - 1] == '1':
					a = a[:f] + '0' + a[f + 2:]
				elif f + 2 < len(a):
					if a[f + 2] == '0':
						a = a[:f] + '1' + a[f + 2:]
					else:
						a = a[:f] + '0' + a[f + 2:]
				else:
					a = a[:f] + '0' + a[f + 2:]
			elif f + 2 < len(a):
				if a[f + 2] == '0':
					a = a[:f] + '1' + a[f + 2:]
				else:
					a = a[:f] + '0' + a[f + 2:]
			else:
				a = a[:f] + '0' + a[f + 2:]
			f = a.rfind('10')
		print(a)
main()


t = int(input())
for case in range(t):
	n = int(input())
	s = input()
	p1 = 0
	p2 = 0
	if n == 0 or n == 1:
		print(s)
	elif '0' not in s or '1' not in s:
		print(s)
	else:
		new_s = ''
		p1 = 0
		p2 = n - 1
		lead_zeroes = 0
		trail_ones = 0
		while s[p1] == '0':
			new_s += '0'
			p1 += 1
		while s[p2] == '1':
			new_s += '1'
			p2 -= 1
		if p1 < p2:
			new_s = '0' + new_s
		print(new_s)


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
import io, os
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().strip().split()))
rls = lambda : list(map(str, input().split()))
t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(input())
	s = [a[0]]
	for i in range(1, n):
		s.append(a[i])
		while len(s) > 1 and (s[-2] == '1' and s[-1] == '0'):
			s.pop()
			s.pop()
			s.append('x')
	q = [s[0]]
	for i in range(1, len(s)):
		q.append(s[i])
		while len(q) > 1 and (q[-2] == '1' and q[-1] == 'x' or (q[-2] == 'x' and q[-1] == '0') or (q[-2] == 'x' and q[-1] == 'x')):
			q.pop()
			q.pop()
			q.append('x')
	s1 = ''
	for i in range(0, len(q)):
		if q[i] == 'x':
			s1 = s1 + '0'
		else:
			s1 = s1 + q[i]
	print(s1)


for t in range(int(input())):
	n = int(input())
	s = input()
	zl = s.rfind('0')
	o1 = s.find('1')
	if zl != -1 and o1 != -1 and (o1 < zl):
		s = s[:o1] + s[zl:]
	print(s)


from enum import *
from copy import *
from sys import *
from collections import *
from itertools import *
from functools import *
from math import *

def l2i(fr=None):
	return map_type_to_fr(int, fr)[0]

def i2i(fr=None):
	return l2i(fr)

def dbg(*args):
	print(*args, file=stderr)

def dbv(var_name):
	print(f'{var_name} = {eval(var_name)}', file=stderr)

def map_type_to_fr(t, fr):
	global GETLINE_OFFSET
	if fr is None:
		if RUNNING_ON_MY_PC:
			fr = TEST_INP[GETLINE_OFFSET].split()
			GETLINE_OFFSET += 1
		else:
			fr = input().split()
	return list(map(t, fr))

def mis(fr=None):
	return map_type_to_fr(int, fr)

def mbs(fr=None):
	return map_type_to_fr(bool, fr)

def gs(fr=None):
	return map_type_to_fr(str, fr)[0]
import os
import sysconfig
RUNNING_ON_MY_PC = os.name == 'nt' and platform == 'win32' and (sysconfig.get_platform() == 'win-amd64')
GETLINE_OFFSET = 0
TEST_INP = '5\n10\n0001111111\n4\n0101\n8\n11001101\n10\n1110000000\n1\n1\n'.split('\n')

def my_r(x):
	c = ceil(x)
	if c - x > 0.5:
		return floor(x)
	return c
for t in range(i2i()):
	n = i2i()
	s = gs()
	zf = s.find('1')
	of = s.rfind('0')
	if zf == of + 1:
		of += 1
	print(s[:zf] + s[of:])


n = int(input())
results = []
for i in range(n):
	l = int(input())
	s = input()
	if '1' in s:
		firstone = s.index('1')
	else:
		results.append(s)
		continue
	if '0' in s:
		lastzero = l - s[::-1].index('0') - 1
	else:
		results.append(s)
		continue
	result = s[:firstone]
	if firstone < lastzero:
		result += '0'
	result += s[lastzero + 1:]
	results.append(result)
print(*results, sep='\n')


def mi():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(input())
	out = ''
	i = 0
	while i < n:
		(o, z) = (0, 0)
		while i < n and a[i] == '1':
			i += 1
			o += 1
		while i < n and a[i] == '0':
			i += 1
			z += 1
		if o > 0 and z > 0:
			out += '2'
		elif o > 0:
			out += o * '1'
		else:
			out += z * '0'
	n = len(out)
	i = 0
	while i < n:
		if out[i] == '2':
			while i < n and out[i] == '2':
				i += 1
			print(0, end='')
		else:
			print(out[i], end='')
			i += 1
	print()


from math import ceil
t = int(input())
for _ in range(t):
	n = int(input())
	s = [int(i) for i in input()]
	lind = 0
	while lind < n and s[lind] == 0:
		lind += 1
	rind = n - 1
	while rind >= 0 and s[rind] == 1:
		rind -= 1
	st = ''.join(map(str, s[:lind]))
	if lind <= rind:
		st += '0'
	st += ''.join(map(str, s[1 + rind:]))
	print(st)


T = int(input())
for i in range(T):
	N = int(input())
	string = input()
	left1 = -1
	right0 = -1
	for (idx, c) in enumerate(string):
		if left1 < 0 and c == '1':
			left1 = idx
		elif c == '0':
			right0 = idx
	if left1 >= 0 and right0 >= 0 and (left1 < right0):
		print(string[:left1] + string[right0:])
	else:
		print(string)


for I in range(int(input())):
	n = int(input())
	s = input()
	one = -1
	zero = -1
	for i in range(n):
		if s[i] == '1' and one == -1:
			one = i
		if s[i] == '0':
			zero = i
	if one < 0 or zero < 0 or one > zero:
		print(s)
	elif one == 0 and zero == n - 1:
		print('0')
	else:
		string = s[:one] + s[zero:]
		print(string)


def f(arr):
	cnt_1 = 0
	cnt_0 = sum((1 - a for a in arr))
	ans = []
	for a in arr:
		skip = True
		cnt_1 += a == 1
		while ans and ans[-1] > a:
			if cnt_1 >= cnt_0:
				cnt_1 -= 1
				ans.pop(-1)
			else:
				cnt_0 -= 1
				skip = False
				break
		if skip:
			cnt_0 -= a == 0
		if skip:
			ans.append(a)
	print(''.join([str(a) for a in ans]))
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input()]
	f(arr)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if '1' not in s:
		print(s)
	elif '0' not in s:
		print(s)
	else:
		(i, j) = (0, 0)
		for k in range(n):
			if s[k] == '1':
				i = k
				break
		for k in range(n - 1, -1, -1):
			if s[k] == '0':
				j = k
				break
		a = s[:i]
		b = s[j:]
		if len(a) + len(b) > n:
			print(s[:i] + s[j + 1:])
		else:
			print(a + b)


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

def multiple_input():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	s = input()
	pos = -1
	ans = ''
	for i in range(n):
		if s[i] == '0':
			pos = i
	if pos == -1:
		ans = s
	else:
		temp = 0
		for i in range(n):
			if s[i] == '0':
				temp += 1
				ans += s[i]
			else:
				break
		if temp == pos + 1:
			pos += 1
		for i in range(pos, n):
			ans += s[i]
	print(ans)


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	s = input()
	i = 0
	ans = []
	while i < n:
		j = i + 1
		while j < n and s[j] == s[i]:
			j += 1
		ans.append(j - i)
		i = j
	if len(ans) == 1:
		print(s)
	elif len(ans) == 2:
		if s[0] == '0':
			print(s)
		else:
			print('0')
	elif s[0] == '0':
		if len(ans) % 2 == 0:
			print('0' * ans[0] + '0' + '1' * ans[-1])
		else:
			print('0' * ans[0] + '0')
	elif len(ans) % 2 == 0:
		print('0')
	else:
		print('0' + '1' * ans[-1])


t = int(input())
while t != 0:
	t = t - 1
	n = int(input())
	s = input()
	zero = 0
	one = 0
	for i in range(0, n):
		if s[i] == '0':
			zero = zero + 1
		elif s[i] == '1':
			one = one + 1
	if one == n or zero == n:
		print(s)
	else:
		trailone = 0
		leadzero = 0
		flag = 1
		for i in range(0, n):
			if s[i] == '0':
				leadzero = leadzero + 1
			else:
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				trailone = trailone + 1
			else:
				break
		if leadzero + trailone == n:
			print(s)
		else:
			ans = ''
			for i in range(1, leadzero + 1):
				ans = ans + '0'
			ans = ans + '0'
			for i in range(1, trailone + 1):
				ans = ans + '1'
			print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	one = []
	zero = []
	k = 0
	for i in s:
		if i == '1':
			one.append(k)
		else:
			zero.append(k)
		k += 1
	if len(one) == n or len(one) == 0 or zero[-1] < one[0]:
		print(s)
	elif zero[0] > one[-1]:
		print(0)
	else:
		ans = ''
		if one[0] != 0:
			ans = ans + '0' * one[0]
		if one[-1] != n - 1:
			ans = ans + '0'
		else:
			ans = ans + '0'
			ans = ans + '1' * (n - zero[-1] - 1)
		print(ans)


import copy
for _ in range(int(input())):
	n = int(input())
	s = input()
	a = list(s)
	(x, y) = ('', '')
	if s.find('10') == -1:
		print(s)
	else:
		for i in range(len(s)):
			if s[i] == '1':
				break
			x += s[i]
		for i in range(len(s) - 1, -1, -1):
			y += s[i]
			if s[i] == '0':
				break
		y = y[::-1]
		z = x + y
		if len(z) > len(s):
			print(z[:-1])
		else:
			print(z)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	tmp = list(input().rstrip())
	one = 100000
	zero = 0
	for i in range(n):
		if tmp[i] == '1':
			one = min(one, i)
		else:
			zero = max(zero, i)
	if one > zero:
		print(''.join(tmp))
	else:
		print(''.join(tmp[0:one] + tmp[zero:]))


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = [int(x) for x in list(stdin.readline().strip())]
	bool1 = -1
	for x in range(n):
		if s[x] == 1:
			bool1 = x
			break
		else:
			stdout.write('0')
	mybool = -1
	for x in range(n - 1, -1, -1):
		if s[x] == 0:
			mybool = x
			break
	if mybool != bool1 - 1 and mybool != -1 and (bool1 != -1):
		stdout.write('0')
	if mybool != -1:
		for y in range(mybool + 1, n):
			stdout.write('1')
	else:
		for x in s:
			stdout.write(str(x))
	stdout.write('\n')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	x = 0
	y = 0
	for i in range(n):
		if s[i] == '0':
			x = x + 1
		else:
			break
	for i in range(n):
		if s[n - i - 1] == '1':
			y = y + 1
		else:
			break
	if x + y == n:
		print(s)
	else:
		print('0' * (x + 1) + '1' * y)


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	val1 = 0
	val2 = n - 1
	for i in range(n - 1, -1, -1):
		val2 = i
		if s[i] == '0':
			break
	for i in range(n):
		val1 = i
		if s[i] == '1':
			break
	if val1 > val2:
		val1 -= 1
	print(s[:val1] + s[val2:])
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	flag = 0
	num1 = 0
	num0 = 0
	i = n - 1
	while i >= 0:
		if s[i] == '0' and num1 == 0:
			num0 += 1
		elif s[i] == '1' and num0 > 0:
			num1 += 1
		elif s[i] == '0' and num1 > 0:
			s = s[:i + 1] + s[i + num1 + num0:]
			num0 = 2
			num1 = 0
		i -= 1
	if num1 > 0 and num0 > 0:
		s = s[num1 + num0 - 1:]
	print(s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	out = ''
	i = 0
	while i < n and s[i] == '0':
		out += '0'
		i += 1
	x = s[i:].count('10')
	p = ''
	if i != n or i == 0:
		i = -1
		while i >= -1 * n and s[i] == '1':
			p += '1'
			i -= 1
	if x:
		out += '0'
	print(out + p)


def solve():
	n = int(input())
	s = input()
	sl = ''
	sr = ''
	check0 = False
	check1 = False
	for i in range(len(s)):
		if s[i] == '0':
			check0 = True
		if s[i] == '1':
			check1 = True
	if check0 == False or check1 == False:
		ans = s
	else:
		i = 0
		while i < len(s) and s[i] == '0':
			sl += s[i]
			i += 1
		i = len(s) - 1
		while i >= 0 and s[i] == '1':
			sr += s[i]
			i -= 1
		if len(sl) + len(sr) != len(s):
			ans = sl + '0' + sr
		else:
			ans = sl + sr
	print(ans)
t = int(input())
for i in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	s = input()
	last0 = -1
	ans = ''
	for i in range(n):
		if s[i] == '0':
			last0 = i
	no_one = True
	for i in range(n):
		if s[i] == '1':
			if i > last0:
				ans += '1'
			elif no_one:
				ans += '0'
			no_one = False
		if s[i] == '0' and no_one:
			ans += s[i]
	print(ans)


import sys
input = sys.stdin.readline

def rle(lst):
	ans = []
	cnt = 1
	ini = lst[0]
	for i in range(1, len(lst)):
		if ini == lst[i]:
			cnt += 1
		else:
			ans.append((ini, cnt))
			cnt = 1
			ini = lst[i]
	ans.append((ini, cnt))
	return ans
t = int(input())
for p in range(t):
	n = int(input())
	s = list(input())
	sr = rle(s)
	ans = []
	if len(sr) == 2:
		print(''.join(s))
	elif sr[0][0] == '0' and sr[-2][0] == '1':
		if len(sr) == 3:
			print(''.join(s))
		else:
			for i in range(sr[0][1]):
				ans.append('0')
			ans.append('0')
			for i in range(sr[-2][1]):
				ans.append('1')
			print(''.join(ans))
	elif sr[0][0] == '0' and sr[-2][0] == '0':
		for i in range(sr[0][1]):
			ans.append('0')
		ans.append('0')
		print(''.join(ans))
	elif sr[0][0] == '1' and sr[-2][0] == '1':
		ans.append('0')
		for i in range(sr[-2][1]):
			ans.append('1')
		print(''.join(ans))
	else:
		print(0)


t = int(input())
c = []
for i in range(t):
	n = int(input())
	s = input()
	i = 0
	while i < n:
		if s[i] == '1':
			j = i
			while j < n - 1 and s[j + 1] == '1':
				j += 1
			zero = 0
			while j < n - 1 and s[j + 1] == '0':
				j += 1
				zero = 1
			if zero == 1:
				if '0' in s[j + 1:n]:
					s = s[0:i] + '1' + s[j + 1:n]
				else:
					s = s[0:i] + '0' + s[j + 1:n]
				n = n - j + i
				i = 0
			else:
				i = j + 1
		else:
			i = i + 1
	c.append(s)
for k in c:
	print(k)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

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

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(int(input())):
	n = int(input())
	s = input()
	f1 = 0
	x = -1
	y = -1
	for i in range(n):
		if s[i] == '1' and f1 != 1:
			f1 = 1
			x = i
		elif s[i] == '0':
			y = i
	if x == -1 or y == -1:
		print(s)
	elif x > y:
		print(s)
	else:
		print(s[:x] + s[y:])


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	if s.count('10') > 0:
		zero = 0
		one = 0
		for i in range(len(s)):
			if s[i] != '0':
				break
			zero += 1
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				one += 1
			else:
				break
		if one + zero == len(s):
			print(s)
		ans = ''
		ans = '0' * (zero + 1)
		ans += '1' * one
		print(ans)
	else:
		print(s)


from sys import stdin
from bisect import bisect_left as bl
from bisect import bisect_right as br

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

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

def intsput():
	return map(int, sinput())

class RangedList:

	def __init__(self, start, stop, val=0):
		self.shift = 0 - start
		self.start = start
		self.stop = stop
		self.list = [val] * (stop - start)

	def __setitem__(self, key, value):
		self.list[key + self.shift] = value

	def __getitem__(self, key):
		return self.list[key + self.shift]

	def __repr__(self):
		return str(self.list)

	def __iter__(self):
		return iter(self.list)

def dprint(*args, **kwargs):
	if debugging:
		print(*args, **kwargs)
debugging = 1
t = intput()
for _ in range(t):
	n = intput()
	s = input()
	start = None
	end = None
	for i in range(n):
		if s[i] == '1':
			start = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			end = i
			break
	if start is not None and end is not None and (start < end):
		print(s[:start] + '0' + s[end + 1:])
	else:
		print(s)


t = int(input())
h = 1
while h <= t:
	n = int(input())
	s = input()
	zero = 0
	one = 0
	for i in range(n):
		if s[i] == '0':
			zero += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			one += 1
		else:
			break
	if zero + one == n:
		print(s)
	else:
		for i in range(0, zero):
			print('0', end='')
		print('0', end='')
		for j in range(0, one):
			print('1', end='')
	print()
	h += 1


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	N = int(stdin.readline())
	s = stdin.readline().strip()
	if N == 1:
		print(s)
		continue
	(start, end) = (0, N - 1)
	first = ''
	last = ''
	found1 = False
	for i in range(N):
		if s[i] == '1':
			found1 = True
			start = i
			break
		first += '0'
	if not found1:
		print(s)
		continue
	s = s[::-1]
	found0 = False
	for i in range(N):
		if s[i] == '0':
			end = N - i
			found0 = True
			break
		last += '1'
	if not found0:
		print(s)
		continue
	if start == end:
		print(first + last)
		continue
	print(first + '0' + last)


for s in [*open(0)][2::2]:
	try:
		i = s.index('1')
		j = s.rindex('0')
		print(s[:i] + '0' * (j > i) + s[j + 1:])
	except:
		print(s)


tt = int(input())
for loop in range(tt):
	n = int(input())
	s = input()
	ans = []
	ans2 = []
	if '0' not in s or '1' not in s:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			ans += ['0'] * i
			fi = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			ans2 += ['1'] * (n - 1 - i)
			se = i
			break
	if fi > se:
		ans += ans2
	else:
		ans = ans + ['0'] + ans2
	print(''.join(ans))


from collections import deque

def main():
	t = int(input())
	while t > 0:
		t = t - 1
		n = int(input())
		s = str(input())
		str_ans = ''
		can_clean = False
		for i in range(0, n - 1):
			if s[i] == '1' and s[i + 1] == '0':
				can_clean = True
				break
		if not can_clean:
			print(s)
			continue
		for i in range(0, n):
			if s[i] == '0':
				str_ans = str_ans + '0'
			else:
				break
		str_ans = str_ans + '0'
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				str_ans = str_ans + '1'
			else:
				break
		print(str_ans)
main()


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	n = int(fastinput())
	s = []
	for i in input():
		if not s:
			s.append([i, i])
		else:
			count = 0
			while s and (s[-1][0] == '1' and s[-1][1] == '0' or (s[-1][0] == '1' and s[-1][1] == '1')) and (i == '0'):
				s.pop()
				count += 1
			if count == 0:
				s.append([i, i])
			else:
				s.append(['1', '0'])
	for i in s:
		print(i[1], end='')
	print()


import sys
import math
from sys import stdin, stdout
from collections import deque, defaultdict
from math import ceil, floor, inf, sqrt, factorial, gcd, log2
from copy import deepcopy
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
for _ in range(ii1()):
	n = ii1()
	s = is1()
	flag = 0
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			flag = 1
			break
	if flag == 0:
		print(s)
		continue
	end = 1
	start = 1
	for i in range(n):
		if s[i] == '1':
			end = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			start = i
			break
	print(s[:end] + '0' + s[start + 1:])


t = int(input())
for i in range(0, t):
	n = int(input())
	s = input()
	z0 = ''
	z1 = ''
	k = 0
	for j in range(0, n):
		if s[j] == '0':
			if k == 0:
				z0 = z0 + s[j]
		else:
			k = -1
	k = 0
	for j in range(0, n):
		if s[n - j - 1] == '1':
			if k == 0:
				z1 = z1 + s[n - j - 1]
		else:
			k = -1
	zf = z0 + z1
	if len(zf) == n:
		print(zf)
	elif len(z1) == 0 and len(z0) == 0:
		print('0')
	elif len(z1) == 0:
		print(zf + '0')
	elif len(z0) == 0:
		print('0' + zf)
	else:
		print(z0 + '0' + z1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	f = 0
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '0':
			f = 1
			break
	if f == 1:
		c1 = c2 = 0
		for i in range(n):
			if s[i] == '1':
				break
			c1 += 1
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				break
			c2 += 1
		print('0' * (c1 + 1) + '1' * c2)
	else:
		print(s)


import sys
sys.setrecursionlimit(10000)
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	len0 = s.find('1')
	if len0 == -1:
		print(s)
		continue
	ans = '0' * len0
	got1 = True
	got0 = False
	total0 = 0
	for i in range(len0, n):
		if s[i] == '0' and got0 is False:
			total0 += 1
			got0 = True
		elif s[i] == '1' and got0 is True:
			got0 = False
	if total0 > 0:
		total0 = 1
	len1 = 0
	if got0 is False:
		reverse = s[::-1]
		len1 = reverse.find('0')
	if len1 < 0:
		print(s)
		continue
	ans += '0' * total0
	ans += '1' * len1
	print(ans)


for _ in ' ' * int(input()):
	a = int(input())
	b = input()
	b = b.replace('01', '0 1').replace('10', '1 0').split()
	k = ''
	if len(b) == 1:
		print(*b)
	elif len(b) == 2:
		if '0' in b[0]:
			for i in b:
				print(i, end='')
			print()
		else:
			print(0)
	else:
		k = ''
		r = len(b)
		u = 0
		for i in range(len(b)):
			if i == 0:
				if '0' in b[0]:
					k += b[0]
			elif i == r - 1:
				if '1' in b[i]:
					k += b[i]
			elif u == 0:
				k += '0'
				u = 1
		print(k)


import sys
t = int(input())
while t > 0:
	n = int(input())
	str = input()
	isDesc = False
	cur = 0
	while cur + 1 < n:
		if str[cur] == '1' and str[cur + 1] == '0':
			isDesc = True
			break
		cur += 1
	if isDesc:
		zeros = 0
		while zeros < n and str[zeros] == '0':
			zeros += 1
			sys.stdout.write('0')
		sys.stdout.write('0')
		ones = 0
		while ones < n and str[n - 1 - ones] == '1':
			ones += 1
			sys.stdout.write('1')
		print()
	else:
		print(str)
	t -= 1


t = int(input())
import math
for i in range(t):
	q = int(input())
	a = list(input())
	if a.count('1') == q or a.count('0') == q:
		print(''.join(a))
		continue
	c = 0
	for j in range(q - 1):
		if a[j] == '1' and a[j + 1] == '0':
			c += 1
	if c == 0:
		print(''.join(a))
		continue
	else:
		if a[0] == '1' and a[len(a) - 1] == '0':
			print(0)
			continue
		if a[0] == '0' and a[len(a) - 1] == '1':
			c = 0
			for i in range(len(a) - 1, -1, -1):
				if a[i] == '1':
					c += 1
				else:
					break
			x = 0
			for i in range(len(a)):
				if a[i] == '0':
					x += 1
				else:
					break
			print('0' * x + '0' + c * '1')
			continue
		if a[0] == '1' and a[len(a) - 1] == '1':
			c = 0
			for i in range(len(a) - 1, -1, -1):
				if a[i] == '1':
					c += 1
				else:
					break
			print('0' + c * '1')
			continue
		if a[0] == '0' and a[len(a) - 1] == '0':
			x = 0
			for i in a:
				if i == '0':
					x += 1
				else:
					break
			print(x * '0' + '0')
			continue


import math

def isPrimes2(n):
	if n > 1:
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		for x in range(3, int(math.sqrt(n) + 1), 2):
			if n % x == 0:
				return False
		return True
	return False

def isok(n):
	while n != 1:
		if n % 2 == 1:
			return False
		n /= 2
	return True

def main():
	t = int(input())
	for i in range(t):
		k = int(input())
		s = input()
		if '1' in s and '0' in s:
			ans = ''
			flag1 = 0
			flag0 = 0
			for i in range(len(s)):
				if s[i] == '1':
					flag1 = i
					break
			for i in range(len(s)):
				if s[-i - 1] == '0':
					flag0 = i
					break
			if flag0 + flag1 + 2 > len(s):
				print(s)
			else:
				ans = s[0:flag1] + '0' + s[len(s) - flag0:len(s)]
				print(ans)
		else:
			print(s)
main()


def solve():
	n = int(input())
	s = input()
	b1 = -1
	e0 = -1
	for (i, c) in enumerate(s):
		if c == '1' and b1 == -1:
			b1 = i
		if c == '0':
			e0 = i
	if b1 - 1 == e0 or b1 == -1 or e0 == -1:
		print(s)
	else:
		e0 = n - e0 - 1
		print('0' * (b1 + 1) + '1' * e0)
t = int(input())
for _ in range(t):
	solve()


for t in range(int(input())):
	n = int(input())
	s = input()
	one = s.find('1')
	zero = s.rfind('0')
	if one >= 0 and zero >= 0 and (zero > one):
		print(s[:one] + '0' + s[zero + 1:])
	else:
		print(s)


def main(n, s):
	if ''.join(sorted(s)) == s:
		return s
	(l1, r0) = (0, 0)
	for i in range(n):
		if s[i] == '1':
			l1 = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			r0 = i
			break
	return s[:l1] + s[r0:]
for i in range(int(input())):
	n = int(input())
	s = input()
	print(main(n, s))


T = int(input())

def solve(s):
	(start, end) = (-1, -1)
	for i in range(0, len(s)):
		if s[i] == '1':
			start = i
			break
	for j in range(i, len(s)):
		if s[j] == '0':
			end = j
	if start != -1 and end != -1:
		return s[0:start] + s[end:]
	return -1
while T > 0:
	l = int(input())
	s = input()
	ans = solve(s)
	if ans == -1:
		print(s)
	else:
		print(ans)
	T -= 1


import sys

def main():
	n = int(input())
	for _ in range(n):
		length = int(input())
		string = input()
		if dec(string) or len(string) == 1:
			print(string)
		else:
			x = 1
			y = 0
			for i in range(len(string)):
				if string[i] == '0':
					x += 1
				else:
					break
			for j in range(len(string)):
				if string[len(string) - 1 - j] == '1':
					y += 1
				else:
					break
			s = ''
			for _ in range(x):
				s += '0'
			for _ in range(y):
				s += '1'
			print(s)

def dec(s):
	for i in range(len(s) - 1):
		if int(s[i]) > int(s[i + 1]):
			return False
	return True
main()


for ad in range(int(input())):
	n = int(input())
	s = input()
	l = set(list(s))
	t = 0
	x = ''
	if len(l) == 2:
		for i in range(n):
			if s[i] == '0':
				x += '0'
			else:
				break
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				x += '1'
			else:
				break
		if len(x) != n:
			x = '0' + x
		print(x)
	else:
		print(s)


import sys
import math
from collections import defaultdict

def solve(test):
	n = int(input())
	s = list(input())
	if '1' not in s or '0' not in s:
		print(''.join(s))
		return
	idx = -1
	f1 = s.index('1')
	for i in range(n):
		if s[i] == '0':
			idx = i
	if idx < f1:
		print(''.join(s))
	else:
		ans = ''.join(s[:f1]) + ''.join(s[idx:])
		print(ans)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


def main():
	n = int(input())
	s = input()
	n0 = 0
	for i in range(n):
		if s[i] != '0':
			break
		n0 += 1
	n1 = 0
	for i in range(n):
		if s[n - i - 1] != '1':
			break
		n1 += 1
	mid = ''
	if n0 + n1 < n:
		mid = '0'
	return '0' * n0 + mid + '1' * n1
for _ in range(int(input())):
	print(main())


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	if s == sorted(s):
		print(''.join(s))
		continue
	i = 0
	cz = co = 0
	while s[i] == '0':
		cz += 1
		i += 1
	i = n - 1
	while s[i] == '1':
		co += 1
		i -= 1
	print('0' * (cz + 1), '1' * co, sep='')


for _ in range(int(input())):
	n = int(input())
	st = input()
	ans = ''
	for i in range(n):
		if st[i] == '0':
			ans += st[i]
		else:
			i = i - 1
			break
	for j in range(n - 1, -1, -1):
		if st[j] == '1':
			continue
		else:
			break
	if i == j:
		print(st)
	else:
		print(ans + st[j:])


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(str(input()))
	zero = 0
	one = 0
	E = 0
	for i in range(n):
		if s[i] == '0':
			zero += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			one += 1
		else:
			break
	for i in range(n - 1):
		if s[i] != s[i + 1]:
			E += 1
	print(max('0', '0' * zero + '0' * int(E > 1) + '1' * one))


t = int(input())
for T in range(t):
	n = int(input())
	s = input()
	count1 = 0
	count0 = 0
	countl1 = 0
	last = True
	first = True
	for i in range(n - 1, -1, -1):
		if s[i] == '1' and last:
			countl1 += 1
		else:
			break
	for i in range(n):
		if s[i] == '0' and first:
			count0 += 1
		else:
			break
	ans = ''
	for i in range(count0):
		ans += '0'
	if n > count0 + countl1:
		ans += '0'
	for i in range(countl1):
		ans += '1'
	print(ans)


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	if list(s) == sorted(list(s)):
		print(s)
	else:
		(left, right) = (1, 1)
		for i in range(n):
			if s[i] == '1':
				left = i
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				right = i
				break
		print(s[:left] + '0' + s[right + 1:])


for k in range(int(input())):
	n = int(input())
	t = list(input())
	if t.count('1') == 0:
		print(''.join(t))
	elif t.count('0') == 0:
		print(''.join(t))
	else:
		a = t.index('1')
		b = t[::-1].index('0')
		B = n - 1 - b
		if a > B:
			print(''.join(t))
		else:
			s = ''.join(t[:a]) + ''.join(t[B:])
			print(s)


test = int(input())
for t in range(test):
	n = int(input())
	s = input()
	array = list(s)
	array1 = array.copy()
	array1.sort()
	array2 = array1.copy()
	array2.reverse()
	if array1 == array:
		print(s)
	elif array2 == array and set(array) == {'0', '1'}:
		print(0)
	elif array1 != array and array2 != array and (set(array) == {'0', '1'}):
		if s[n - 1] == '0':
			for i in range(len(s)):
				if s[i] == '1':
					break
			ans = '0' * i
			print(ans + '0')
		else:
			for i in range(len(s)):
				if s[i] == '1':
					break
			ans = '0' * i
			count = 0
			for i in range(n - 1, -1, -1):
				if s[i] == '0':
					break
			ans2 = '1' * (n - i - 1)
			print(ans + '0' + ans2)


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(S):
	ans = []
	S = S[::-1]
	for c in S:
		if c == '1':
			if ans and ans[-1] == '0':
				while ans and ans[-1] == '0':
					ans.pop()
				ans.append('0')
			else:
				ans.append('1')
		else:
			ans.append('0')
	return ''.join(ans)[::-1]

def main():
	T = read_int()
	for _ in range(T):
		read_int()
		S = read_str()
		print(slv(S))
main()


def solve(n, s):
	k_10 = False
	for i in range(1, n):
		if s[i - 1] > s[i]:
			k_10 = True
			break
	if not k_10:
		return s
	i = 0
	while i < n and s[i] == '0':
		i += 1
	m = i
	i = n - 1
	while i >= 0 and s[i] == '1':
		i -= 1
	k = n - i - 1
	return '0' * m + '0' + '1' * k
t = int(input())
results = []
for i in range(0, t):
	n = int(input())
	s = input()
	results.append(solve(n, s))
for i in results:
	print(i)


for _ in range(int(input())):
	n = int(input())
	s = input()
	stack = []
	for i in range(n - 1, -1, -1):
		num = s[i]
		if num == '0':
			stack.append(num)
		elif len(stack) == 0:
			stack.append(num)
		elif stack[-1] == '0':
			while stack and stack[-1] == '0':
				stack.pop()
			stack.append('0')
		else:
			stack.append('1')
	print(''.join(stack[::-1]))


a = int(input())
for i in range(a):
	b = int(input())
	s = str(input())
	c = 0
	i1 = -1
	i2 = -1
	for j in range(len(s)):
		if s[j] == '1':
			i1 = j
			break
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '0':
			i2 = j
			break
	if i1 > i2:
		print(s)
	else:
		s = s[:i1] + s[i2:]
		print(s)


import os
os_input = os.read(0, int(10000000.0)).split()
os_input_pos = -1
answer_list = []

def read_s():
	global os_input_pos
	os_input_pos += 1
	return os_input[os_input_pos].decode()

def read_i():
	return int(read_s())

def write_s(v):
	answer_list.append(v)

def write_i(v):
	write_s(str(v))

def print_ans():
	os.write(1, '\n'.join(answer_list).encode())
	os.write(1, '\n'.encode())
T = read_i()
while T:
	T -= 1
	n = read_i()
	s = read_s()
	head = []
	tail = []
	for c in s:
		if c == '1':
			break
		head.append(c)
	for c in reversed(s):
		if c == '0':
			break
		tail.append(c)
	if len(head) + len(tail) == len(s):
		write_s(s)
	else:
		write_s(''.join(head) + '0' + ''.join(tail))
print_ans()


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	lst = [ch for ch in s]
	one_pos = -1
	zero_pos = -1
	for i in range(n):
		if lst[i] == '1':
			one_pos = i
			break
	for i in range(n - 1, -1, -1):
		if lst[i] == '0':
			zero_pos = i
			break
	if one_pos == -1 or zero_pos == -1:
		print(s)
	elif one_pos < zero_pos:
		print(''.join(lst[:one_pos] + lst[zero_pos:]))
	else:
		print(s)
	t -= 1


t = int(input())
for z in range(t):
	n = int(input())
	s = input()
	l = list()
	c = 0
	i = 0
	j = n - 1
	a = ''
	b = ''
	if len(s) > 1:
		while s[i] == '0' and i < n - 1:
			a += '0'
			if i == n - 1:
				break
			else:
				i += 1
		while s[j] == '1':
			b += '1'
			if j == 0:
				break
			else:
				j -= 1
		for k in range(i, j + 1):
			if s[k] == '0':
				a += '0'
				break
		a += b
		print(a)
		continue
	else:
		print(s)


t = int(input())
for i in range(t):
	ans = []
	n = int(input())
	s = list(input())
	for j in range(len(s)):
		if s[j] == '0':
			ans.append(str(s[j]))
		elif s[j] == '1':
			break
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '1':
			ans.append(str(s[j]))
		elif s[j] == '0':
			break
	if len(ans) == len(s):
		print(''.join(ans))
	else:
		ans.insert(0, '0')
		print(''.join(ans))


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 10 ** 9 + 7

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

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k)))) % NUMBER
from collections import deque, defaultdict
import heapq
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

def dfs(g, timeIn, timeOut, depths, parents):
	cnt = 0
	stack = [[1, 0, 0, 0]]
	while stack:
		(v, neig_i, parent, depth) = stack[-1]
		parents[v] = parent
		depths[v] = depth
		if neig_i == 0:
			timeIn[v] = cnt
			cnt += 1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i += 1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u, 0, v, depth + 1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
cnt = 0

@bootstrap
def dfs(v, adj, timeIn, timeOut, depths, parents, parent=0, depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt += 1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u, adj, timeIn, timeOut, depths, parents, v, depth + 1)
	timeOut[v] = cnt
	cnt += 1
	yield

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

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

def solution(s, n):
	sol = []
	if '1' not in s or '0' not in s:
		return ''.join(s)
	i = -1
	while s[i + 1] == '0' and i < n - 1:
		sol.append('0')
		i += 1
	if i == n:
		return ''.join(sol)
	ones_end = []
	j = n
	while s[j - 1] == '1' and j > 0:
		ones_end.append('1')
		j -= 1
	if j <= i + 1:
		return ''.join(sol + ones_end)
	return ''.join(sol + ['0'] + ones_end)

def main():
	T = ri()
	for i in range(T):
		n = ri()
		s = rs()
		x = solution(s, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	if '10' in s:
		(i, j) = (0, n)
		while s[i] == '0':
			i += 1
		while s[j - 1] == '1':
			j -= 1
		print(s[:i] + '0' + s[j:])
	else:
		print(s)


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	a = ''
	i = 0
	(oc, zc) = (0, 0)
	while i < n:
		if s[i] == '0':
			a = a + s[i]
		else:
			break
		i = i + 1
	while i < n - 1:
		if s[i] == '1' and s[i + 1] == '0':
			a = a + '0'
			break
		i = i + 1
	i = n - 1
	while i >= 0:
		if s[i] == '1':
			a = a + s[i]
		else:
			break
		i = i - 1
	print(a)


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	if n == 1:
		print(s)
		continue
	zeros = [0] * (n + 1)
	if s[n - 1] == '0':
		zeros[n - 1] = 1
	for i in range(n - 2, -1, -1):
		if s[i] == '0':
			zeros[i] += 1
		zeros[i] += zeros[i + 1]
	ones = [0] * n
	if s[0] == '1':
		ones[0] = 1
	for i in range(1, n):
		if s[i] == '1':
			ones[i] += 1
		ones[i] += ones[i - 1]
	fin = ''
	i = 0
	while i < n:
		if s[i] == '0':
			if ones[i] == 0:
				fin += '0'
			elif zeros[i + 1] == 0:
				fin += '0'
		elif zeros[i] == 0:
			fin += '1'
		i += 1
	print(fin)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	s = inputstring()
	firstone = -1
	hasone = False
	lastzero = -1
	for i in range(n):
		if s[i] == '1' and (not hasone):
			firstone = i
			hasone = True
		if s[i] == '0':
			lastzero = i
	if lastzero == -1 or firstone == -1 or lastzero < firstone:
		for c in s:
			print(c, end='')
		print()
		continue
	rtn = ''
	for i in range(n):
		if i < firstone or i >= lastzero:
			rtn += s[i]
	print(rtn)


import sys
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
from collections import defaultdict as df
from math import *
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	s = input().strip()
	if n == 1:
		print(s)
		continue
	i = 0
	ans = ''
	while i < n and s[i] == '0':
		ans += s[i]
		i += 1
	if i == n:
		print(ans)
		continue
	j = n - 1
	ans2 = ''
	while j >= 0 and s[j] == '1':
		ans2 += s[j]
		j -= 1
	if j == -1:
		print(ans2[::-1])
		continue
	if i == j + 1:
		print(ans + ans2[::-1])
		continue
	else:
		print(ans + '0' + ans2[::-1])


def solution():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		ans = ''
		z = ''
		if '0' not in s:
			print(s)
		elif '1' not in s:
			print(s)
		else:
			s = list(s)
			i = 0
			while s[i] == '0':
				ans += s[i]
				i += 1
			z = s[i]
			for j in range(i + 1, n):
				if s[j] == '0':
					z = '0'
				else:
					z += '1'
			if z != '':
				ans += z
			print(ans)
solution()


from sys import stdin
for _ in [0] * int(input()):
	a = int(stdin.readline().rstrip())
	s = stdin.readline().rstrip()
	z = -1
	o = -1
	for i in range(a):
		if s[i] == '0':
			z = i
		elif s[i] == '1' and o == -1:
			o = i
	if o == -1 or z == -1:
		print(s)
	elif z < o:
		print(s)
	else:
		print('0' * (o + 1), end='')
		print('1' * (a - z - 1))


def solve(n, s):
	is10 = False
	for i in range(1, n):
		if s[i - 1] > s[i]:
			is10 = True
			break
	if not is10:
		return s
	i = 0
	while i < n and s[i] == '0':
		i += 1
	zero1 = i
	i = n - 1
	while i >= 0 and s[i] == '1':
		i -= 1
	ones = n - i - 1
	return '0' * zero1 + '0' + '1' * ones
t = int(input())
results = []
for _ in range(0, t):
	n = int(input())
	s = input()
	results.append(solve(n, s))
for result in results:
	print(result)


T = int(input())

def solve(x):
	first_one = x.find('1')
	last_zero = x[::-1].find('0')
	if first_one == -1 or last_zero == -1:
		return x
	last_zero = len(x) - 1 - last_zero
	if first_one >= last_zero:
		return x
	return x[:first_one] + x[last_zero:]
for _ in range(T):
	_ = input()
	print(solve(input()))


for _ in range(int(input())):
	n = int(input())
	s = input()
	zes = 0
	lao = 0
	f1 = 0
	for i in s:
		if i == '0':
			zes += 1
		else:
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			lao += 1
		else:
			break
	if zes == n - lao:
		for i in range(zes):
			print(0, end='')
		for i in range(lao):
			print(1, end='')
		print()
	else:
		for i in range(zes + 1):
			print(0, end='')
		for i in range(lao):
			print(1, end='')
		print()


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heappushpop, heapreplace

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

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

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

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

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

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
mod = 1000000007
res = ['Yes', 'No']
test_case = ii()
while test_case:
	test_case -= 1
	n = ii()
	a = lsi()
	o = z = -1
	for i in range(n):
		if a[i] == '0':
			z = i
		elif o < 0:
			o = i
	if o > -1 and z > -1 and (z > o):
		a = a[:o] + a[z:]
	print(*a, sep='')


import sys
input = sys.stdin.readline

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

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

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

def getStr():
	return input().strip()
q = getInt()
for _ in range(q):
	n = getInt()
	s = getStr()
	first1 = s.find('1')
	last0 = s.rfind('0')
	res1 = ''
	res2 = ''
	if first1 > -1 and last0 > -1 and (first1 < last0):
		res = ''
		if first1 > 0:
			res += s[:first1]
		res += '0'
		res += s[last0 + 1:]
	else:
		res = s
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	first_one = -1
	last_zero = -1
	for (i, c) in enumerate(s):
		if c == '1' and first_one == -1:
			first_one = i
		if c == '0':
			last_zero = i
	if first_one > last_zero:
		print(s)
	else:
		print(s[:first_one] + s[last_zero:])


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ans = []
	if '1' in s:
		id = s.index('1')
		ans.append(s[:id])
		s = s[id:]
		if '0' in s:
			id = s[::-1].index('0')
			ans.append(s[-1 - id:])
			print(''.join(ans))
		else:
			ans.append(s)
			print(''.join(ans))
	else:
		print(s)


from sys import stdin, stdout
from sys import maxsize

def solve(s):
	b = ''
	c = ''
	d = ''
	while len(s) > 0 and s[0] == '0':
		b += '0'
		s.pop(0)
	s.reverse()
	while len(s) > 0 and s[0] == '1':
		c += '1'
		s.pop(0)
	if len(s) != 0:
		d += '0'
	ans = b + d + c
	print(ans)
	pass
test = 1
test = int(input())
for t in range(0, test):
	n = int(input())
	s = list(input())
	ans = solve(s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	z = s.rfind('0')
	o = s.find('1')
	if o < z:
		print(s[:o] + '0' + s[z + 1:])
	else:
		print(s)


T = int(input())
for _ in range(T):
	N = int(input())
	s = input()
	(f1, l0) = (s.find('1'), s.rfind('0'))
	if f1 == -1 or l0 == -1 or l0 < f1:
		print(s)
	else:
		print(s[:f1] + s[l0:])


import math

def main():
	t = Iint()
	for _ in range(t):
		n = Iint()
		s = I()
		if '0' not in s or '1' not in s:
			print(s)
			continue
		if s.lstrip('0').rstrip('1') == '':
			print(s)
			continue
		for i in range(n - 1, -1, -1):
			if s[i] != '1':
				break
		last1 = '1' * (n - 1 - i)
		for i in range(n):
			if s[i] != '0':
				break
		first0 = '0' * (i + 1)
		ans = first0 + last1
		print(ans)

def I():
	return input()

def Iint():
	return int(input())

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

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

def Plist(li, s=' '):
	print(s.join(map(str, li)))
FIO = True
if FIO:
	from io import BytesIO, IOBase
	import sys
	import os
en = enumerate
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
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))

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


def fn(n, s):
	a = ''
	for i in range(n):
		if s[i] == '1':
			break
		a = a + s[i]
	if i == n - 1:
		return s
	x = i
	b = ''
	for i in range(n - 1, -1, -1):
		b = b + s[i]
		if s[i] == '0':
			break
	if i < x:
		return s
	return a + b[::-1]
for _ in range(int(input())):
	n = int(input())
	s = input()
	print(fn(n, s))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	first0 = -1
	last1 = -1
	count10 = 0
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '0':
			count10 += 1
	for i in range(n):
		if s[i] == '0':
			first0 = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			last1 = i
			break
	if count10 == 0:
		print(s)
		continue
	ans = []
	if first0 == 0:
		for j in range(n):
			if s[j] == '0':
				ans.append('0')
			else:
				break
	ans.append('0')
	if last1 == n - 1:
		for j in range(n - 1, -1, -1):
			if s[j] == '1':
				ans.append('1')
			else:
				break
	print(''.join(ans))


import queue
import math
t = int(input())
while t:
	n = int(input())
	s = input()
	(pref, suff) = (0, 0)
	for i in range(n):
		if s[i] == '0':
			pref += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			suff += 1
		else:
			break
	for i in range(pref):
		print('0', end='')
	if pref + suff < n:
		print('0', end='')
	for i in range(suff):
		print('1', end='')
	print()
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	arr = input()
	last = -1
	for i in range(n - 1, -1, -1):
		if arr[i] == '0':
			break
	last = i
	flag = 0
	ans = ''
	for i in range(last):
		if arr[i] == '0' and flag == 0:
			ans += arr[i]
		if arr[i] == '1':
			flag = 1
	ans = ans + arr[last:]
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	i = 0
	while i < len(s):
		if i + 1 < len(s):
			if s[i] == '1' and s[i + 1] == '0':
				if s.find('1', 0, i) != -1:
					s = s[:i] + s[i + 1:]
					i -= 1
				elif s.find('0', i + 2, len(s)) != -1:
					s = s[:i + 1] + s[i + 2:]
				else:
					s = s[:i] + s[i + 1:]
					i += 1
			else:
				i += 1
		else:
			i += 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if s == '0' * n or s == '1' * n:
		print(s)
		continue
	a = s.find('1')
	b = s[::-1].find('0')
	if a + b == n:
		print(s)
		continue
	print('0' * (a + 1) + '1' * b)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, list(input())))
	zero = 0
	one = 0
	for i in a:
		if i == 0:
			zero += 1
		else:
			break
	a = a[zero:]
	a = a[::-1]
	for i in a:
		if i == 1:
			one += 1
		else:
			break
	if zero + one == n:
		s = '0' * zero + '1' * one
		print(s)
	else:
		s = '0' * zero + '0' + '1' * one
		print(s)


for z in range(int(input())):
	n = int(input())
	arr = list(input())
	i = 0
	(s, e) = ('', '')
	while i <= n - 1 and arr[i] == '0':
		s += arr[i]
		i += 1
	i = n - 1
	while i >= 0 and arr[i] == '1':
		e += arr[i]
		i -= 1
	if len(s) + len(e) != n:
		print(s + '0' + e)
	else:
		print(s + e)


for _ in range(int(input())):
	n = int(input())
	st = input()
	arr = []
	val = ''
	for i in range(n):
		if val == '':
			val += st[i]
		elif val[-1] != st[i]:
			arr.append(val)
			val = st[i]
		else:
			val += st[i]
	if val != '':
		arr.append(val)
	ans = ''
	arr = arr[::-1]
	i = 0
	flag = 0
	while i < len(arr):
		if i != len(arr) - 1 and arr[i][0] == '0' and (arr[i + 1][0] == '1') and (flag == 0):
			ans += '0'
			flag = 1
			i += 1
		elif i != len(arr) - 1 and arr[i][0] == '0' and (arr[i + 1][0] == '1') and (flag == 1):
			i += 1
		else:
			ans += arr[i]
		i += 1
	print(ans[::-1])


for _ in range(int(input())):
	n = int(input())
	s = input()
	s1 = [i for i in s.split('0') if i != '']
	s2 = [i for i in s.split('1') if i != '']
	if s[0] == '0':
		if len(s1) == 0:
			print(s)
		elif len(s1) == len(s2) == 1:
			print(s)
		elif s[-1] == '0':
			print(s2[0] + '0')
		else:
			print(s2[0] + '0' + s1[-1])
	elif len(s2) == 0:
		print(s)
	elif s[-1] == '0':
		print('0')
	else:
		print('0' + s1[-1])


for tt in range(int(input())):
	n = int(input())
	s = input()
	(left, right, flag) = (0, 0, True)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			flag = False
			break
	if flag:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			left = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			right = i
			break
	print(s[:left] + '0' + s[right + 1:])


def split(s):
	return [char for char in s]
y = int(input())
for i in range(y):
	length = int(input())
	bin = split(input())
	oz = False
	for i in range(length - 1):
		if bin[i] > bin[i + 1]:
			oz = True
			break
	if oz == False:
		print(''.join(bin))
		continue
	l = bin.index('1', 0, len(bin))
	r = len(bin) - bin[::-1].index('0') - 1
	print(f"{''.join(bin[:l])}0{''.join(bin[r + 1:])}")


for _ in range(int(input())):
	n = int(input())
	s = input()
	j = -1
	sp = ''
	for i in range(0, n):
		if s[i] == '0':
			j = i
	k = -1
	for i in range(0, n):
		if s[i] == '1':
			k = i
			break
	if k < j:
		print(s[0:k] + s[j:])
	else:
		print(s)


import re
from functools import cmp_to_key

def memoize(f):
	memo = {}

	def helper(x):
		if x not in memo:
			memo[x] = f(x)
		return memo[x]
	return helper

def compare(x, y):
	if len(x) < len(y):
		return -1
	elif len(y) < len(x):
		return 1
	else:
		for idx in range(len(x)):
			i_x = int(x[idx])
			i_y = int(y[idx])
			if i_x < i_y:
				return -1
			elif i_y < i_x:
				return 1
	return 0

def solve_old(s):
	stack = [s]
	out = []
	while len(stack) > 0:
		s = stack.pop()
		if s.count('10') == 0:
			out.append(s)
		else:
			new_s = [replacer(s, match.span(), '0') for match in re.finditer('1+0+', s)]
			stack.extend(new_s)
	return sorted(out, key=cmp_to_key(compare))[0]

def solve_old2(s):
	while s.count('10') > 0:
		(*_, last_match) = re.finditer('1+0+', s)
		s = replacer(s, last_match.span(), replacement='0')
	return s

def solve(xs):
	prefix = 0
	suffix = 0
	middle = ''
	for idx in range(len(xs)):
		if xs[idx] != 0:
			break
		else:
			prefix += 1
	for idx in range(len(xs) - 1, -1, -1):
		if xs[idx] != 1:
			break
		else:
			suffix += 1
	if len(xs) > prefix + suffix:
		middle = '0'
	return '0' * prefix + middle + '1' * suffix

def replacer(s, span, replacement='0'):
	return s[:span[0]] + replacement + s[span[1]:]

def main():
	T = int(input())
	for _ in range(T):
		l = int(input())
		s = list(map(int, input()))
		print(solve(s))
main()


def solve(n, s):
	seq = []
	index = 0
	while index < len(s):
		left = index
		left_start = index
		while s[left] == '1':
			left += 1
			if left == len(s):
				break
		if left == index or left == len(s):
			index += 1
			continue
		left -= 1
		right = left + 1
		while s[right] == '0':
			right += 1
			if right == len(s):
				break
		right -= 1
		if s[left_start] == '1' and s[right] == '0':
			seq.append((left_start, right))
		index = left + 1
	if len(seq) == 0:
		answ = s
	elif len(seq) == 1:
		if seq[0][1] == n - 1:
			answ = s[:seq[0][0]] + '0'
		else:
			answ = s[:seq[0][0]] + '0' + s[seq[-1][1] + 1:]
	else:
		answ = s[:seq[0][0]] + '0' + s[seq[-1][1] + 1:]
	print(answ)
t = int(input())
while t:
	n = int(input())
	s = input()
	solve(n, s)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = ''
	i = 0
	while i < n:
		if s[i] == '0':
			x += s[i]
			i += 1
		else:
			j = n - 1
			while j >= i:
				if s[j] == '0':
					x += '0'
					break
				j -= 1
			x += '1' * (n - 1 - j)
			break
	print(x)


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	n = I()
	a = input().strip()
	b = []
	i = 0
	flag = -1
	k = -1
	for i in range(n):
		if a[i] == '1':
			flag = i
			break
	for i in range(n):
		if a[i] == '0':
			k = i
	if flag >= k:
		print(a)
	else:
		print(a[:flag] + a[k:])
for _ in range(I()):
	solve()


import math

def func(n, a):
	i = 0
	x = ''
	y = ''
	while i < n and a[i] == '0':
		x += a[i]
		i += 1
	j = n - 1
	while j >= 0 and a[j] == '1':
		y += a[j]
		j -= 1
	if i == j + 1:
		print(x + y)
	else:
		print(x + '0' + y)
for _ in range(int(input())):
	n = int(input())
	a = list(input())
	func(n, a)


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	if '10' not in s:
		print(s)
		continue
	f = s.index('1')
	for i in range(n):
		if s[i] == '0':
			d = i
	s1 = s[:f] + '0' + s[d + 1:]
	print(''.join(s1))


import math
import datetime
import collections
import statistics
import itertools

def is_prime(num):
	for i in range(2, int(math.sqrt(num)) + 1):
		if num % i == 0:
			return False
	return True

def input_list():
	ll = list(map(int, input().split(' ')))
	return ll
tc = int(input())
while tc:
	n = int(input())
	s = list(input())
	oo = 0
	ii = 0
	for i in range(0, n):
		if s[i] == '0':
			oo += 1
		else:
			break
	vv = s
	vv = vv[::-1]
	for i in range(0, n):
		if vv[i] == '1':
			ii += 1
		else:
			break
	cc = False
	if len(s) > ii + oo:
		cc = True
	if cc:
		rf = ['0'] * (oo + 1) + ['1'] * ii
		rf = ''.join(rf)
	else:
		rf = ['0'] * oo + ['1'] * ii
		rf = ''.join(rf)
	print(rf)
	tc -= 1


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	(flag1, flag2) = (False, False)
	for i in range(n):
		if s[i] == '1':
			flag1 = True
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '0':
			flag2 = True
			break
	if flag1 and flag2:
		if i - j != 1:
			print(s[:i] + '0' + s[j + 1:])
		else:
			print(s)
	else:
		print(s)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import heapq

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

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

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

def main():
	try:
		n = I()
		l = list(input())
		(no0, no1) = (-1, -1)
		for x in range(n):
			if no1 == -1 and l[x] == '1':
				no1 = x
			elif l[x] == '0':
				no0 = x
		if no0 == -1 or no1 == -1:
			print(''.join(l))
		else:
			if no0 < no1:
				ans = ['0'] * no1
			else:
				ans = ['0'] * (no1 + 1)
			for i in range(n - (no0 + 1)):
				ans.append('1')
			print(''.join(ans))
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


t = int(input())
for i in range(t):
	n = int(input())
	st = input()
	lis = list(st)
	found = 0
	f0 = 0
	f1 = 0
	for k in range(len(lis) - 1, -1, -1):
		if lis[k] == '0' and found == 0:
			end = k
			found = 1
			f0 = 1
		elif lis[k] == '1' and found == 1:
			start = k
			f1 = 1
	s = ''
	if f1 == 0 or f0 == 0:
		print(st)
	else:
		del lis[start:end]
		print(s.join(lis))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if '0' not in s or '1' not in s:
		print(s)
		continue
	first1 = s.index('1')
	last0 = n - s[::-1].index('0') - 1
	if last0 < first1:
		print(s)
		continue
	out = s[:first1] + '0' + s[last0 + 1:]
	print(out)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, S):
	S = deque(S)
	head = []
	while S and S[0] == '0':
		head.append(S.popleft())
	tail = []
	while S and S[-1] == '1':
		tail.append(S.pop())
	mid = ''
	if S:
		mid = '0'
	return ''.join(head) + mid + ''.join(tail)
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	S = input().decode().rstrip()
	ans = solve(N, S)
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

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

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

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	n = int(ri())
	s = ri()
	start = -1
	for i in range(len(s)):
		if s[i] == '1':
			start = i
			break
	end = -1
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '0':
			end = i
			break
	if start == -1 or end == -1 or start > end:
		print(s)
	else:
		ans = s[:start]
		ans = [i for i in ans]
		ans.append('0')
		for i in range(end + 1, len(s)):
			ans.append(s[i])
		print(''.join(ans))


from sys import stdin
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	s = stdin.readline().strip()
	begin = 0
	end = n - 1
	while begin < n and s[begin] == '0':
		begin += 1
	while end >= 0 and s[end] == '1':
		end -= 1
	if begin < end:
		print(s[:begin] + '0' + s[end + 1:])
	else:
		print(s[:begin] + s[end + 1:])


for _ in range(int(input())):
	l = int(input())
	s = input()
	i = j = 0
	while i < l and s[i] == '0':
		i = i + 1
	while j < l and s[l - j - 1] == '1':
		j = j + 1
	if l > i + j:
		print(i * '0' + '0' + j * '1')
	else:
		print(i * '0' + j * '1')


def game(s):
	st = -1
	ed = 0
	for i in range(len(s)):
		if s[i] == '1':
			st = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '0':
			ed = i
			break
	if st > ed:
		print(s)
	else:
		print(s[:st] + s[ed:])
t = int(input())
while t:
	n = int(input())
	game(input())
	t = t - 1


t = int(input())
for i in range(0, t):
	n = int(input())
	s = input()
	numb1 = n - 1
	flag = False
	while numb1 >= 0:
		if s[numb1] == '0':
			break
		numb1 -= 1
	numb2 = 0
	flag = False
	while numb2 < n:
		if s[numb2] == '1':
			break
		numb2 += 1
	if numb2 > numb1:
		print(s)
	else:
		print(s[0:numb2] + s[numb1:n])


for _ in range(int(input())):
	n = int(input())
	s = input()
	fo = -1
	lz = -1
	for i in range(n):
		if s[i] == '1':
			fo = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			lz = i
			break
	if fo != -1 and lz != -1 and (fo < lz):
		print(s[:fo] + s[lz:])
	else:
		print(s)


from sys import stdin

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

def sinput():
	return input()

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

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	n = iinput()
	s = sinput()
	flag = False
	i = 0
	while i < n and s[i] == '0':
		i += 1
	if i < s.count('0'):
		i += 1
	ans = '0' * i
	j = n - 1
	while j >= 0 and s[j] == '1':
		j -= 1
	ans += '1' * (n - j - 1)
	print(ans)


def solve():
	n = int(input())
	s = [int(v) for v in input()]
	first1 = 0
	last0 = n - 1
	while first1 < n and (not s[first1]):
		first1 += 1
	while last0 >= 0 and s[last0]:
		last0 -= 1
	if first1 == n or last0 == -1:
		print(''.join((str(v) for v in s)))
		return
	ans = ''
	added = False
	for i in range(n):
		if i >= first1 and i <= last0:
			if not added:
				ans += '0'
				added = True
			continue
		ans += str(s[i])
	print(ans)
t = int(input())
for _ in range(t):
	solve()


for i in range(int(input())):
	n = int(input())
	s = input()
	fj = s.find('1')
	fz = s[::-1].find('0')
	if fz == -1 or fj == -1 or fj + fz == n:
		print(s)
	else:
		print('0' * (fj + 1) + '1' * fz)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict, Counter
from os import path
import bisect as bi
import heapq
mod = 10 ** 9 + 7

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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

	def minp():
		return map(int, input().split())
else:

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

	def minp():
		return map(int, stdin.readline().split())
for _ in range(inp()):
	n = inp()
	s = list(input())
	s = [int(x) for x in s]
	if s == sorted(s):
		print(*s, sep='')
		continue
	count_0 = 1
	count_1 = 0
	i = 0
	while s[i] != 1 and i < n:
		count_0 += 1
		i += 1
	i = n - 1
	while s[i] != 0 and i >= 0:
		count_1 += 1
		i -= 1
	for i in range(count_0):
		print(0, end='')
	for i in range(count_1):
		print(1, end='')
	print()


for _ in range(int(input())):
	l = int(input())
	s = input()
	if len(s) == 1:
		if s[0] == '1':
			print('1')
		else:
			print('0')
	else:
		s1 = s.count('0')
		s2 = s.count('1')
		c1 = 0
		c2 = 0
		for i in s:
			if i == '0':
				c1 += 1
			else:
				break
		for i in s[::-1]:
			if i == '1':
				c2 += 1
			else:
				break
		if c1 == s1 and c2 == s2:
			print(s)
		elif c1 == 0 and c2 == 0:
			print('0')
		else:
			print('0' * c1, end='')
			print('0', end='')
			print('1' * c2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ct_strt = 0
	ct_end = 0
	for i in range(n):
		if s[i] == '0':
			ct_strt += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			ct_end += 1
		else:
			break
	if ct_strt + ct_end != n:
		ct_strt += 1
	s_ans = '0' * ct_strt + '1' * ct_end
	print(s_ans)


import sys
n = int(sys.stdin.readline().strip())
inp = []
for i in range(n):
	sys.stdin.readline()
	inp.append(sys.stdin.readline().strip())
results = []
for each in inp:
	cand = each.split('1')[0] + '0' + each.split('0')[-1]
	if len(cand) > len(each):
		print(each)
	else:
		print(cand)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = []
	for i in range(n):
		if s[i] == '0':
			ans.append('0')
		else:
			break
	else:
		print(s)
		continue
	ans2 = []
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			ans2.append('1')
		else:
			break
	else:
		print(s)
		continue
	if len(ans) + len(ans2) == n:
		print(s)
		continue
	else:
		res = ans + ['0'] + ans2
		print(''.join(res))


for t in range(int(input())):
	n = int(input())
	s = input()
	if '10' not in s:
		print(s)
	else:
		i = 0
		while s[i] == '0':
			print('0', end='')
			i += 1
		print('0', end='')
		i = n - 1
		while s[i] == '1':
			print('1', end='')
			i -= 1
		print()


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input()))
	one = zer = fl = fr = 0
	ans = []
	for i in range(n):
		if s[i] == 1:
			one += 1
		else:
			zer += 1
	for i in range(n - 1, -1, -1):
		if s[i] == 1 and fl == 0:
			ans.append(s[i])
		elif s[i] == 0 and fl == 0:
			ans.append(s[i])
			fl = 1
		elif s[i] == 0 and one == 0:
			ans.append(s[i])
		if s[i] == 0:
			zer -= 1
		else:
			one -= 1
	ans.reverse()
	num = str(''.join(map(str, ans)))
	print(num)


a = input()
for x in range(int(a)):
	b = input()
	c = input()
	tag = -1
	tag1 = ''
	ans = ''
	for i in range(len(c)):
		if c[i] == '0':
			tag = i
			ans += '0'
		else:
			break
	for i in range(len(c) - 1, tag, -1):
		if c[i] == '1':
			tag1 = c[i] + tag1
		else:
			tag1 = c[i] + tag1
			break
	print(ans + tag1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = ''
	(firstone, currone) = (-1, -1)
	for i in range(len(s)):
		if s[i] == '1' and firstone == -1:
			firstone = i
			currone = i
		elif s[i] == '1' and currone == -1:
			currone = i
		elif s[i] == '0' and firstone == -1:
			ans += s[i]
		elif s[i] == '0':
			currone = -1
	if currone != firstone:
		ans += '0'
	if currone != -1:
		ans += (len(s) - currone) * '1'
	print(ans)


a = int(input())
for i in range(a):
	r = input()
	s = input()
	ans = []
	count = 1
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			count += 1
		else:
			ans.append(count)
			count = 1
	ans.append(count)
	if s[0] == '0':
		if len(ans) <= 2:
			print(s)
			continue
		if s[-1] == '0':
			print((ans[0] + 1) * '0')
		else:
			print(ans[0] * '0' + '0' + ans[-1] * '1')
	else:
		if len(ans) == 1:
			print(s)
			continue
		if s[-1] == '0':
			print(0)
			continue
		print('0' + ans[-1] * '1')


def solve(n, s):
	ans = ''
	if s.count('0') == 0 or s.count('1') == 0:
		return s
	start = s.index('1')
	end = s.rindex('0')
	if start > end:
		return s
	ans = s[0:start] + s[end:]
	return ans
t = int(input())
for we in range(t):
	n = int(input())
	s = input()
	print(solve(n, s))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	vals = [int(k) for k in input()]
	gaps = []
	lastzer = 0
	for s in range(n):
		if vals[s] == 1:
			gaps.append(s)
		elif vals[s] == 0:
			lastzer = s
	gaps.append(n)
	outy = ''
	for s in range(gaps[0]):
		outy += '0'
	if lastzer > gaps[0]:
		outy += '0'
		for s in range(n - 1 - lastzer):
			outy += '1'
		print(outy)
	else:
		back = [str(k) for k in vals]
		print(''.join(back))


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
from itertools import count
pi = 3.141592653589793

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

def IO():
	return stdin.readline()

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

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

def P(x):
	return stdout.write(str(x))

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

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

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def solve():
	n = II()
	s = input()
	if n == 1:
		print(s)
		return
	elif s[-1] == '0':
		ne = ''
		for i in range(n):
			if s[i] != '1':
				ne += '0'
			else:
				print(ne + '0')
				break
		else:
			print(ne)
	else:
		ne = ''
		for i in range(n):
			if s[i] == '1':
				found = False
				for j in range(i + 1, n):
					if s[j] == '0':
						found = True
						break
				if found == True:
					cnt = 0
					for k in range(n - 1, -1, -1):
						if s[k] == '0':
							break
						else:
							cnt += 1
					print(ne + '0' + '1' * cnt)
					return
				else:
					print(s)
					return
			else:
				ne += '0'
t = II()
for i in range(t):
	solve()


import sys

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

def main(N, string):
	zeros = [0] * N
	zeros[-1] = 1 if string[-1] == '0' else 0
	stack = []
	for i in reversed(range(N - 1)):
		zeros[i] = zeros[i + 1]
		if string[i] == '0':
			zeros[i] += 1
	ones = 0
	for i in range(N):
		if stack and stack[-1] == '1' and (string[i] == '0'):
			if ones >= zeros[i]:
				while stack and stack[-1] == '1' and (string[i] == '0') and (ones >= zeros[i]):
					stack.pop()
					ones -= 1
				if not stack or stack[-1] != '1':
					stack.append(string[i])
		else:
			stack.append(string[i])
			if string[i] == '1':
				ones += 1
	print(''.join(stack))
n = int(input())
for i in range(n):
	N = int(input())
	string = get_string()
	main(N, string)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2
for _ in range(int(input())):
	n = int(input())
	li = input()
	if '1' not in li or '0' not in li:
		print(li)
	else:
		f = li.index('1')
		r = n - 1 - li[::-1].index('0')
		if r < f:
			print(li)
		else:
			print(li[:f] + li[r:])


import sys
input = sys.stdin.readline
for T in range(int(input())):
	n = int(input())
	s = input().strip()
	z = -1
	o = n
	for i in range(n):
		if s[i] == '1':
			o = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			z = i
			break
	if z < o:
		print(s)
	else:
		res = s[:o] + s[z:]
		print(res)


import math

def main():
	n = int(input())
	line = input()
	zero = 0
	one = 0
	i = 0
	while i < n and line[i] == '0':
		zero += 1
		i += 1
	i = n - 1
	while i > -1 and line[i] == '1':
		one += 1
		i -= 1
	zr = False
	on = False
	for i in range(n):
		if line[i] == '0':
			zr = True
	for i in range(n - 1, -1, -1):
		if line[i] == '0':
			on = True
		if line[i] == '1' and on:
			zero += 1
			break
	if zero == 0 and one == 0:
		if zr:
			print(0)
		else:
			print(1)
	else:
		line = ''
		for k in range(zero):
			line += '0'
		for k in range(one):
			line += '1'
		print(line)
t = int(input())
for i in range(t):
	main()


from sys import stdin

def readline():
	return stdin.readline()
tests = int(readline())

def solve(n, s):
	i0 = -1
	i1 = -1
	for i in range(0, n):
		if s[i] == '1' and i1 < 0:
			i1 = i
		if s[n - i - 1] == '0' and i0 < 0:
			i0 = n - i - 1
		if i1 >= 0 and i0 >= 0:
			break
	if i0 == -1 or i1 == -1 or i0 < i1:
		return s
	return s[0:i1] + '0' + s[i0 + 1:n]
for t in range(0, tests):
	n = int(readline().rstrip('\n'))
	s = readline().rstrip('\n')
	print(solve(n, s))


for _ in range(int(input())):
	n = int(input())
	s = input()
	block = 0
	i = 0
	ans = ''
	if s.count('1') == 0 or s.count('0') == 0:
		ans = s
	else:
		i = 0
		pre = ''
		while s[i] == '0':
			pre += s[i]
			i += 1
		stop = i
		i = n - 1
		last = ''
		while s[i] == '1':
			last += s[i]
			i -= 1
		if i != stop - 1:
			ans = pre + '0' + last
		else:
			ans = pre + last
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	stk = []
	left = 0
	right = 0
	flag = 0
	while right < len(s):
		if s[right] == '1' and flag == 0:
			flag = 1
			right += 1
		elif s[right] == '1' and flag == 1:
			right += 1
		elif s[right] == '0' and flag == 1:
			flag = 2
			right += 1
		elif s[right] == '0' and flag == 2:
			right += 1
		elif s[right] == '1' and flag == 2:
			s[left:right] = '0'
			right = left + 1
			flag = 1
		elif s[right] == '0' and flag == 0:
			right += 1
			left += 1
	if flag == 2:
		s[left:right] = '0'
	print(''.join(s))


import sys
input = sys.stdin.readline
T = int(input())
for testcase in range(T):
	n = int(input())
	s = list(input())
	ans = []
	if s[0] == '0':
		ch = 0
		for i in range(1, n):
			if s[i] != s[i - 1]:
				ch += 1
		if ch == 0:
			ans = ['0'] * n
		elif ch == 1:
			for i in range(n):
				ans.append(s[i])
		elif ch % 2 == 0:
			for i in range(n):
				if s[i] == '1':
					break
				ans.append('0')
			ans.append('0')
		else:
			for i in range(n):
				if s[i] == '1':
					break
				ans.append('0')
			ans.append('0')
			for i in range(n - 1, -1, -1):
				if s[i] == '0':
					break
				ans.append('1')
	else:
		ch = 0
		for i in range(1, n):
			if s[i] != s[i - 1]:
				ch += 1
		if ch == 0:
			ans = ['1'] * n
		elif ch % 2 == 1:
			ans.append('0')
		else:
			ans.append('0')
			for i in range(n - 1, -1, -1):
				if s[i] == '0':
					break
				ans.append('1')
	print(''.join(ans))


for _ in range(int(input())):
	n = int(input())
	a = input()
	(z, o) = (0, 0)
	for i in range(n):
		if a[i] == '0':
			z += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if a[i] == '1':
			o += 1
		else:
			break
	if z + o == n:
		print(a)
	else:
		print('0' * (z + 1) + '1' * o)


for _ in range(int(input())):
	ans = ''
	n = int(input())
	arr = [int(c) for c in input()]
	a = 0
	b = 0
	for i in arr:
		if i == 0:
			a += 1
		else:
			break
	for j in arr[::-1]:
		if j == 1:
			b += 1
		else:
			break
	if a + b != n:
		c = 1
	else:
		c = 0
	print('0' * (a + c) + '1' * b)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input()
		ind_one = []
		ind_two = []
		ind = 0
		for i in s:
			if i == '1':
				ind_one.append(ind)
				ind += 1
			else:
				ind_two.append(ind)
				ind += 1
		if len(ind_one) > 0 and len(ind_two) > 0:
			x1 = min(ind_one)
			xo = max(ind_two)
			if x1 > xo:
				ans = '0' * x1 + '1' * (len(s) - (xo + 1))
				print(ans)
			else:
				ans = '0' * (x1 + 1) + '1' * (len(s) - (xo + 1))
				print(ans)
		else:
			print(s)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if s == '1' * n:
		print(s)
		continue
	if s == '0' * n:
		print(s)
		continue
	l = s.index('1')
	r = s.rindex('0')
	if r <= l:
		print(s)
		continue
	print('0' * l + '0' + '1' * (n - r - 1))


def cont(s):
	zc = 0
	oc = 0
	i = 0
	while i < len(s) and s[i] == '0':
		zc += 1
		i += 1
	j = len(s) - 1
	while j >= i and s[j] == '1':
		oc += 1
		j -= 1
	if oc == 0 and zc == 0:
		return '0'
	elif oc + zc == len(s):
		return s
	else:
		res = '0' * zc + '0' + '1' * oc
		return res
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	print(cont(s))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	(l, r, b) = (1, 1, False)
	for j in range(n - 1):
		if s[j] > s[j + 1]:
			b = True
			break
	if not b:
		print(s)
		continue
	if '1' in s:
		l = s.find('1')
	if '0' in s:
		r = s.rfind('0')
	s = s[:l] + '0' + s[r + 1:]
	print(s)


from collections import defaultdict, Counter
import math
from functools import reduce, lru_cache
from heapq import heapify, heappush, heappop
import sys
from sys import stdin, stdout
from random import seed
from random import randint
mod = 10 ** 9 + 7

def mul_mod(a, b):
	return a % mod * (b % mod) % mod

def add_mod(a, b):
	return (a % mod + b % mod) % mod

def sub_mod(a, b):
	return (a % mod - b % mod + mod) % mod

def modInverse(b):
	return pow(b, mod - 2, mod)

def div_mod(a, b):
	a = a % mod
	inv = modInverse(b)
	return inv * a % mod

class Graph:

	def __init__(self, vertices):
		self.V = vertices + 1
		self.graph = defaultdict(set)
		self.Time = 0
		self.P = 0
		self.Q = 0

	def addEdge(self, u, v):
		self.graph[u].add(v)
		self.graph[v].add(u)
for _ in range(int(input())):
	n = int(input())
	string = input()
	i = 0
	ans = ''
	while i < len(string) and string[i] == '0':
		i += 1
		ans += '0'
	j = len(string) - 1
	temp = ''
	while j >= 0 and string[j] == '1':
		j -= 1
		temp += '1'
	if i < j:
		ans += '0'
	ans += temp
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = list(s)
	rev = s[::-1]
	(c, d) = (0, 0)
	for i in s:
		if i == '0':
			c += 1
		else:
			break
	for i in rev:
		if i == '1':
			d += 1
		else:
			break
	if c + d == n:
		print(s)
	else:
		ans = '0' * c + '0' + '1' * d
		print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	L = 0
	R = 0
	for j in range(n):
		if s[j] == '1':
			break
		L += 1
	for j in range(1, n + 1):
		if s[-j] == '0':
			break
		R += 1
	if L + R == n:
		print(s)
	else:
		print('0' * L + '0' + '1' * R)


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = list(s)
	q = ''
	t = ''
	for i in range(n - 1, -1, -1):
		if l[i] == '1':
			q = q + '1'
		else:
			break
	for j in range(n):
		if l[j] == '0':
			t = t + '0'
		else:
			break
	if '10' in s:
		print(t + '0' + q)
	else:
		print(t + q)


from sys import stdin
for _ in range(int(input())):
	n = int(stdin.readline())
	s = input()
	if s.count('10') == 0:
		print(s)
	else:
		ans = ''
		if s[0] == '0':
			for e in s:
				if e == '1':
					break
				ans += e
		ans += '0'
		if s[-1] == '1':
			for e in s[::-1]:
				if e == '0':
					break
				ans += e
		print(ans)


t = int(input())
while t:
	n = int(input())
	s = input()
	l = []
	m = -1
	i = n - 1
	while i >= 0:
		if m != -1 and s[i] == '1' and (l[m] == '0'):
			while m > 0 and l[m - 1] == '0':
				l.pop()
				m -= 1
			while i >= 0 and s[i] == '1':
				i -= 1
		else:
			l.append(s[i])
			m += 1
			i -= 1
	l.reverse()
	print(''.join(l))
	t -= 1


def solve():
	l = int(input())
	string = list(input())
	s2 = []
	first1 = -1
	for i in range(l):
		if string[i] == '0':
			s2.append('0')
		else:
			first1 = i
			break
	if first1 == -1:
		return ''.join(string)
	last0 = -1
	for i in range(first1, l):
		if string[i] == '0':
			last0 = i
	if last0 != -1:
		s2.append('0')
		for i in range(1 + last0, l):
			s2.append('1')
	else:
		for i in range(first1, l):
			s2.append('1')
	return ''.join(s2)
for _ in range(int(input())):
	print(solve())


import sys

def solve(test):
	n = int(input())
	s = list(input())
	isSolExist = False
	for i in range(0, n - 1, 1):
		if s[i] == '1' and s[i + 1] == '0':
			isSolExist = True
			break
	if not isSolExist:
		print(''.join(s))
	else:
		while True:
			index = -1
			for i in range(len(s) - 2, -1, -1):
				if s[i] == '1' and s[i + 1] == '0':
					index = i
					break
			if index == -1:
				print(''.join(s))
				break
			else:
				ones = 0
				for i in range(index - 1, -1, -1):
					if s[i] == '1':
						ones += 1
					else:
						break
				zeros = 0
				for i in range(index + 2, len(s)):
					if s[i] == '0':
						zeros += 1
					else:
						break
				if ones == 0 and zeros == 0:
					s.pop(index)
				elif ones == zeros or zeros > ones:
					s.pop(index + 1)
				else:
					s.pop(index)

def main():
	test_case = int(input())
	for test in range(test_case):
		solve(test + 1)
main()


def contains(l, bool):
	for i in range(len(l) - 1):
		if l[i] == '1' and l[i + 1] == '0':
			bool = True
			break
	return bool

def func(self, l):
	if not func(l):
		return l
	for i in range(len(l) - 2):
		if l[i] == '1' and l[i + 1] == '0':
			if l[i + 2] == '1':
				l.pop(i)
			elif l[i + 2] == '0':
				l.pop(i + 1)
			break
	return self.func(l)
for _ in range(int(input())):
	n = int(input())
	s = input()
	l = list(s)
	a = 0
	while contains(l, False):
		for i in range(len(l) - 2, -1, -1):
			if l[i] == '1' and l[i + 1] == '0':
				if i + 2 != len(l):
					if l[i + 2] == '1':
						l.pop(i)
					elif l[i + 2] == '0':
						l.pop(i + 1)
				else:
					l.pop(i)
				break
	s = ''
	s = s.join(l)
	print(s)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	n = int(input())
	s = input().split()[0]
	cou = 1
	res = [int(s[0])]
	arr = []
	for i in range(1, n):
		if s[i] == s[i - 1]:
			cou += 1
		else:
			arr.append(cou)
			cou = 1
			res.append(int(s[i]))
	if cou != 0:
		arr.append(cou)
	for i in range(len(arr) - 1):
		if res[i] == 1 and res[i + 1] == 0:
			ind = i
	for i in range(len(arr) - 1):
		if res[i] == 1 and res[i + 1] == 0:
			if i == ind:
				arr[i + 1] = 1
				arr[i] = 0
			else:
				arr[i + 1] = 0
				arr[i] = 0
	ss = ''
	for i in range(len(arr)):
		ss += str(res[i]) * arr[i]
	print(ss)
	t -= 1


n = int(input())
for _ in range(n):
	l = int(input())
	a = list(input())
	if '10' not in ''.join(a):
		print(''.join(a))
	else:
		x = 0
		y = len(a)
		for i in range(len(a)):
			if a[i] == '1':
				x = i
				break
		for i in range(len(a) - 1, -1, -1):
			if a[i] == '0':
				y = i
				break
		M = []
		M.extend(a[:x])
		M.append('0')
		M.extend(a[y + 1:])
		print(''.join(M))


t = int(input())
answer = []
for i in range(t):
	n = int(input())
	a = input().strip()
	j = n - 1
	ans = ''
	f = 0
	x = 0
	while j >= 0:
		if a[j] == '1':
			j = j - 1
		else:
			x = j
			j = j - 1
			f = 1
			break
	if f == 1:
		while j >= 0:
			if a[j] == '1':
				f = 0
				break
			else:
				j = j - 1
		if f == 0:
			k = 0
			while k < n:
				if a[k] == '0':
					ans = ans + a[k]
					k = k + 1
				else:
					break
			ans = ans + a[x:]
			answer.append(ans)
		else:
			answer.append(a)
	else:
		answer.append(a)
for i in range(t):
	print(answer[i])


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	zeros = 0
	for x in s:
		if x == '0':
			zeros += 1
	last = '0'
	s2 = ''
	for (i, x) in enumerate(s):
		if x == '1':
			s2 += x
			last = '1'
		else:
			if zeros <= 1 or last == '0':
				s2 += x
				last = '0'
			zeros -= 1
	s3 = s2[-1]
	for i in range(len(s2) - 2, -1, -1):
		if s2[i] == '0':
			s3 += s2[i]
		elif s3[-1] == '1':
			s3 += s2[i]
	print(s3[::-1])


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	i = n - 1
	j = n - 1
	count = 0
	res = ''
	while s[i] == '1' and i >= 0:
		res += s[i]
		i -= 1
	while i >= 0:
		if count == 1:
			if s[i] == '0':
				count += 1
				i -= 1
			else:
				i -= 1
		elif s[i] == '0':
			count += 1
			i -= 1
		else:
			count = 1
			i -= 1
	temp = ''
	for x in range(count):
		temp += '0'
	print(temp + res)


def solve(s):
	if all([c == s[0] for c in s]):
		return s
	(prefix_zeros, suffix_ones) = (0, 1)
	while s[prefix_zeros] == '0':
		prefix_zeros += 1
	while s[-suffix_ones] == '1':
		suffix_ones += 1
	s = s[prefix_zeros:len(s) - suffix_ones + 1]
	return '0' * prefix_zeros + ('0' if len(s) > 0 else '') + '1' * (suffix_ones - 1)
for t in range(int(input())):
	n = int(input())
	s = input()
	print(solve(s))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().rstrip()
	if s.count('10') == 0:
		print(s)
		continue
	i = 0
	ans = ''
	while i < n:
		if s[i] == '1':
			ans += s[:i]
			break
		i += 1
	i = n - 1
	ans += '0'
	while i > 0:
		if s[i] == '0':
			ans += s[i + 1:]
			break
		i -= 1
	print(ans)


from sys import stdin, stdout
from fractions import Fraction
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = input()
	z = o = -1
	for i in range(n):
		if s[i] == '0':
			z = i
		elif s[i] == '1' and o == -1:
			o = i
	if z == -1 or o == -1 or z < o:
		print(s)
	else:
		ans = s[:o] + '0' + s[z + 1:]
		print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	k = s[::-1]
	l = list(s)
	x = ''
	y = ''
	for i in range(0, n):
		if k[i] == '1':
			x = x + k[i]
			if len(s) > 1 and len(x) != len(k):
				if k[i + 1] == '0':
					break
		else:
			break
	for i in range(0, n):
		if s[i] == '0':
			y = y + s[i]
			if len(s) > 1 and len(y) != len(s):
				if s[i + 1] == '1':
					break
		else:
			break
	if len(x) == 0 and len(y) == 0:
		print(0)
	elif len(x) == 0 and len(y) != 0:
		if len(x) + len(y) == len(s):
			print(y)
		else:
			print(y + '0')
	elif len(x) != 0 and len(y) == 0:
		if len(x) + len(y) == len(s):
			print(x)
		else:
			print('0' + x)
	elif len(x) + len(y) == len(s):
		print(y + x)
	else:
		print(y + '0' + x)


for _ in range(int(input())):
	x = int(input())
	s = input()
	n = 1
	p = s[0]
	a = []
	for i in range(1, len(s)):
		if s[i] == p:
			n += 1
		else:
			a.append(n)
			p = s[i]
			n = 1
	a.append(n)
	ans = ''
	if s[0] == '0':
		ans += a.pop(0) * '0'
	if len(a) == 0:
		pass
	elif len(a) == 1:
		ans += a[0] * s[-1]
	else:
		ans += '0'
		if len(a) % 2 == 1:
			ans += a.pop(len(a) - 1) * '1'
	print(ans)


import sys
for _ in range(int(input())):
	sys.stdin.readline()
	s = sys.stdin.readline()
	s = list(s[:-1])
	for (i, x) in enumerate(s):
		s[i] = int(x)
	zero = 0
	for (_, x) in enumerate(s):
		if x == 1:
			break
		zero += 1
	one = 0
	for j in range(len(s) - 1, -1, -1):
		if s[j] == 1:
			s.pop()
			one += 1
		else:
			break
	s = s[zero:]
	if len(s) > 0:
		mid = 1
	else:
		mid = 0
	zero += mid
	print('0' * zero + '1' * one)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

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

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

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		n = N()
		s = input()
		res = ''
		b = False
		e = False
		for i in range(n):
			if s[i] == '0':
				res += '0'
			else:
				b = True
				break
		res1 = ''
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				res1 += '1'
			else:
				e = True
				break
		if len(res) + len(res1) == n:
			print(s)
		elif e:
			print(res + '0' + res1[::-1])
		else:
			print(res + res1[::-1])
main()


rw = int(input())
for ewqr in range(rw):
	n = int(input())
	s = input()
	t0 = False
	t1 = False
	p0 = 0
	p1 = 0
	c = ''
	b = '0'
	a = ''
	min1 = -1
	sc0 = s.count('0')
	sc1 = s.count('1')
	for i in range(n):
		if s[i] == '0':
			a += '0'
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			c += '1'
		else:
			break
	if a + c == s:
		print(s)
	else:
		print(a + b + c)


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	z = 0
	o = 0
	az = ''
	ao = ''
	for i in s:
		if i == '0':
			z += 1
			az += i
		else:
			break
	for i in s[::-1]:
		if i == '1':
			z += 1
			ao += i
		else:
			break
	if o + z == n:
		print(s)
	else:
		print(az + '0' + ao)
	t -= 1


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
from collections import Counter
for i in range(int(input())):
	n = int(input())
	s = input()
	ans = ''
	f = 0
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			f = 1
			break
	if f == 0:
		print(s)
	else:
		for i in range(len(s)):
			if s[i] == '1':
				left = i
				break
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '0':
				right = i
				break
		print(s[:left] + '0' + s[right + 1:])


t = int(input())
for T in range(t):
	n = int(input())
	s = input()
	ele = s[0]
	val = []
	count = 0
	for i in range(n):
		if s[i] == ele:
			count += 1
		else:
			ele = s[i]
			val.append(count)
			count = 1
	val.append(count)
	ind = 1
	if s[-1] == '1':
		ind = 2
	(v1, v2) = (s[0], str(abs(int(s[0]) - 1)))
	for i in range(len(val) - ind, 0, -2):
		val[i] = 1
		val[i - 1] = 0
	for i in range(len(val) - ind, 2, -2):
		if val[i - 2] > 0:
			val[i] = 0
	ans = ''
	for i in range(len(val)):
		if i % 2 == 0:
			ans += v1 * val[i]
		else:
			ans += v2 * val[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	j = n - 1
	while i < n and s[i] == '0':
		i += 1
	while j > -1 and s[j] == '1':
		j -= 1
	if i - j == 1:
		print(s)
		continue
	print(s[:i] + '0' + s[j + 1:])


def function(a):
	if all([c == a[0] for c in a]):
		return a
	(hangingzero, leadingone) = (0, 0)
	while a[hangingzero] == '0':
		hangingzero += 1
	while a[len(a) - leadingone - 1] == '1':
		leadingone += 1
	a = a[hangingzero:len(a) - leadingone]
	return '0' * hangingzero + ('0' if len(a) > 0 else '') + '1' * leadingone
for i in range(int(input())):
	b = int(input())
	a = input()
	print(function(a))


T = int(input().rstrip())
for tt in range(T):
	N = int(input().rstrip())
	st = input().rstrip()
	lst = []
	flg = st[0]
	cnt = 1
	for ind in range(1, len(st)):
		if st[ind] == flg:
			cnt += 1
		else:
			lst.append([flg, cnt])
			flg = st[ind]
			cnt = 1
	lst.append([flg, cnt])
	ind = len(lst) - 2
	while ind >= 0:
		if ind + 1 < len(lst) and lst[ind][0] == '1' and (lst[ind + 1][0] == '0'):
			if ind - 1 < 0:
				lst[ind + 1][1] = 1
				lst.pop(ind)
			elif lst[ind - 1][0] == '0':
				lst[ind - 1][1] += 1
				lst.pop(ind + 1)
				lst.pop(ind)
				ind -= 1
			else:
				lst[ind + 1][1] = 1
				lst.pop(ind)
		ind -= 1
	out = ''
	for (i, cnt) in lst:
		out += i * cnt
	print(out)


import math

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

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

def bs(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return arr[mid]
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def swap(list, pos1, pos2):
	(list[pos1], list[pos2]) = (list[pos2], list[pos1])
	return list
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	x = ''
	for i in range(n):
		if s[i] == '0':
			x += '0'
		else:
			break
	z = ''
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			z += '1'
		else:
			break
	if len(x) + len(z) == n:
		print(x + z)
	else:
		print(x + '0' + z)


import re
for _ in range(int(input())):
	n = int(input())
	s = input()
	while '10' in s:
		s = re.sub('(1+0+)+', '0', s)
	print(s)


t = int(input())
for i in range(t):
	n = int(input())
	sta = 0
	en = 0
	count = 0
	nums = 0
	ar = [int(i) for i in input()]
	for l in range(n):
		if ar[l] == 1:
			sta = l
			count += 1
			break
		else:
			pass
	for l in range(n):
		if ar[-(l + 1)] == 0:
			en = n - (l + 1)
			nums += 1
			break
		else:
			pass
	if count == 1 and nums == 1 and (sta < en):
		b = ar[:sta]
		c = ar[en:]
		print(''.join((str(i) for i in b)) + ''.join((str(i) for i in c)))
	else:
		print(''.join((str(i) for i in ar)))


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		n = int(input())
		s = input().strip()
		start = s[0]
		switches = 1
		for i in range(n - 1):
			if s[i] != s[i + 1]:
				switches += 1
		if switches == 1:
			sys.stdout.write(s + '\n')
		elif switches == 2 and start == '0':
			sys.stdout.write(s + '\n')
		elif start == '1':
			if switches % 2 == 0:
				sys.stdout.write('0\n')
			else:
				for i in range(1, n):
					if s[-i] == '0':
						break
				sys.stdout.write('0' + '1' * (i - 1) + '\n')
		elif switches % 2 == 0:
			for i in range(1, n + 1):
				if s[-i] == '0':
					break
			for j in range(n):
				if s[j] == '1':
					break
			sys.stdout.write('0' * j + '0' + '1' * (i - 1) + '\n')
		else:
			for j in range(n):
				if s[j] == '1':
					break
			sys.stdout.write('0' * (j + 1) + '\n')
prog()


for _ in range(int(input())):
	n = int(input())
	ls = [int(a) for a in input()]
	ls1 = []
	(zers, ons) = (0, 0)
	for i in range(n - 1, -1, -1):
		if ls[i] == 0:
			zers += 1
			for j in range(ons):
				ls1.append(1)
			ons = 0
		else:
			ons += 1
			if zers:
				zers = 1
				ons = 0
	for i in range(ons):
		ls1.append(1)
	for i in range(zers):
		ls1.append(0)
	ls1.reverse()
	print(''.join((str(ls1[i]) for i in range(len(ls1)))))


test_cases = int(input())
clean_strings = []
for test_case in range(test_cases):
	n = int(input())
	s = input()
	if '0' not in s or '0' not in s:
		clean_strings.append(s)
		continue
	i_1 = s.find('1')
	for item in range(len(s) - 1, 0 - 1, -1):
		if s[item] == '0':
			i_0 = item
			break
	if i_0 < i_1:
		clean_strings.append(s)
		continue
	first_part = s[:i_1]
	last_part = s[i_0:]
	clean_string = first_part + last_part
	clean_strings.append(clean_string)
for clean_string in clean_strings:
	print(clean_string)


for h in range(int(input())):
	n = int(input())
	s = list(map(int, input()))
	o = -1
	z = -1
	flag1 = 0
	flag2 = 0
	for i in range(n):
		if s[i] == 1 and flag1 == 0:
			o = i
			flag1 = 1
		if s[n - i - 1] == 0 and flag2 == 0:
			z = n - i - 1
			flag2 = 1
		if flag1 == 1 and flag2 == 1:
			break
	if o < 0 or z < 0:
		ans = s
	elif o > z:
		ans = s
	else:
		d = z - o
		for i in range(d):
			s.pop(o)
		ans = s
	for i in range(len(ans)):
		print(ans[i], end='')
	print()


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	S = input().strip()
	pre = ''
	for s in S:
		if s == '0':
			pre += s
		else:
			break
	suf = ''
	for s in S[::-1]:
		if s == '1':
			suf += s
		else:
			break
	if len(pre) + len(suf) == n:
		print(pre + suf)
	else:
		print(pre + '0' + suf)
for _ in range(int(input())):
	main()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ans = ''
	i1 = s.find('1')
	i0 = n - s[::-1].find('0') - 1
	if '0' not in s or '1' not in s:
		print(s)
		continue
	if i0 == -1 or i1 == -1:
		print(s)
		continue
	if i0 < i1:
		print(s)
		continue
	else:
		for j in range(i1):
			ans += s[j]
		ans += '0'
		for j in range(i0 + 1, n):
			ans += s[j]
		print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if '10' not in s:
		print(s)
		continue
	else:
		rev = s[::-1]
		x = 1
		y = 0
		zer = s.index('0')
		one = rev.index('1')
		if s[0] == '0':
			for i in range(zer, n):
				if s[i] == '1':
					break
				else:
					x += 1
		if rev[0] == '1':
			for i in range(one, n):
				if rev[i] == '0':
					break
				else:
					y += 1
	if x >= 1 and y >= 1:
		print('0' * x + '1' * y)
	elif x == 1 and y >= 1:
		print('0' + '1' * y)
	else:
		print('0' * x)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

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

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

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

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	n = int(input())
	s = list(input())
	i = n - 1
	ans = ''
	while i >= 0 and s[i] == '1':
		ans = s[i] + ans
		i -= 1
	indx = i
	if indx >= 0:
		ans = s[i] + ans
	else:
		print(ans)
		return
	while i >= 0:
		if s[i] == '1':
			indx = i
		i -= 1
	for j in range(indx):
		ans = s[j] + ans
	print(ans)
t = int(input())
for _ in range(t):
	solve()


from sys import stdin
input = stdin.readline
for t in range(int(input())):
	n = int(input())
	s = input().strip()
	if len(s) == 1:
		print(s)
		continue
	i = len(s) - 2
	while i >= 0:
		if s[i] == '1' and s[i + 1] == '0':
			if i + 2 < len(s) and s[i + 2] == '0':
				s = s[:i + 1] + s[i + 2:]
			else:
				s = s[:i] + s[i + 1:]
		else:
			i -= 1
	print(s)


def lee(s):
	if '0' not in s or '1' not in s:
		print(s)
	else:
		l = len(s)
		lz = l - s[::-1].index('0') - 1
		fo = s.index('1')
		if lz < fo:
			print(s)
		else:
			print(s[:fo] + s[lz:])
t = int(input())
l = []
for i in range(t):
	n = int(input())
	s = input()
	l.append(s)
for j in l:
	lee(j)


import collections
t = int(input())
for _i in range(t):
	n = int(input())
	s = input()
	(i, j) = (0, 0)
	for c in s:
		if c == '0':
			i += 1
		else:
			break
	for c in reversed(s):
		if c == '1':
			j += 1
		else:
			break
	if i + j == len(s):
		print(s)
	else:
		print('0' * (i + 1) + '1' * j)


import sys
ip = lambda : sys.stdin.readline().rstrip()
for _ in range(int(ip())):
	n = int(ip())
	s = ip()
	i = 0
	ans = []
	pre = False
	while i < n:
		if s[i] == '1':
			j = i
			t = ''
			while j < n and s[j] == '1':
				t += s[j]
				j += 1
			if pre:
				if j != n:
					ans.pop()
				pre = False
			if j < n and s[j] == '0':
				ans.append('0')
				pre = True
			else:
				ans += t
			i = j
		else:
			if not pre:
				ans.append(s[i])
			i += 1
	print(*ans, sep='')


import math
import sys
input = sys.stdin.readline
result = []
t = int(input())
for i in range(t):
	n = int(input())
	s = input().strip()
	(c, d, x, y) = (-1, -1, 0, 0)
	for i in range(n):
		if s[i] == '1' and x == 0:
			(c, x) = (i, 1)
		if s[i] == '0':
			d = i
	result.append(s[:c] + s[d:]) if d >= 0 and c >= 0 and (c < d) else result.append(s)
print('\n'.join(result))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	b = []
	for j in s:
		b.append(j)
	p = -1
	q = -1
	for j in range(n):
		if b[j] == '1' and p == -1:
			p = j
		if b[j] == '0':
			q = j
		j += 1
	if p == -1 or q == -1:
		s = 0
	else:
		s = 0
		j = p
		while j <= q:
			if b[j] == '0':
				s = 1
				break
			j += 1
	if p == -1:
		p = n
	if q == -1:
		q = n
	else:
		q = n - 1 - q
	print(''.join(['0'] * p) + ''.join(['0'] * s) + ''.join(['1'] * q))


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	l = 0
	r = n - 1
	if len(set(a)) == 1:
		print(*a, sep='')
	else:
		for i in range(n):
			if a[i] == '1':
				l = i
				break
		for j in range(n - 1, -1, -1):
			if a[j] == '0':
				r = n - j - 1
				break
		if l + r == n:
			print('0' * l + '1' * r)
		else:
			print('0' * (l + 1) + '1' * r)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(input())
	for i in range(len(l)):
		l[i] = int(l[i])
	while 1:
		p = len(l) - 1
		flag = 0
		for i in range(p, 0, -1):
			if l[i - 1] == 1 and l[i] == 0:
				pos = i
				flag = 1
				break
		if flag == 0:
			for i in l:
				print(i, end='')
			print()
			break
		else:
			pos2 = -1
			for i in range(pos, p + 1):
				if l[i] != 0:
					pos2 = i - 1
					break
			if pos2 == -1:
				pos2 = p
			if pos2 - pos + 1 == 1:
				del l[pos - 1]
			else:
				del l[pos:pos2]
				del l[pos - 1]


for i in range(int(input())):
	n = int(input())
	s = input()
	one = 0
	zero = 0
	one = s.find('1')
	zero = s.rfind('0')
	if one > zero:
		print(s)
	else:
		c = s[0:one]
		d = s[zero:n]
		print(c + d)


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	(z, o) = (0, 0)
	for i in range(len(s)):
		if s[i] == '0':
			z += 1
		else:
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			o += 1
		else:
			break
	if z + o == n:
		print('0' * z + '1' * o)
	else:
		print('0' * z + '0' + '1' * o)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	k = ''
	i = 0
	while i < len(s) and s[i] == '0':
		k += '0'
		i += 1
	i = len(s) - 1
	y = ''
	while i >= 0 and s[i] == '1':
		y += '1'
		i -= 1
	if len(k) + len(y) < len(s):
		print(k + '0' + y)
	else:
		print(k + y)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if n == 1:
		print(s)
	else:
		s1 = ''
		for i in range(n):
			if s[i] == '0':
				s1 += s[i]
			else:
				break
		if '10' in s:
			s1 += '0'
		for j in range(n - 1, -1, -1):
			if s[j] == '1':
				s1 += s[j]
			else:
				break
		print(s1)


t = int(input())
for test in range(t):
	n = int(input())
	s = input()
	beg = 0
	front = ''
	while beg < len(s) and s[beg] == '0':
		front += '0'
		beg += 1
	end = len(s) - 1
	last = ''
	while end >= 0 and s[end] == '1':
		last += '1'
		end -= 1
	if beg < end:
		print(front + '0' + last)
	else:
		print(front + last)


for _ in range(int(input())):
	(x, y, n, a) = (0, 0, int(input()), input())
	for i in a:
		if i == '0':
			x += 1
		else:
			break
	for i in a[::-1]:
		if i == '1':
			y += 1
		else:
			break
	if x + y == n:
		print(a)
		continue
	if '0' in a:
		print('0' * (x + 1), end='')
	print('1' * y)


for _ in range(int(input())):
	n = int(input())
	l = []
	s = input()
	m = s.count('0')
	if m == n:
		print(s)
		continue
	if m == 0:
		print(s)
		continue
	s1 = ''
	y = -1
	for i in range(n):
		if s[i] == '0':
			y = i
			s1 = s1 + s[i]
		else:
			break
	c = -1
	for i in range(n):
		if s[i] == '0':
			c = i
	if c == -1:
		print(n)
	elif y == -1:
		print(s[c:])
	elif c == y:
		print(s1 + s[c + 1:])
	else:
		print(s1 + s[c:])


def strin(l):
	while '10' in l:
		ind = l.index('10')
		l = list(l)
		print(l, ind)
		if ind == 0:
			if ind + 2 < len(l):
				if l[ind + 2] == '0':
					l.pop(ind + 2)
				else:
					l.pop(ind)
			else:
				l.pop(ind)
		else:
			if ind + 2 < len(l):
				if l[ind + 2] == '0':
					l.pop(ind + 2)
			if ind - 1 >= 0:
				if l[ind - 1] == '1':
					l.pop(ind - 1)
				else:
					l.pop(ind)
			else:
				l.pop(ind)
		l = ''.join(l)
		print(l)
for _ in range(int(input())):
	n = int(input())
	s = input()
	l = list(s)
	if '10' in s:
		ans = '0'
		i = s.find('1')
		l.reverse()
		j = l.index('0')
		j = n - j - 1
		for k in range(i):
			ans = ans + '0'
		for k in range(j + 1, n):
			ans = ans + s[k]
		print(ans)
	else:
		print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	s1 = ''.join(sorted(s))
	if s == s1:
		print(s)
	else:
		ans = ''
		start = 0
		for i in range(n):
			if s[i] == '0':
				ans += s[i]
			else:
				start = i
				break
		end = start
		for i in range(start, n):
			if s[i] == '0':
				end = i
		if end != start:
			ans += '0'
		for i in range(end + 1, n):
			ans += s[i]
		print(ans)


n = input('')
n = int(n)
str = []
matrix = []
for i in range(n):
	entries = list(map(int, input().split()))
	matrix.append(entries)
	str.append(input(''))
for i in str:
	i = list(i)
	k = len(i) - 1
	while k >= 0:
		if k < len(i) and i[k] == '0' and (k - 1 >= 0) and (i[k - 1] == '1'):
			if k + 1 < len(i) and i[k + 1] == '0':
				del i[k]
			elif k - 2 >= 0 and i[k - 2] == '1':
				del i[k - 1]
			else:
				del i[k - 1]
		else:
			k = k - 1
		if len(i) == 1:
			break
	print(''.join(i))


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	s = input()
	not_in = False
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			not_in = True
			break
	if not not_in:
		ans.append(s)
		continue
	zero_c = 1
	one_c = 0
	for i in range(n):
		if s[i] == '0':
			zero_c += 1
		else:
			break
	for i in range(0, n + 1):
		if s[n - i - 1] == '1':
			one_c += 1
		else:
			break
	ans.append('0' * zero_c + '1' * one_c)
for i in range(t):
	print(ans[i])


t = int(input())
for x in range(t):
	n = int(input())
	s = input()
	l = 1
	r = 1
	flag = 0
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			flag = 1
			break
	if flag == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			l = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			r = i
			break
	ans = s[:l] + '0' + s[r + 1:]
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = input()
	out = ''
	late0 = 0
	e1 = n
	for i in range(n - 1, -1, -1):
		if a[i] == '0':
			late0 = i
			break
	for i in range(n):
		if a[i] == '1':
			e1 = i
			break
	if late0 == e1 - 1:
		print(a)
	else:
		print(a[:e1] + a[late0:])


t = int(input())
for q in range(t):
	n = int(input())
	s = input()
	i_0 = -1
	i_1 = -1
	for i in range(n):
		if s[i] == '0':
			i_0 = i
		elif i_1 == -1:
			i_1 = i
	i = 0
	if i_0 == -1 or i_1 == -1:
		print(s)
	else:
		while i < i_1:
			print('0', end='')
			i += 1
		if i_0 > i_1:
			print('0', end='')
		i = i_0 + 1
		while i < len(s):
			print('1', end='')
			i += 1
		print()


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = stdin.readline()
	st = []
	x = y = -1
	for i in range(n):
		if s[i] == '0':
			st.append('0')
		else:
			x = i
			break
	st1 = []
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			st1.append('1')
		else:
			y = i
			break
	if len(st) + len(st1) == n:
		print(''.join(st) + ''.join(st1))
	else:
		if y != -1:
			st.append('0')
		elif x != -1:
			st.append('1')
		print(''.join(st) + ''.join(st1))


for _ in range(int(input())):
	N = int(input())
	s = input()
	counts = []
	count = 1
	for i in range(1, len(s)):
		if s[i] != s[i - 1]:
			counts.append(count)
			count = 1
		else:
			count += 1
	counts.append(count)
	if len(s) == 1:
		print(s)
	elif s[0] == '0' and s[-1] == '1':
		if len(counts) == 2:
			print(s)
		else:
			print(counts[0] * '0', end='')
			print('0', end='')
			print(counts[-1] * '1')
	elif s[0] == '0' and s[-1] == '0':
		if len(counts) == 1:
			print(s)
		else:
			print(counts[0] * '0', end='')
			print('0')
	elif s[0] == '1' and s[-1] == '1':
		if len(counts) == 1:
			print(s)
		else:
			print('0', end='')
			print(counts[-1] * '1')
	elif s[0] == '1' and s[-1] == '0':
		print('0')


from collections import deque
import sys

def inp():
	return sys.stdin.readline().strip()
for _ in range(int(inp())):
	n = int(inp())
	s = inp()
	l = 0
	if n == 1:
		print(s)
		continue
	while l < len(s) and s[l] == '0':
		l += 1
	r = len(s) - 1
	ct = 0
	while r >= 0 and s[r] == '1':
		ct += 1
		r -= 1
	ans = ''
	if l == r + 1:
		print(s)
		continue
	else:
		ans = '0' * (l + 1)
		ans += '1' * ct
		print(ans)


def gen_primes():
	D = {}
	q = 2
	while True:
		if q not in D:
			yield q
			D[q * q] = [q]
		else:
			for p in D[q]:
				D.setdefault(p + q, []).append(p)
			del D[q]
		q += 1

def read_line(type=int):
	return list(map(type, input().split()))

def sum_from_1_to_(i):
	return i * (i + 1) // 2

def is_odd(a):
	return a % 2 == 0
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	start = 0
	i = 0
	while i < n and s[i] == '0':
		start += 1
		i += 1
	end = 0
	i = n - 1
	while i >= 0 and s[i] == '1':
		end += 1
		i -= 1
	print('0' * start + ('0' if n > start + end else '') + '1' * end)


for _ in range(int(input())):
	n = int(input())
	s = input()
	c0 = c1 = 0
	for i in s:
		if i == '1':
			break
		c0 += 1
	for i in s[::-1]:
		if i == '0':
			break
		c1 += 1
	if c0 + c1 == n:
		print(s)
		continue
	print('0' * c0 + '0' + '1' * c1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	i = s.find('1')
	if i == -1:
		print(s)
		continue
	r = s[:i]
	S = ['1']
	for c in s[i + 1:]:
		if c == '1':
			S.append(c)
		else:
			while len(S) >= 2 and S[-1] == '1':
				S.pop()
			if S[-1] != '0':
				S.append(c)
	i = max((i for (i, v) in enumerate(S) if v == '0'), default=-1)
	if i == -1:
		print(r + ''.join(S))
	else:
		print(r + ''.join(S[i:]))


t = int(input())
D = []
for i in range(0, t):
	n = int(input())
	s = [int(x) for x in str(input())]
	j = 0
	A = []
	while j <= n - 1 and s[j] == 0:
		A.append(0)
		j += 1
	c = s.count(0)
	if c > j:
		A.append(0)
	j = n - 1
	while j >= 0 and s[j] == 1:
		A.append(1)
		j = j - 1
	B = ''.join([str(x) for x in A])
	D.append(B)
for i in D:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if s.count(s[0]) == n:
		print(s)
		continue
	ind1 = 0
	ind2 = n - 1
	while s[ind1] == '0':
		ind1 += 1
	while s[ind2] == '1':
		ind2 -= 1
	if ind2 < ind1:
		print(s)
		continue
	print(s[:ind1] + '0' + s[ind2 + 1:n])


t = int(input())
for x in range(t):
	n = int(input())
	s = input()
	(i, ans, last) = (0, '', '')
	while i < len(s):
		if s[i] == '1':
			ans = ans + s[i]
			j = len(s) - 1
			while i < j:
				if s[j] == '0':
					ans = ans[:len(ans) - 1]
					last = '0' + last
					break
				else:
					last = s[j] + last
				j = j - 1
		else:
			ans = ans + s[i]
		if last != '':
			break
		i = i + 1
	print(ans + last)


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	i = 0
	while i < len(s):
		if s[i] == '1':
			break
		i += 1
	j = len(s) - 1
	while j >= 0:
		if s[j] == '0':
			break
		j -= 1
	if i < j:
		print(''.join(s[0:i]) + '0' + ''.join(s[j + 1:]))
	else:
		print(''.join(s))


for test in range(int(input())):
	n = int(input())
	s = input()
	count_groups = 1
	first_group = 1
	last_group = 1
	for i in range(1, n):
		if s[i] != s[i - 1]:
			count_groups += 1
		if i == first_group and s[i] == s[0]:
			first_group += 1
	i = n - 2
	while i > -1 and s[i] == s[i + 1]:
		last_group += 1
		i -= 1
	if count_groups % 2 == 0:
		if s[0] == '1':
			print(0)
		elif count_groups == 2:
			print(s)
		else:
			print('0' * (first_group + 1) + '1' * last_group)
	elif s[0] == '1':
		if count_groups != 1:
			print('0' + '1' * last_group)
		else:
			print(s)
	elif count_groups != 1:
		print('0' * (first_group + 1))
	else:
		print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	j = 0
	a = ''
	if s[0] == '0':
		j += 1
		while j < n and s[j] == '0':
			a += s[j]
			j += 1
		a += '0'
	b = ''
	b = s[j:]
	b = b[::-1]
	c = ''
	for i in range(0, len(b)):
		if b[i] == '0':
			c += '0'
			break
		else:
			c += '1'
	c = c[::-1]
	a += c
	print(a)


for _ in range(int(input())):
	n = int(input())
	str = input()
	(lef, rig, flag) = (1, 1, 0)
	for i in range(n - 1):
		if str[i] > str[i + 1]:
			flag = 1
			break
	if flag == 0:
		print(str)
		continue
	for i in range(n):
		if str[i] == '1':
			lef = i
			break
	for i in range(n - 1, 0, -1):
		if str[i] == '0':
			rig = i
			break
	print(str[:lef] + '0' + str[rig + 1:])


test = int(input())
for i in range(test):
	n = int(input())
	s = input()
	ind = 0
	temp = 0
	for i in range(n):
		if s[i] == '1':
			temp = i
			break
	for i in range(temp, n):
		if s[i] == '0':
			ind = i
	flag = 0
	for i in range(ind):
		if s[i] == '1':
			flag = 1
			break
	if flag == 1:
		ans = ''
		for i in range(temp):
			ans += '0'
		ans += '0'
		for i in range(n - ind - 1):
			ans += '1'
		print(ans)
	else:
		print(s)


from sys import stdin, stdout
from bisect import bisect, bisect_left, bisect_right

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

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

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

def gs():
	return stdin.readline()
t = gi()
for _ in range(t):
	n = gi()
	s = gs()
	count = 0
	for i in range(n):
		if s[i] == '0':
			count += 1
		else:
			break
	one = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			one += 1
		else:
			break
	ans = ''
	for i in range(count):
		ans = ans + '0'
	if count + one != n:
		ans += '0'
	for i in range(one):
		ans = ans + '1'
	print(ans)


def lee(l, s):
	if '0' not in s or '1' not in s:
		return s
	else:
		last_zero = l - s[::-1].index('0') - 1
		first_one = s.index('1')
		if last_zero < first_one:
			return s
		else:
			return s[:first_one] + s[last_zero:]
t = int(input())
array = []
for i in range(t):
	a = int(input())
	b = input()
	array.append([a, b])
for x in array:
	print(lee(*x))


coun = 1
for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	stack = []
	s2 = ''
	for i in range(n - 1, -1, -1):
		if not stack:
			stack.append(s[i])
		elif s[i] == '1':
			if stack[-1] == '0':
				s2 = ''
				continue
			else:
				stack.append(s[i])
				s2 = ''
		elif stack[-1] == '1':
			stack.append(s[i])
			s2 = ''
		else:
			s2 += s[i]
			continue
	print(s2, end='')
	for i in range(len(stack) - 1, -1, -1):
		print(stack[i], end='')
	print()


t = int(input())
for h in range(t):
	n = int(input())
	s = input()
	ans = list()
	fl = 0
	for i in range(n):
		if s[i] == '1':
			break
		else:
			ans.append(0)
	if '10' in s:
		ans.append(0)
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			break
		else:
			ans.append('1')
	for i in ans:
		print(i, end='')
	print()


for _ in range(int(input())):
	n = int(input())
	s = input()
	a = list(s)
	x = 0
	for i in range(n - 1, -1, -1):
		if a[i] == '0':
			x = i
			break
	c = a[x:]
	b = []
	for j in range(x):
		if a[j] == '0':
			b.append('0')
		else:
			break
	y = b + c
	print(''.join(y))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(input())
	zeroes = 0
	ones = 0
	for i in range(n):
		if arr[i] == '0':
			zeroes += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if arr[i] == '1':
			ones += 1
		else:
			break
	if zeroes + ones == n:
		for i in arr:
			print(i, end='')
		print()
	else:
		ans = ''
		for i in range(zeroes):
			ans += '0'
		ans += '0'
		for i in range(ones):
			ans += '1'
		print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ind_1 = s.find('1')
	ind_2 = s.rfind('0')
	if ind_1 > ind_2:
		print(s)
	else:
		print(s[:ind_1] + s[ind_2:])


import sys
import heapq
import random
import collections

def solve(k):
	console(k)
	if len(k) == 1:
		return k
	if len(k) == k.count('1') or len(k) == k.count('0'):
		return k
	ending_1 = 0
	for i in k[::-1]:
		if i == '1':
			ending_1 += 1
			continue
		else:
			break
	ending_0 = 0
	for i in k[::-1]:
		if i == '0':
			ending_0 += 1
			continue
		else:
			break
	starting_0 = 0
	for i in k:
		if i == '0':
			starting_0 += 1
			continue
		else:
			break
	if ending_1 == k.count('1'):
		return k
	if ending_0 > 0:
		return '0' * (starting_0 + 1)
	return '0' * (starting_0 + 1) + '1' * ending_1

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	_ = input()
	k = input()
	res = solve(k)
	print(res)


TC = int(input())
for tc in range(TC):
	N = int(input())
	S = input()
	result = []
	zeros = 0
	ones = 0
	removals = 0
	for s in S:
		if s == '0':
			zeros += 1
		else:
			break
	for s in reversed(S):
		if s == '1':
			ones += 1
		else:
			break
	if len(S) > ones + zeros:
		zeros += 1
	print(''.join(['0'] * zeros + ['1'] * ones))


tt = int(input())
for ttt in range(tt):
	n = int(input())
	s = input()
	a = []
	for i in range(n):
		a.append(int(s[i]))
	start = a[0]
	prev = a[0]
	chlst = [0]
	for i in range(1, n):
		if a[i] != prev:
			chlst.append(i)
			prev = a[i]
	end = a[chlst[-1]]

	def printk(a):
		for x in a:
			print(x, end='')
		print()

	def is_compressible(a):
		prev = a[0]
		for i in range(1, len(a)):
			if prev == 1 and a[i] == 0:
				return True
			prev = a[i]
		return False
	if len(chlst) == 1:
		printk(a)
	elif start and end:
		printk([0] + a[chlst[-1]:len(a)])
	elif start == 0 and end:
		if is_compressible(a):
			printk(a[0:chlst[1]] + [0] + a[chlst[-1]:len(a)])
		else:
			printk(a)
	elif start and end == 0:
		printk([0])
	elif is_compressible(a):
		printk(a[0:chlst[1]] + [0])
	else:
		print('NOT POSSIBLE')


from __future__ import division, print_function

def get_ints():
	return map(int, input().strip().split())

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

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		count_zero = count_one = 0
		for i in range(n):
			if s[i] == '0':
				count_zero += 1
			else:
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				count_one += 1
			else:
				break
		if count_one + count_zero == n:
			print(s)
		else:
			print('0' * count_zero + '0' + '1' * count_one)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

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

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

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

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

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

class IOWrapper(IOBase):

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


import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
tc = int(input())
for zzz in range(tc):
	arr = []
	useless = input()
	brr = input()
	s = []
	for ele in brr:
		s.append(int(ele))
	l = len(s)
	for i in range(l - 1, -1, -1):
		if len(arr) != 0:
			k = arr[-1]
			if k[0] == 0 and s[i] == 1:
				arr[-1] = (0, 1)
			elif k[0] == s[i]:
				arr[-1] = (k[0], k[1] + 1)
			else:
				arr.append((s[i], 1))
		else:
			arr.append((s[i], 1))
	ss = len(arr)
	for i in range(ss - 1, -1, -1):
		print(str(arr[i][0]) * arr[i][1], end='')
	print()


t = int(input())
for q in range(0, t):
	n = int(input())
	a = input()
	j = n
	k = 0
	for i in range(0, n):
		if a[i] == '1':
			j = i
			break
	for i in range(0, n):
		if a[i] == '0':
			k = i
	ans = []
	for i in range(0, n):
		if i >= j and i < k:
			abc = 2
		else:
			ans.append(a[i])
	print(*ans, sep='')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	zeroes = s.split('1', 1)[0]
	ones = s.rsplit('0', 1)[-1]
	c = '0' * (len(s) - len(zeroes + ones) > 0)
	res = zeroes + c + ones
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	s = list(s)
	i = n - 2
	j = n - 1
	while i >= 0:
		if s[i] == '1' and s[j] == '0':
			if j + 1 <= n - 1 and s[j + 1] == '0':
				s.pop(j)
				n = len(s)
			else:
				s.pop(i)
				j -= 1
				i -= 1
				n = len(s)
		else:
			j -= 1
			i -= 1
	print(''.join(s))


t = int(input())
for q in range(t):
	n = int(input())
	s = input()
	if s.find('10') != -1:
		ans = s[:s.find('1') + 1] + s[s.rfind('0'):]
		c = ans.find('10')
		ans = ans[:c] + ans[c + 1:]
	else:
		ans = s
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	str1 = input()
	ans = ''
	i = 0
	while i < len(str1):
		if str1[i] == '0':
			ans += '0'
		else:
			break
		i += 1
	temp = ''
	j = len(str1) - 1
	while j >= i:
		if str1[j] == '1':
			temp += '1'
		else:
			break
		j -= 1
	for k in range(i, j + 1):
		if str1[k] == '0':
			ans += '0'
			break
	ans += temp
	print(ans)
	t -= 1


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	s = input()
	ns = ''
	while s and s[0] == '0':
		ns += '0'
		s = s[1:]
	while s and s[-1] == '1':
		ns += '1'
		s = s[:-1]
	if s:
		ns = '0' + ns
	ans.append(ns)
for el in ans:
	print(el)


test = int(input())
while test != 0:
	n = int(input())
	s = list(input())
	b = s
	flag = 1
	last1 = 0
	last0 = 0
	while flag == 1:
		i = 0
		flag = 0
		while i < len(s) - 1:
			if s[i] == '1' and s[i + 1] == '0':
				flag = 1
				if i > 0 and s[i - 1] == '1':
					s.pop(i)
					i -= 1
					last1 = -1
				else:
					s.pop(i + 1)
					last1 = i + 1
			else:
				i += 1
	if last1 > 0:
		s[last1 - 1] = '0'
	print(*s, sep='')
	test -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	flag = 0
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '0':
			flag = 1
			break
	if flag == 0:
		print(s)
	else:
		ans = ''
		if s[0] == '1' and s[-1] == '0':
			ans = '0'
		elif s[0] == '0' and s[-1] == '0':
			for i in range(len(s)):
				if s[i] == '1':
					idx_1 = i
					break
			ans = s[0:idx_1] + '0'
		elif s[0] == '1' and s[-1] == '1':
			for i in range(len(s) - 1, -1, -1):
				if s[i] == '0':
					idx_0 = i
					break
			ans = s[idx_0:]
		else:
			for i in range(len(s)):
				if s[i] == '1':
					idx_1 = i
					break
			for i in range(len(s) - 1, -1, -1):
				if s[i] == '0':
					idx_0 = i
					break
			if idx_1 < idx_0:
				ans = s[:idx_1] + s[idx_0:]
			else:
				ans = s
		print(ans)


rr = lambda : input()
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))
INF = float('inf')

def solve(N, S):
	i = 0
	ans = []
	while i < len(S):
		if S[i] == '1':
			ones = 0
			zeroes = 0
			while i < len(S) and S[i] == '1':
				ones += 1
				i += 1
			while i < len(S) and S[i] == '0':
				zeroes += 1
				i += 1
			if ones > 0 and zeroes > 0:
				ans.append('*')
			else:
				ans.append('1' * ones)
		else:
			ans.append('0')
			i += 1
	temp = []
	last = None
	for v in ans:
		if v == '*':
			if last != '*':
				temp.append('0')
		else:
			temp.append(v)
		last = v
	return ''.join(temp)
t = rri()
for _ in range(t):
	N = rri()
	S = rr()
	print(solve(N, S))


import sys
t = int(sys.stdin.readline())
while t:
	n = int(sys.stdin.readline())
	s = sys.stdin.readline().strip()
	zeroFound = oneFound = False
	firstone = 0
	lastzero = 0
	for i in range(n):
		if s[i] == '1' and (not oneFound):
			oneFound = True
			firstone = i
		if s[i] == '0':
			zeroFound = True
			lastzero = i
	if oneFound and zeroFound:
		if firstone < lastzero:
			ans = s[:firstone] + s[lastzero:]
		else:
			ans = s
	else:
		ans = s
	print(ans)
	t -= 1


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(n, s):
	i = 0
	j = n - 1
	while i < n and s[i] == '0':
		i += 1
	while j > -1 and s[j] == '1':
		j -= 1
	if i <= j:
		print(s[:i] + '0' + s[j + 1:])
	else:
		print(s)
for _ in range(int(input())):
	n = int(input())
	s = str(input())[:-1]
	solve(n, s)


from math import *
from math import factorial as fact, comb as ncr
from bisect import bisect_left as bl
from bisect import bisect_right as br
from array import array
from collections import Counter as ctr
from collections import deque as dq
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')

def solve():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		if not len(set(list(s))) - 1:
			print(s)
			continue
		i1 = s.index('1')
		i2 = s[::-1].index('0')
		if i1 + i2 != n:
			print('0' * (i1 + 1) + '1' * i2)
		else:
			print(s)
solve()


for n in range(int(input())):
	a = int(input())
	st = input()
	n1 = st.find('1')
	if n1 == -1:
		n1 = a
	n2 = st.rfind('0')
	n3 = a if n2 == -1 else a - n2 - 1
	if n1 + n3 == a:
		print(st)
	else:
		print('0' * (n1 + 1) + '1' * n3)


outputs = []
for __ in range(int(input())):
	n = int(input())
	A = input()
	first_1 = -1
	last_0 = -1
	for (j, i) in enumerate(A):
		if i == '1':
			first_1 = j
			break
	for (j, i) in enumerate(A):
		if i == '0':
			last_0 = j
	if first_1 > last_0 or first_1 == -1 or last_0 == -1:
		outputs.append(A)
	else:
		outputs.append(A[0:first_1] + '0' + A[last_0 + 1:])
for o in outputs:
	print(o)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	S = input().strip()
	OPENING = -1
	for i in range(n):
		if S[i] == '1':
			OPENING = i
			break
	ENDING = n
	for i in range(n - 1, -1, -1):
		if S[i] == '0':
			ENDING = i
			break
	if OPENING == -1 or ENDING == n:
		print(S)
	elif OPENING > ENDING:
		print(S)
	else:
		print(''.join(map(str, [0] * (OPENING + 1) + [1] * (n - 1 - ENDING))))


for k in range(int(input())):
	n = int(input())
	s = input()
	out = ''
	for i in range(n):
		if s[i] == '1':
			break
		else:
			out = out + '0'
	for j in range(n - 1, -1, -1):
		if s[j] == '0':
			break
		else:
			out = out + '1'
	if s == out:
		print(out)
	else:
		print('0' + out)


def solution(string, slen):
	lista = [int(i) for i in string]
	if lista == sorted(lista):
		return string
	else:
		lead = 0
		trail = 0
		j = 0
		while string[j] == '0' and j < slen:
			lead += 1
			j += 1
		j = slen - 1
		while string[j] == '1' and j > 0:
			trail += 1
			j -= 1
		return (lead + 1) * '0' + trail * '1'
t = int(input())
for i in range(t):
	n = int(input())
	string = input()
	print(solution(string, n))


for _ in range(int(input())):
	n = int(input())
	b = input()
	if n == 1:
		sol = b
	else:
		i = 0
		if b[0] == '0':
			while i < n and b[i] == '0':
				i += 1
		j = 0
		if b[n - 1] == '1':
			while j < n and b[n - 1 - j] == '1':
				j += 1
		if n - i - j > 0:
			x = '0'
		else:
			x = ''
		sol = '0' * i + x + '1' * j
	print(sol)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	one_index = n
	zero_index = -1
	if n == 1:
		print(s)
		continue
	for i in range(len(s)):
		if s[i] == '1':
			one_index = i
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '0':
			zero_index = i
			break
	if zero_index < one_index:
		print(s[:one_index] + s[zero_index + 1:])
	else:
		print(s[:one_index] + '0' + s[zero_index + 1:])


from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	L = [False] * n
	for i in range(1, n):
		if s[i] == '0' and (s[i - 1] == '1' or L[i - 1]):
			L[i] = True
	ans = deque()
	f0 = False
	flag = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '1' and f0:
			if flag == 1:
				ans.appendleft('0')
				flag = -1
		elif s[i] == '1':
			ans.appendleft(s[i])
		elif s[i] == '0' and L[i]:
			f0 = True
			if flag == -1:
				continue
			flag = 1
		else:
			ans.appendleft(s[i])
			f0 = True
	print(''.join(ans))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	i = 0
	if s == n * '0' or s == n * '1':
		print(s)
	else:
		while s[i] != '1' and i <= n:
			i += 1
		j = 0
		while s[-j - 1] != '0' and j < n:
			j += 1
		if i == n - j:
			print(s)
		else:
			print(i * '0' + '0' + j * '1')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	new_s = ''
	i = 0
	while i < n:
		count_ones = 0
		if i == 0:
			count_nulls = 0
			while i < len(s) and s[i] == '0':
				count_nulls += 1
				new_s += '0'
				i += 1
		else:
			while i < len(s) and s[i] == '0':
				i += 1
		while i < len(s) and s[i] == '1':
			count_ones += 1
			i += 1
	if count_nulls + count_ones != len(s) and count_ones != len(s):
		new_s += '0'
	for i in range(count_ones):
		new_s += '1'
	print(new_s)


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	if s == sorted(s):
		print(''.join(s))
	elif s == sorted(s, reverse=True):
		print('0')
	else:
		ind = n - s[::-1].index('0')
		ind1 = s.index('1')
		print(''.join(s[0:ind1]) + ''.join(s[ind - 1:]))


def solve():
	n = int(input())
	s = input()
	a = 0
	b = 0
	for i in range(n):
		if s[i] == '1':
			break
		else:
			a += 1
	s = s[::-1]
	for i in range(n):
		if s[i] == '0':
			break
		else:
			b += 1
	t = ''
	t += a * '0'
	if a + b < n:
		t += '0'
	t += b * '1'
	print(t)
t = int(input())
for h in range(t):
	solve()


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	S = input().rstrip()
	Query.append((N, S))
for (N, S) in Query:
	i1 = N
	while i1 > 0 and S[i1 - 1] == '1':
		i1 -= 1
	i2 = -1
	while i2 + 1 < N - 1 and S[i2 + 1] == '0':
		i2 += 1
	if i2 + 1 == i1:
		tmp = ''
	else:
		tmp = '0'
	ans = '0' * (i2 + 1) + tmp + '1' * (N - i1)
	print(ans)


def pos(s):
	o = False
	for i in s:
		if i == '1':
			o = True
		if o and i == '0':
			return True
	return False

def rm(s, i, n):
	if i + 2 < n:
		if s[i + 2] == '0':
			s.pop(i + 1)
			return s
	s.pop(i)
	return s
for _t in range(int(input())):
	n = int(input())
	s = list(input())
	while pos(s):
		for i in range(len(s) - 1, -1, -1):
			if i - 1 >= 0:
				if s[i] == '0' and s[i - 1] == '1':
					s = rm(s, i - 1, len(s))
					break
	print(''.join(s))


for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	(a, b) = (-1, -1)
	while i < n:
		if s[i] == '1':
			a = i
			break
		i += 1
	i = n - 1
	while i >= 0:
		if s[i] == '0':
			b = i
			break
		i -= 1
	x = ''
	if a < b:
		x = s[0:a] + s[b:]
		print(x)
	elif a == -1 or b == -1:
		print(s)
	else:
		print(s)


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	res = ''
	try:
		f = s.index('1')
		res += '0' * f
		w = s[::-1]
		try:
			l = w.index('0')
			if n - l != f:
				res += '0'
			res += '1' * l
			print(res)
		except ValueError:
			print(s)
	except ValueError:
		print(s)
	t -= 1


import math

def solve():
	n = int(input())
	s = input()
	one_index = s.find('1')
	zero_index = s.rfind('0')
	if one_index == -1 or zero_index == -1:
		return s
	if one_index < zero_index:
		return '0' * one_index + '0' + '1' * (n - zero_index - 1)
	return s
t = int(input())
while t > 0:
	t -= 1
	print(solve())


[print(t[1] if '0' not in t[1] or '1' not in t[1] else t[1].index('1') * '0' + ('0' if '10' in t[1] else '') + list(reversed(t[1])).index('0') * '1') for t in [(input(), input()) for _ in range(int(input()))]]


t = int(input())
for u in range(t):
	n = int(input())
	s = str(input())
	(h1, h2, l) = ([], [], [])
	hak = dict()
	temp = 0
	for i in s:
		if i == '1':
			temp += 1
			h1.append(temp)
		else:
			temp = 0
			h1.append(temp)
	temp = 0
	for i in s[::-1]:
		if i == '0':
			temp += 1
			h2.append(temp)
		else:
			temp = 0
			h2.append(temp)
	i = 0
	while i < n - 1:
		if s[i] == '1' and s[i + 1] == '0':
			k1 = i - h1[i] + 1
			k2 = i + h2[n - i - 2]
			hak[k1] = k2
			i = k2
		i += 1
	i = 0
	while i < n:
		if i in hak:
			l.append('0')
			i = k2
		else:
			l.append(s[i])
		i += 1
	print(''.join(l))


import math

def solve():
	n = int(input())
	a = input()
	ans = ''
	i = len(a) - 1
	one = -1
	zero = -1
	for i in range(len(a)):
		if one == -1 and a[i] == '1':
			one = i
		if a[i] == '0':
			zero = i
	if one != -1 and zero != -1 and (one < zero):
		for i in range(one):
			ans += a[i]
		ans += '0'
		for i in range(zero + 1, len(a)):
			ans += a[i]
	if not ans:
		ans = a
	print(ans)
t = int(input())
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	i = n - 2
	o = 0
	z = 0
	i = n - 1
	notFound = True
	while i >= 0 and notFound:
		if s[i] == '0':
			notFound = False
		else:
			o += 1
			i -= 1
	i = 0
	notFound = True
	while i < n and notFound:
		if s[i] == '1':
			notFound = False
		else:
			z += 1
			i += 1
	if n == z + o:
		print('0' * z + '1' * o)
	else:
		print('0' * (z + 1) + '1' * o)


for _ in range(int(input())):
	n = int(input())
	s = input()
	a = -1
	b = -1
	if '1' in s:
		a = s.index('1')
	if '0' in s:
		b = n - s[::-1].index('0') - 1
	if a == -1 or b == -1:
		print(s)
	elif b < a:
		print(s)
	else:
		ans = s[:a] + s[b:]
		print(ans)


t = int(input())
for testcase in range(t):
	n = int(input())
	s = input()
	(lef, rig, sw) = (1, 1, 0)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			sw = 1
			break
	if sw == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			lef = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			rig = i
			break
	st = s[:lef] + '0' + s[rig + 1:]
	print(st)


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = []
	a = ''
	check = 0
	for i in range(n - 1, 0, -1):
		if s[i - 1:i + 1] == '10':
			check = 1
			break
	if check == 0:
		print(s)
	else:
		i -= 1
		j = i + 1
		while s[j] == '0':
			j += 1
			if j == n:
				break
		p = 0
		while s[p] == '0':
			p += 1
		if j == i:
			s = s[:p] + s[i + 1]
		else:
			s = s[:p] + s[i + 1] + s[j:]
		print(s)


for u in range(int(input())):
	n = int(input())
	s = input()
	r = ''
	x = 0
	(i, j) = (0, 0)
	for i in range(n):
		if s[i] == '0':
			x += 1
		else:
			break
	y = 0
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			y += 1
		else:
			break
	if x < s.count('0'):
		x = x + 1
	print('0' * x + '1' * y)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

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

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

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

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

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in range(base ** n):
		s = [tb // base ** bt % base for bt in range(n)]
		rt += [s]
	return rt

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

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=1):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.node_size = len(ls) + 1
				(self.edges, _) = GI(self.node_size, self.node_size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.node_size = int(input())
		else:
			self.node_size = inp_size
		(self.edges, _) = GI(self.node_size, self.node_size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.node_size = len(ls) + 1
		(self.edges, _) = GI(self.node_size, self.node_size - 1, ls, index=index)
		return

	def dfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.node_size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def bfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.node_size
		v[x] = root_v
		while q:
			c = q.popleft()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def parent(self, x):
		return self.dfs(0, func=lambda pr, prv, nx, dist: pr, root_v=-1)

	def topological_sort(self, x):
		tps = []
		q = deque([x])
		v = [None] * self.node_size
		v[x] = 0
		while q:
			c = q.popleft()
			tps.append(c)
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = 0
		return tps

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.node_size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.node_size
		self.ETout = [-1] * self.node_size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

	def __str__(self):
		return str(self.edges)

	def show(self):
		if all([all([d == 1 for (nd, d) in e]) for e in self.edges]):
			print([[nd for (nd, d) in e] for e in self.edges])
		else:
			print(self)

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def right_bound(self, pos, x):
		k = (self.size - pos).bit_length()
		for j in range(k)[::-1]:
			nx = pos + (1 << j)
			if nx < n and self.query(pos, nx + 1) <= x:
				pos += 1 << j
		return pos

	def left_bound(self, pos, x):
		k = pos.bit_length()
		for j in range(k)[::-1]:
			nx = pos - (1 << j)
			if 0 <= nx and self.query(nx, pos + 1) <= x:
				pos -= 1 << j
		return pos

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = 0
for _ in range(int(input())):
	ans = 0
	n = I()
	s = input()
	c = 0
	for i in range(n):
		if s[i] == '1':
			break
		c += 1
	z = c
	c = 0
	for i in range(n)[::-1]:
		if s[i] == '0':
			break
		c += 1
	u = c
	if u + z == n:
		ans = '0' * z + '1' * u
	else:
		ans = '0' * (z + 1) + '1' * u
	print(ans)


from itertools import groupby

def solve(s):
	g = [(k, len(list(grp))) for (k, grp) in groupby(s)]
	if len(g) == 1:
		return s
	if len(g) == 2:
		if g[0][0] == '1':
			return '0'
		else:
			return s
	if len(g) > 2:
		if g[-1][0] == '1' and g[0][0] == '1':
			return '0' + g[-1][1] * '1'
		elif g[-1][0] == '0' and g[0][0] == '0':
			return g[0][1] * '0' + '0'
		elif g[-1][0] == '0' and g[0][0] == '1':
			return '0'
		elif g[-1][0] == '1' and g[0][0] == '0':
			return g[0][1] * '0' + '0' + g[-1][1] * '1'
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	print(solve(s))


def solve(n, string):
	k = 0
	for i in range(1, n):
		if string[i] == '0' and string[i - 1] == '1':
			k = 1
			break
	if k == 0:
		return string
	else:
		zero = 0
		ones = 0
		for i in range(n):
			if string[i] == '0':
				zero += 1
			else:
				break
		for i in range(n - 1, -1, -1):
			if string[i] == '1':
				ones += 1
			else:
				break
	return '0' * (zero + 1) + '1' * ones
for _ in range(int(input())):
	n = int(input())
	string = input()
	print(solve(n, string))


from math import *

def r1(t):
	return t(input())

def r2(t):
	return [t(i) for i in input().split()]
for _ in range(r1(int)):
	n = r1(int)
	s = input()
	c0 = 0
	c1 = 0
	for i in range(n):
		if s[i] == '0':
			c0 += 1
		if s[i] == '1':
			c1 += 1
	if c1 == 0 or c0 == 0:
		print(s)
	else:
		ans = ''
		i = 0
		while i < n:
			if s[i] == '1':
				break
			i += 1
		ans += i * '0'
		c0 = i - 1
		ts = i - 1
		while i < n:
			if s[i] == '0':
				c0 = i
			i += 1
		if c0 > ts:
			ans += '0'
		ans += '1' * (n - c0 - 1)
		print(ans)


def solve():
	(n, s) = (int(input()), input())
	t = True
	for i in range(1, n):
		if s[i] < s[i - 1]:
			t = False
			break
	if t:
		print(s)
		return
	p1 = 0
	for i in range(n):
		if s[i] == '1':
			break
		p1 += 1
	p2 = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			break
		p2 += 1
	print(s[:p1] + '0' + s[n - p2:])
for _ in range(int(input())):
	solve()


def clean(s):
	fo = -1
	lz = -1
	i = 0
	while i < len(s):
		if s[i] == '1':
			if fo == -1 or i < fo:
				fo = i
		if s[i] == '0':
			if lz == -1 or i > lz:
				lz = i
		i = i + 1
	if (fo != -1 and lz != -1) and lz > fo:
		s = s[:fo] + s[lz:]
	return s
t = int(input())
while t > 0:
	n = int(input())
	s = input().strip()
	print(clean(s))
	t = t - 1


from collections import *
from bisect import *
from math import *
for _ in range(int(input())):
	n = int(input())
	l = list(input())
	zero_ind = -1
	one_ind = -1
	ones = []
	zeroes = []
	for i in range(n):
		if l[i] == '0':
			zero_ind = i
			zeroes.append(i)
		if l[i] == '1' and one_ind == -1:
			one_ind = i
		if l[i] == '1':
			ones.append(i)
	if len(ones) == 0 or len(zeroes) == 0:
		print(''.join(l))
	elif zero_ind < one_ind:
		print(''.join(l))
	else:
		ans = l[:ones[0]] + l[zeroes[-1]:]
		print(''.join(ans))


from sys import stdin, stdout

def II():
	return int(input())

def SI():
	return input()
t = II()
for _ in range(t):
	n = II()
	s = SI()
	x = s[::-1]
	(p0, s1) = (0, 0)
	for c in s:
		if c == '0':
			p0 += 1
		else:
			break
	for c in x:
		if c == '1':
			s1 += 1
		else:
			break
	if n > p0 + s1:
		ans = '0' * (p0 + 1) + '1' * s1
	else:
		ans = s
	stdout.write(str(ans) + '\n')


for i in range(int(input())):
	L = int(input())
	s = input()
	flag = 0
	if L == 1 or s.count('0') == 0 or s.count('1') == 0:
		print(s)
		continue
	elif s.index('1') < len(s) - 1 - s[::-1].index('0'):
		flag = 1
	print(s[:s.index('1')] + '0' * flag + s[len(s) - 1 - s[::-1].index('0') + 1:])


for _ in range(0, int(input())):
	n = int(input())
	l = list(input().strip())
	l.reverse()
	if l.count('0') == 0 or l.count('1') == 0:
		print(''.join((str(x) for x in l)))
	else:
		ones = 0
		zeroes = 0
		for i in range(0, n):
			if l[i] == '0':
				break
			else:
				ones += 1
		l.reverse()
		for i in range(0, n):
			if l[i] == '1':
				break
			else:
				zeroes += 1
		if n > ones + zeroes:
			zeroes += 1
		print('0' * zeroes + '1' * ones)


t = int(input())
for i in range(t):
	n = int(input())
	S = list(input())
	a = 0
	for j in range(n):
		if S[j] == '1':
			break
		else:
			a += 1
	B = S[a:][::-1]
	N = len(B)
	b = 0
	for j in range(N):
		if B[j] == '0':
			break
		else:
			b += 1
	if a + b < n:
		ans = ['0' for i in range(a + 1)] + ['1' for i in range(b)]
	else:
		ans = ['0' for i in range(a)] + ['1' for i in range(b)]
	ans = ''.join(ans)
	print(ans)


for i in range(int(input())):
	n = int(input())
	t = input()
	h = 0
	for j in range(n - 1, -1, -1):
		if t[j] == '0':
			ans = t[j:]
			if '1' in t[:j]:
				ans = '0' * t[:j].index('1') + ans
			else:
				ans = t
			print(ans)
			h += 1
			break
	if h == 0:
		print(t)


q = int(input())
for i in range(q):
	n = int(input())
	ch = input()
	ch1 = ch[::-1]
	res = ''
	res1 = ''
	x = -1
	for i in range(n):
		if ch[i] == '0':
			res1 = res1 + ch[i]
		else:
			break
	for i in range(n - 1):
		if ch1[i] == '0' and ch1[i + 1] == '1':
			x = i
			break
	if x == -1:
		res = ch
	else:
		res = ch1[0:x + 1]
		res = res[::-1]
		y = -1
		for i in range(len(res) - 1):
			if res[i] == '0' and res[i + 1] == '1':
				y = i
				break
		if y == -1:
			res = '0'
		else:
			res = res[y:]
		res = res1 + res
	print(res)


for _ in range(int(input())):
	n = int(input())
	s = input()
	zero = s.rfind('0')
	one = s.find('1')
	if one > zero:
		print(s)
	else:
		print(s[0:one] + s[zero:])


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = input()
	j = n - 1
	k = 0
	R = ''
	L = ''
	while j >= 0 and l[j] == '1':
		R = R + '1'
		j -= 1
	while k < n and l[k] == '0':
		L += '0'
		k += 1
	if j < 0:
		print(R)
	elif k == n:
		print(L)
	elif j < k:
		ans = L + R
		print(ans)
	else:
		ans = L + '0' + R
		print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	s1 = int(s[0] == '0') * (s + '1').index('1') * '0'
	s3 = int(s[-1] == '1') * (s[::-1] + '0').index('0') * '1'
	s2 = '0' * int(len(s1) + len(s3) != n)
	print(s1 + s2 + s3)


import sys

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

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

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

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

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(n, s):
	if s.count('1') == 0 or s.count('0') == 0:
		return s
	ss = s[:s.index('1')]
	i = 0
	while i < n and s[n - i - 1] == '1':
		i += 1
	se = s[-i:] if i > 0 else ''
	c = ''
	if len(ss) + len(se) < n:
		c = '0'
	return ss + c + se

def main():
	for _ in range(ri()):
		n = ri()
		s = rs()
		ws(solve(n, s))
main()


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():

	def solve():
		n = int(input())
		ss = input()
		fone = ss.find('1')
		lzero = ss.rfind('0')
		if fone == -1 or lzero == -1 or lzero < fone:
			print(ss)
			return
		print('0' * (fone + 1) + '1' * (n - lzero - 1))
	t = int(input())
	for _ in range(t):
		solve()
main()


t = int(input())
for test in range(0, t):
	n = int(input())
	s = input()
	l = n
	r = -1
	for i in range(0, n):
		if l == n:
			if s[i] == '1':
				l = i
		if r == -1:
			if s[n - 1 - i] == '0':
				r = n - 1 - i
	if l < r:
		ans = s[0:l] + '0' + s[r + 1:n]
		print(ans)
	else:
		print(s)


for _ in range(int(input())):
	n = int(input())
	l = input()
	ans = ''
	if '10' in l:
		ans += '0'
	for i in range(n):
		if l[i] == '0':
			ans += '0'
		else:
			break
	for i in reversed(range(n)):
		if l[i] == '1':
			ans += '1'
		else:
			break
	print(ans if len(ans) > 0 else '0')


import re
tc = int(input())
while tc > 0:
	n = int(input())
	print(re.sub('(10+)+', '0', re.sub('1+0', '10', input())))
	tc -= 1


import sys

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

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	n = int(input())
	s = [int(i) for i in input()]
	i = n - 1
	while i >= 0:
		j = i
		if s[i] == 1:
			i -= 1
			continue
		while i >= 0 and s[i] == 0:
			i -= 1
		if i < 0:
			break
		else:
			while j >= 0 and s[j] == 0:
				s[j] = -1
				j -= 1
			s[i] = 0
	for i in range(len(s)):
		if s[i] == -1:
			continue
		print(s[i], end='')
	print()


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = input().rstrip()
	if '1' not in a or '0' not in a:
		print(a)
		continue
	idx1 = a.find('1')
	b = a[::-1]
	idx2 = b.find('0')
	idx3 = n - idx2
	if idx1 == idx3:
		print('0' * idx1 + '1' * idx2)
	else:
		print('0' * idx1 + '0' + '1' * idx2)


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	if '10' not in s:
		print(s)
		continue
	f = s.find('1')
	f2 = s.rfind('0')
	s1 = s[:f] + '0' + s[f2 + 1:]
	print(s1)


import math
t = int(input())
for g in range(0, t):
	n = int(input())
	s = input()
	a = []
	for i in range(0, n):
		if s[i] == '1':
			a.append(i)
	if len(a) == 0:
		print(s)
	elif len(a) == 1:
		if a[0] == n - 1:
			print(s)
		else:
			print(s[0:a[0]] + '0')
	elif len(a) == n:
		print(s)
	else:
		ans = '0'
		i = 0
		p = 0
		q = 0
		while i < n:
			if s[i] == '0':
				ans += '0'
				p += 1
			else:
				break
			i += 1
		i = n - 1
		while i >= 0:
			if s[i] == '1':
				ans += '1'
				q += 1
			else:
				break
			i -= 1
		if p + q == n:
			print(s)
		else:
			print(ans)


for _ in range(int(input())):
	n = int(input())
	a = input()
	ans = []
	f = 0
	t = []
	for i in range(n - 1, -1, -1):
		if a[i] == '0':
			t.append(a[i])
		if a[i] == '1':
			if len(t) > 0:
				t = ['0']
			else:
				ans.append('1')
				t = []
	if len(t) > 0:
		for i in range(len(t)):
			ans.append('0')
	for i in range(len(ans) - 1, -1, -1):
		print(ans[i], end='')
	print('')


import sys

def Q2():
	t = int(sys.stdin.readline())
	for i in range(t):
		n = int(sys.stdin.readline())
		c = str(sys.stdin.readline())
		zeros = 0
		ones = 0
		for j in range(n):
			if c[j] != '0':
				break
			zeros += 1
		for j in range(n - 1, -1, -1):
			if c[j] != '1':
				break
			ones += 1
		for j in range(zeros):
			print(0, end='')
		if zeros + ones != n:
			print(0, end='')
		for j in range(ones):
			print(1, end='')
		print()
Q2()


list_ans = []
for _ in range(int(input())):
	n = int(input())
	s = input()
	if '0' not in s:
		list_ans.append(s)
	else:
		s1 = s[:][::-1]
		a = s1.index('0')
		if '1' not in s1[a + 1:]:
			list_ans.append(s)
		else:
			b = s[:-a - 1].index('1')
			list_ans.append('0' * (b + 1) + '1' * a)
for item in list_ans:
	print(item)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	string = input()
	flag = False
	primeiroum = n
	ultimozero = -1
	for k in range(n):
		if string[k] == '1' and k < primeiroum:
			primeiroum = k
		if string[k] == '0' and k > ultimozero:
			ultimozero = k
	if primeiroum == n or ultimozero == -1 or ultimozero < primeiroum:
		print(string, end='')
		return
	stringaux = string[:primeiroum] + '0' + string[ultimozero + 1:]
	print(stringaux, end='')
test = int(input())
while test != 0:
	solve()
	test -= 1


for p in range(int(input())):
	n = int(input())
	s = input()
	l = s.find('1')
	r = s.rfind('0')
	if r > l:
		a = s[:l] + '0' + s[r + 1:]
		print(a)
	else:
		print(s)


import math
from bisect import bisect_left
for _ in range(int(input())):
	input()
	s = input()
	i = s.find('10')
	if i > 0:
		while s[i - 1] == '1':
			i -= 1
			if i == 0:
				break
	if i == -1:
		print(s)
		continue
	ans = s[:i]
	if s[-1] == '0':
		ans += '0'
	else:
		r = s[::-1]
		p = r.find('0')
		ans += '0' + '1' * p
	print(ans)


def main():
	for _ in range(int(input())):
		n = int(input())
		s = list(input())
		s1 = ''.join(s)
		print(s1[:s1.find('1')] + ''.join(s[s1.rfind('0'):]) if s1.rfind('0') + 1 != s1.find('1') else s1)
main()


R1 = lambda : list(map(int, input().split()))
R2 = lambda : int(input())
for _ in range(R2()):
	k = R2()
	A = input()
	d = True
	first_zero = last_zero = 0
	for i in range(k - 1):
		if A[i] > A[i + 1]:
			d = False
			break
	if d:
		print(A)
		continue
	for i in range(k):
		if A[i] == '1':
			first_zero = i
			break
	for i in range(k - 1, 0, -1):
		if A[i] == '0':
			last_zero = i
			break
	res = A[:first_zero] + '0' + A[last_zero + 1:]
	print(res)


def solution():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input()
		i = n - 2
		is_one = False
		first_ap = 0
		index = 0
		if s[n - 1] == '0':
			is_one = True
			first_ap = 1
			index = n - 1
		while i >= 0:
			if is_one and s[i] == '1':
				current_i = i - 1
				while current_i >= 0 and s[current_i] == '1':
					current_i -= 1
				s = s[0:current_i + 1] + '0' + s[index + 1:]
				is_one = False
				i = current_i + 1
				continue
			if s[i] == '0':
				if first_ap == 0:
					first_ap = 1
				if not is_one:
					index = i
				is_one = True
			i -= 1
		print(s)
solution()


def short(s):
	arr = []
	pre = False
	curr = ''
	for i in range(len(s)):
		if pre == False:
			pre = s[i]
			curr = pre
		elif s[i] == pre:
			curr += s[i]
		else:
			arr.append(curr)
			curr = s[i]
			pre = s[i]
	arr.append(curr)
	res = ''
	ans = ''
	if len(arr) == 1:
		return arr[0]
	elif arr[0][0] == '1':
		if arr[len(arr) - 1][0] == '0':
			return '0'
		else:
			return '0' + arr[len(arr) - 1]
	elif arr[len(arr) - 1][0] == '0':
		return arr[0] + '0'
	elif len(arr) > 2:
		return arr[0] + '0' + arr[len(arr) - 1]
	else:
		return arr[0] + arr[len(arr) - 1]

def main():
	for _ in range(int(input())):
		input()
		print(short(str(input())))
main()


import re

def pro_input():
	contents = []
	while True:
		try:
			line = input()
		except EOFError:
			break
		contents.append(line)
	return contents

def delete_from_str(str, i):
	res = ''
	for (j, el) in enumerate(str):
		if j != i:
			res += el
	return res

def replace_el(str, i, replacer):
	res = ''
	for (j, el) in enumerate(str):
		if j == i:
			res += replacer
		else:
			res += el
	return res

def work_once(s):
	a = 'lala'
	for (i, el) in enumerate(s):
		if el == '0':
			a = i
	if a != 'lala':
		s = replace_el(s, a, '2')
		s = re.sub('(1)(0+)', '1', s)
		s = re.sub('2', '0', s)
		s = re.sub('(1+)(0)', '0', s)
	return s
for t in range(int(input())):
	n = input()
	s = str(input())
	print(work_once(s))


import math
for _ in range(int(input())):
	n = int(input())
	l = list(input())
	while True:
		one = 0
		zero = 0
		s = ''
		u = ''
		t = False
		for i in range(len(l)):
			if l[i] == '0' and one != 0:
				zero += 1
			elif l[i] == '0' and one == 0:
				one = 0
				zero = 0
				s += '0'
			elif l[i] == '1' and zero == 0:
				one += 1
			elif l[i] == '1' and zero != 0:
				t = True
				one = 1
				zero = 0
		if t:
			s += '0'
			u = s
		if one != 0 and zero != 0 and (not t):
			s += '0'
			u = s
		elif one != 0 and zero == 0:
			u = s + '1' * one
		else:
			u = s
		print(u)
		break


import os, io
from sys import stdout
import collections
import random
import math
from operator import itemgetter
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def divisors(n):
	i = 1
	result = []
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
		i += 1
	return result
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().decode('utf-8').strip()
	one = -1
	for (i, e) in enumerate(s):
		if e == '1':
			one = i
			break
	zero = -1
	while i < len(s):
		if s[i] == '0':
			zero = i
		i += 1
	if one == -1 or zero == -1:
		print(s)
	else:
		res = s[:one] + s[zero:]
		print(''.join(res))


def solve():
	n = int(input())
	s = input()
	first = -1
	last0 = -1
	for i in range(n):
		if s[i] == '1':
			first = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			last0 = i
			break
	if first == -1 or last0 == -1 or last0 < first:
		print(s)
	else:
		print(s[:first] + s[last0:])
for i in range(int(input())):
	solve()


import math
from decimal import *
getcontext().prec = 30
t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	first_one = -1
	last_zero = -1
	for i in range(n):
		if s[i] == '1':
			first_one = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			last_zero = i
			break
	if last_zero < first_one:
		print(s)
	else:
		ans = s[:first_one] + s[last_zero:]
		print(ans)


t = int(input())
for k in range(t):
	n = int(input())
	s = input()
	s1 = list(s)
	s2 = []
	while s1 != []:
		s = s1.pop()
		if s2 == []:
			s2.append(s)
		else:
			p = s2.pop()
			if s == '0':
				s2.append(p)
				s2.append(s)
			elif s == '1':
				if p == '1':
					s2.append(p)
					s2.append(s)
				elif s2 == []:
					s2.append(p)
				elif s2[-1] == '0':
					s1.append(s)
				elif s2[-1] == '1':
					s2.append(p)
	res = list(s2)
	print(''.join(res[::-1]))


for i in range(int(input())):
	n = int(input())
	s = input()
	(a, b) = ('', '')
	for i in range(n):
		if s[i] == '0':
			a += s[i]
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			b += s[i]
		else:
			break
	if len(a) + len(b) == n:
		print(a + b)
	elif len(a) != 0 and len(b) != 0:
		print(a + '0' + b)
	elif len(a) == 0 and len(b) == 0:
		print(0)
	elif len(a) == 0:
		print('0' + b)
	elif len(b) == 0:
		print(a + '0')


for _ in range(int(input())):
	n = int(input())
	s = input()
	if s.find('10') == -1:
		print(s)
		continue
	d = dict()
	d[1] = []
	d[0] = []
	j = s.find('1')
	st = '0' * j
	o = 0
	z = 0
	for i in range(j, n):
		if s[i] == '1':
			if z != 0:
				d[0].append(z)
				z = 0
			o += 1
		else:
			if o != 0:
				d[1].append(o)
				o = 0
			z += 1
	if z != 0:
		d[0].append(z)
	ed = '1' * o
	res = st + '0' + ed
	print(res)


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	n = int(input())
	S = input()
	A = []
	st = S[0]
	prev = st
	cur = 0
	for s in S:
		if s == prev:
			cur += 1
		else:
			A.append(cur)
			cur = 1
			prev = s
	A.append(cur)
	if len(A) == 1:
		print(S)
	elif len(A) == 2:
		if st == '0':
			print(S)
		else:
			print('0')
	elif st == '0':
		if S[-1] == '0':
			print('0' * (A[0] + 1))
		else:
			print('0' * (A[0] + 1) + '1' * A[-1])
	elif S[-1] == '0':
		print('0')
	else:
		print('0' + '1' * A[-1])


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	(cnt0, cnt1) = (-1, -1)
	for i in range(n):
		if s[i] == '1':
			cnt0 = i
			break
	for i in range(n):
		if s[n - i - 1] == '0':
			cnt1 = i
			break
	if min(cnt0, cnt1) == -1 or cnt0 + cnt1 == n:
		print(''.join(s))
	else:
		print('0' * (cnt0 + 1) + '1' * cnt1)


test = int(input())
for j in range(test):
	n = int(input())
	x = input()
	c1 = 0
	c0 = 0
	for i in range(n - 1, -1, -1):
		if x[i] == '1':
			c1 += 1
		else:
			break
	for i in range(n):
		if x[i] == '0':
			c0 += 1
		else:
			break
	y = ''
	for i in range(c0):
		y += '0'
	if c0 + c1 != n:
		y += '0'
	for i in range(c1):
		y += '1'
	print(y)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
MOD = 10 ** 9 + 9
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	s = str(stdin.readline().strip('\n'))
	if '0' not in s or '1' not in s:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			fo = i
			break
	for i in range(n):
		if s[n - 1 - i] == '0':
			lz = n - 1 - i
			break
	if fo < lz:
		print(s[:fo] + '0' + s[lz + 1:])
	else:
		print(s)


t = int(input())
for i in range(0, t):
	n = int(input())
	s = input()
	ans = ''
	j = 0
	cnt = 0
	k = n - 1
	cnt1 = 0
	temp = ''
	n = len(s)
	while j < n and s[j] == '0':
		ans += '0'
		cnt += 1
		j += 1
	while k >= 0 and s[k] == '1':
		cnt1 += 1
		temp += '1'
		k -= 1
	if n - cnt - cnt1 > 1:
		ans += '0'
	ans += temp
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	arr = input()
	prev_len = -1
	while True:
		i = 0
		s = []
		while i < len(arr):
			if not s:
				s.append(arr[i])
			elif arr[i] == '0' and (s[-1] == 'x' or s[-1] == '1'):
				s[-1] = 'x'
			elif arr[i] == 'x' and (s[-1] == 'x' or s[-1] == '1'):
				s[-1] = 'x'
			else:
				s.append(arr[i])
			i += 1
		if len(s) == prev_len:
			break
		prev_len = len(s)
		arr = s
	print(''.join(s).replace('x', '0'))
	t -= 1


for z in range(int(input())):
	n = int(input())
	s = input()
	c0 = 0
	c1 = 0
	for i in range(n):
		if s[i] == '0':
			c0 += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			c1 += 1
		else:
			break
	ns = ''
	flag = 0
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '0':
			flag = 1
			break
	if flag == 0:
		ns = s
	else:
		for i in range(c0):
			ns = ns + '0'
		ns = ns + '0'
		for j in range(c1):
			ns = ns + '1'
	print(ns)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	l = s.count('0')
	i = 0
	k = 0
	y = 0
	u = 0
	while i < n:
		if s[i] == '1':
			if k == 0:
				k = 1
				u = i
		elif s[i] == '0':
			y = i
		i += 1
	if l == n:
		for i in range(n):
			print(s[i], end='')
		print()
	elif y < u:
		for i in range(n):
			print(s[i], end='')
		print()
	else:
		for i in range(u, y):
			s[i] = ''
		for i in range(len(s)):
			print(s[i], end='')
		print()


def solve(s, n):
	b = list(s)
	b.sort()
	if ''.join(b) == s:
		return s
	b.reverse()
	if ''.join(b) == s:
		return '0'
	zf = s.index('0')
	fl = s.rindex('1')
	ans = ''
	zl = s.rindex('0')
	fl = s.rindex('1')
	for i in range(n):
		if s[i] == '1':
			idx1 = i
			break
		else:
			ans += s[i]
	ans2 = ''
	for i in range(zl, n):
		ans2 += s[i]
	return ans + ans2
try:
	for _ in range(int(input())):
		n = int(input())
		s = input()
		print(solve(s, n))
except EOFError:
	pass


from fractions import Fraction
import bisect
import os
import io
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

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

def iinput():
	return int(input())

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

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for _ in range(t):
	n = iinput()
	a = input()
	i = 0
	ones = 0
	start = ''
	j = -1
	for i in range(n):
		if a[i] == '0':
			start += '0'
		else:
			break
	end = ''
	i = n - 1
	while i >= 0 and a[i] == '1':
		end += '1'
		i -= 1
	got = False
	for i in range(n - 1):
		if a[i] == '1' and a[i + 1] == '0':
			got = True
			break
	print(start + ['', '0'][got] + end)


import sys
from fractions import gcd
from math import ceil, sqrt, sin, pi, tan
from collections import defaultdict
read = sys.stdin.buffer.readline
import heapq
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
as0 = ord('0')
as1 = ord('1')
for _ in range(cin()):
	n = cin()
	s = read()
	st = [chr(s[n - 1])]
	for i in range(n - 2, -1, -1):
		if s[i] == as0:
			st.append('0')
		elif s[i] == as1 and st[-1] == '1':
			st.append('1')
		else:
			while st and st[-1] == '0':
				st.pop()
			st.append('0')
	for el in st[::-1]:
		print(el, end='')
	print()


import sys
import math
from decimal import *

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

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

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

def solve():
	tt = I()
	for ii in range(tt):
		n = I()
		s = input()
		has1 = False
		st1 = None
		idx = 0
		for i in range(len(s)):
			x = s[i]
			if x == '0':
				if has1:
					idx = i
			else:
				if st1 == None:
					st1 = i
				has1 = True
		ans = ''
		if st1 != None and st1 < idx:
			ans += s[0:st1]
		ans += s[idx:]
		print(ans)
solve()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	sa = set(s)
	if len(sa) == 1:
		print(s)
	else:
		a = s.index('1')
		b = s.rindex('0')
		if b < a:
			print(s)
		else:
			print(s[:a] + '0' + s[b + 1:])


import sys
import string
import re
input = sys.stdin.readline
t = int(input())
for test in range(t):
	n = int(input())
	s = input()
	s = s.rstrip('\n')
	zeros = 0
	ones = 0
	for i in range(len(s)):
		if s[i] == '0':
			zeros += 1
		else:
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			ones += 1
		else:
			break
	if zeros + ones == len(s):
		print(s)
	else:
		ans = zeros * '0'
		ans += '0'
		ans += ones * '1'
		print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ind = (s + '1').index('1')
	if s[ind:].count('0') == 0:
		ind = len(s)
	ans = s[:ind]
	if ind == len(s):
		print(ans)
	elif s[-1] == '1':
		z = s[::-1].index('0')
		print(ans + '0' + '1' * z)
	else:
		print(ans + '0')


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

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

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

def c(n, r):
	return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

def main():
	n = int(input())
	s = input()
	res = ''
	i = 0
	while i < n and s[i] != '1':
		res += s[i]
		i += 1
	j = i
	while i < n:
		if s[i] == '0':
			j = i
		i += 1
	while j < n:
		res += s[j]
		j += 1
	print(res)
t = int(input())
for _ in range(t):
	main()


for i in range(int(input())):
	n = int(input())
	s = str(input())
	if len(set(s)) > 1:
		q = s.index('1')
		c = n - s[::-1].index('0')
		if c == q:
			print(s)
		else:
			print(s[:q] + '0' + s[c:])
	else:
		print(s)


t = int(input())
while t:
	n = int(input())
	S = input()
	ans = ''
	for s in S:
		if s != '0':
			break
		ans += '0'
	S = S[len(ans):len(S)]
	if '0' in S and S[len(S) - 1] == '0':
		ans += '0'
	elif '0' in S and S[len(S) - 1] == '1':
		ans += '0'
		idx = len(S) - 1
		while S[idx] == '1':
			ans += '1'
			idx -= 1
	else:
		ans += S
	print(ans)
	t -= 1


for t in range(int(input())):
	n = int(input())
	s = input()
	i = s.find('1')
	ans = ''
	count = 0
	if i >= 0:
		ans += '0' * i
		s = s[i:]
	j = s.rfind('0')
	if j >= 0:
		ans += s[j:]
	else:
		ans += s
	if s == '0' * n:
		ans = s
	print(ans)


import sys

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

def iinput():
	return int(input())

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
	n = iinput()
	s = input()
	l = len(s)
	while '10' in s:
		i = s.rindex('10')
		if i > 0 and s[i - 1] == '1':
			s = s[:i] + '0' + s[i + 2:]
		elif i < l - 2 and s[i + 2] == '0':
			s = s[:i] + '1' + s[i + 2:]
		else:
			s = s[:i] + '0' + s[i + 2:]
		l -= 1
	print(s)


t = int(input())
for qwerty in range(t):
	n = int(input())
	s = input()
	ans1 = ''
	i = 0
	while i < n and s[i] == '0':
		ans1 += '0'
		i += 1
	ans2 = ''
	j = n - 1
	while j >= 0 and s[j] == '1':
		ans2 += '1'
		j -= 1
	if i > j:
		print(ans1 + ans2)
	else:
		print(ans1 + '0' + ans2)


import sys
import re

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

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	n = int(input())
	s = input()
	s = re.sub('1+0', '10', s)
	s = re.sub('10+', '10', s)
	s = re.sub('(10)+', '0', s)
	answers.append(s)
print(*answers, sep='\n')


import math
from sys import stdin
from collections import Counter, defaultdict, deque
input = stdin.readline
mod = pow(10, 9) + 7

def solve():
	n = int(input())
	s = list(input().strip('\n'))
	flag = 0
	s1 = []
	c1 = s.count('0')
	c2 = s.count('1')
	if c1 == 0 or c2 == 0:
		z = ''.join(s)
		print(z)
		return
	l1 = []
	for i in range(n):
		if s[i] == '0':
			l1.append(i)
	x = s.index('1')
	s1 = s1 + s[0:x]
	x1 = l1[-1]
	if x > x1:
		z = ''.join(s)
		print(z)
	else:
		s1 = s1 + s[x1:]
		z = ''.join(s1)
		print(z)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	l = list(input())
	ans = []
	i = 0
	while i < n and l[i] == '0':
		ans.append('0')
		i += 1
	x = n - 1
	ans1 = []
	while x >= 0 and l[x] == '1':
		ans1.append('1')
		x -= 1
	if i < x:
		ans.append('0')
	print(''.join(ans), end='')
	print(''.join(ans1))


t = int(input())
while t > 0:
	n = int(input())
	s = list(input())
	temp = []
	pos = n
	for i in range(n):
		if s[i] == '1':
			pos = i
			break
	temp = s[:pos]
	lpos = -10
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			lpos = i
			break
	if lpos == -10:
		lpos = 0
	elif lpos == pos - 1:
		lpos += 1
	if lpos != -10:
		temp += s[lpos:]
	print(''.join(temp))
	t -= 1


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

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

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

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

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

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

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

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

def S():
	return input()

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

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

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

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

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

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		s = S()
		oi = -1
		zi = 0
		for i in range(n):
			if s[i] == '0':
				zi = i
			elif oi < 0:
				oi = i
		if oi > zi:
			rr.append(s)
		else:
			rr.append(s[:oi] + s[zi:])
	return JA(rr, '\n')
print(main())


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = input()
	j = n - 1
	k = 0
	right = ''
	left = ''
	while j >= 0 and l[j] == '1':
		right = right + '1'
		j -= 1
	while k < n and l[k] == '0':
		left += '0'
		k += 1
	if j < 0:
		print(right)
	elif k == n:
		print(left)
	elif j < k:
		ans = left + right
		print(ans)
	else:
		ans = left + '0' + right
		print(ans)


from collections import defaultdict as dd
import math
import sys
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

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

def lm():
	return list(map(int, input().split()))
q = nn()
for _ in range(q):
	n = nn()
	s = input()
	z = 0
	o = n - 1
	ans = []
	while z < n and s[z] == '0':
		z += 1
		ans.append('0')
	while o >= 0 and s[o] == '1':
		o -= 1
		ans.append('1')
	if z <= o:
		ans = ['0'] + ans
	print(''.join(ans))


import sys
input = sys.stdin.readline
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

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

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

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

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(div, n):
	if div == 0:
		return True
	return n % div == 0
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys

def solve():
	n = int(input())
	s = input().rstrip()
	ones = 0
	zeroes = 0
	for x in s[::-1]:
		if x == '1':
			if zeroes > 0:
				break
			else:
				ones += 1
		else:
			zeroes += 1
	if zeroes + ones != n:
		zeroes = 1
	for x in s:
		if zeroes + ones == n:
			break
		if x == '1':
			break
		else:
			zeroes += 1
	print('0' * zeroes + '1' * ones)
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	x = 0
	y = n - 1
	new_s = ''
	if s == '1' or s == '0':
		print(s)
	else:
		while x <= n - 1 and s[x] == '0':
			x += 1
		while y >= 0 and s[y] == '1':
			y -= 1
		for i in range(0, x):
			new_s += '0'
		if x < y:
			new_s += '0'
		for i in range(y + 1, n):
			new_s += '1'
		print(new_s)


t = int(input())
for test in range(t):
	n = int(input())
	s = list(input())
	i = n - 1
	fi = -1
	si = -1
	while i >= 0:
		if s[i] == '0':
			fi = i
			break
		i -= 1
	for i in range(n):
		if s[i] == '1':
			si = i
			break
	if fi != -1 and si != -1 and (fi > si):
		s[si] = '0'
		for i in range(si + 1, fi + 1):
			s[i] = '-1'
	ans = ''
	for i in range(n):
		if s[i] != '-1':
			ans += s[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(e, f) = (0, 0)
	x = list(s)
	if sorted(x) == x:
		print(s)
	elif sorted(x, reverse=True) == x:
		print(0)
	else:
		for i in s:
			if i == '0':
				e += 1
			else:
				break
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				f += 1
			else:
				break
		print((e + 1) * '0', f * '1', sep='')


def clean(s, l):
	ind_0 = None
	for i in range(l - 1, -1, -1):
		if s[i] == '0':
			ind_0 = i
			break
	ind_1 = None
	for i in range(l):
		if s[i] == '1':
			ind_1 = i
			break
	if ind_1 is None or ind_0 is None:
		return s
	if ind_0 < ind_1:
		return s
	return s[:ind_1] + s[ind_0:]
for _ in range(int(input())):
	l = int(input())
	s = input()
	print(clean(s, l))


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	a = n - 1
	b = 0
	for i in range(n):
		if s[i] == '1':
			a = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			b = i
			break
	if a > b:
		for i in range(n):
			print(s[i], end='')
		print()
	else:
		s = s[:a] + s[b:]
		for i in range(len(s)):
			print(s[i], end='')
		print()


ll = lambda : list(map(int, input().split()))
st = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
for _ in range(ii()):
	n = ii()
	l = st()
	s = []
	if l.count('0') == 0 or l.count('1') == 0:
		print(l)
		continue
	for i in range(n):
		if l[i] == '1':
			k = i
			break
	for i in reversed(range(n)):
		if l[i] == '0':
			j = i
			break
	if j < k:
		print(l)
	else:
		ans = ''
		for i in range(k):
			ans += l[i]
		for i in range(j, n):
			ans += l[i]
		print(ans)


import re
for _ in range(int(input())):
	n = int(input())
	arr = input()
	if '10' not in arr:
		print(arr)
	else:
		final = ''
		final += '0' * (n - len(arr.lstrip('0')))
		final += '0'
		final += '1' * (n - len(arr.rstrip('1')))
		print(final)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(zeros, ones) = (0, 0)
	for i in s:
		if i == '0':
			zeros += 1
		else:
			break
	for i in reversed(range(n)):
		if s[i] == '1':
			ones += 1
		else:
			break
	print('0' * zeros, end='')
	if zeros + ones != n:
		print('0', end='')
	print('1' * ones)


import sys
n = int(sys.stdin.readline().strip())
inp = []
for _ in range(n):
	sys.stdin.readline()
	inp.append(sys.stdin.readline().strip())
for line in inp:
	starting_zeros = line.split('1', 1)[0]
	trailing_ones = line.rsplit('0', 1)[-1]
	if len(starting_zeros) + len(trailing_ones) == len(line):
		print(line)
	else:
		print('0'.join([starting_zeros, trailing_ones]))


for _ in ' ' * int(input()):
	(n, a) = (int(input()), input())
	print(a if '10' not in a else '0' + a[a.rfind('0') + 1:] if a.find('1') < a.find('0') else a[:a.find('1')] + '0' + a[a.rfind('0') + 1:])


t = int(input())
for i in range(t):
	n = int(input())
	l = list(input())
	if '1' not in l or '0' not in l:
		print(''.join(l))
	else:
		start = l.index('1')
		final = ''.join(l[:start])
		last = ''.join(l).rindex('0')
		if last > start:
			print(final + '0' + ''.join(l[last + 1:]))
		else:
			print(''.join(l))


from math import ceil
from collections import deque
for _ in range(int(input())):
	n = int(input())
	s = input() + '1'
	j = n
	a = deque()
	while j > 0 and s[j] == '1':
		j -= 1
		a.appendleft(s[j])
	for i in range(j):
		if s[i] == '0':
			print(0, end='')
		else:
			break
	for i in a:
		print(i, end='')
	print()


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def main():
	t = int(input())
	for testcase in range(t):
		n = int(input())
		s = input()
		(lef, rig, sw) = (1, 1, 0)
		for i in range(n - 1):
			if s[i] > s[i + 1]:
				sw = 1
				break
		if sw == 0:
			print(s)
			continue
		for i in range(n):
			if s[i] == '1':
				lef = i
				break
		for i in range(n - 1, 0, -1):
			if s[i] == '0':
				rig = i
				break
		st = s[:lef] + '0' + s[rig + 1:]
		print(st)
main()


for t in range(int(input())):
	n = int(input())
	s = input()
	arr = []
	one = 0
	zero = 0
	for i in range(n):
		if s[i] == '0':
			zero -= 1
			if one != 0:
				arr.append(one)
			one = 0
		else:
			one += 1
			if zero != 0:
				arr.append(zero)
			zero = 0
	if zero != 0:
		arr.append(zero)
	else:
		arr.append(one)
	k = 0
	for i in range(len(arr) - 1):
		if arr[i] > arr[i + 1]:
			k = i
	for i in range(len(arr) - 1):
		if arr[i] > 0:
			if i == k:
				arr[i + 1] = -1
			elif arr[i + 1] < 0:
				arr[i + 1] = 1
			else:
				arr[i + 1] += 1
		if arr[i] < 0:
			print('0' * -arr[i], end='')
	if arr[-1] > 0:
		print('1' * arr[-1])
	else:
		print('0' * -arr[-1])


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	l = s.find('1')
	r = s.rfind('0')
	res = ''
	if l < r:
		res = s[:l] + '0' + s[r + 1:]
	else:
		res = s[:l] + '' + s[r + 1:]
	print(res)


for _ in range(int(input())):
	n = int(input())
	s = input()
	r = ''
	s = s[::-1]
	i = 0
	f = 0
	cnt1 = 0
	while i < len(s):
		x = s[i]
		if x == '1':
			cnt1 = cnt1 + 1
		if x == '0':
			break
		i = i + 1
	j = len(s) - 1 - i
	s = s[::-1]
	i = 0
	f = 0
	cnt0 = 0
	while i < len(s):
		x = s[i]
		if x == '0':
			cnt0 = cnt0 + 1
		if x == '1':
			break
		i = i + 1
	l = [1]
	f = 0
	while i <= j:
		x = s[i]
		if x == '0' and l[-1] == 1:
			f = 1
			break
		i = i + 1
	e = '0' * cnt0
	p = '1' * cnt1
	if f == 1:
		print(e + '0' + p)
	else:
		print(e + p)


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	firstone = -1
	lastzero = n + 1
	for i in range(len(s)):
		if s[i] == '1':
			firstone = i
			break
	for i in range(len(s)):
		if s[i] == '0':
			lastzero = i
	k = s[0:firstone] + s[lastzero:]
	if lastzero < firstone:
		k = s
	if len(s) == 1:
		k = s
	if lastzero == n + 1:
		k = s
	if firstone == -1:
		k = s
	print(k)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	prefix = ''
	root = ''
	suffix = ''
	index1 = 0
	index2 = n - 1
	for i in range(n):
		if s[i] == '1':
			index1 = i
			break
		prefix += s[i]
	for i in reversed(range(n)):
		if s[i] == '0':
			index2 = i
			break
		suffix += s[i]
	suffix = suffix[::-1]
	if prefix == s or suffix == s:
		root = ''
	elif s[index1:index2 + 1] == '':
		root = ''
	else:
		root = '0'
	m = len(root)
	ans = prefix + root + suffix
	print(ans)


for u in range(int(input())):
	n = int(input())
	s = input()
	i = n - 1
	j = n - 1
	ans = 0
	a = ''
	while s[i] == '1' and i >= 0:
		a += s[i]
		i -= 1
	while i >= 0:
		if ans == 1:
			if s[i] == '0':
				ans += 1
				i -= 1
			else:
				i -= 1
		elif s[i] == '0':
			ans += 1
			i -= 1
		else:
			ans = 1
			i -= 1
	for i in range(ans):
		print('0', end='')
	for i in range(len(a)):
		print(a[i], end='')
	print('\n')


for i in range(int(input())):
	n = int(input())
	s = input()
	a = False
	cnt = 0
	cnt1 = 0
	res = ''
	for i in range(n):
		if s[i] == '0':
			res += '0'
		if s[i] == '1':
			break
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '0':
			cnt = 1
			break
	res += '0' * cnt
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			res += '1'
		if s[j] == '0':
			break
	print(res)


for _ in range(int(input())):
	n = int(input())
	s = input()
	s1 = s[::-1]
	i = 0
	ans = ''
	ans1 = ''
	n1 = 0
	while i < n and s[i] == '0':
		ans += '0'
		i += 1
	j = 0
	while j < n and s1[j] == '1':
		ans1 += '1'
		j += 1
	j = n - 1 - j
	if i < j:
		print(ans + '0' + ans1)
	else:
		print(ans + ans1)


for t in range(int(input())):
	n = int(input())
	check = False
	s1 = input()
	if '1' not in s1:
		print(s1)
	else:
		new = ''
		new = new + s1[:s1.index('1')]
		s = s1[s1.index('1'):]
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1' and check == False:
				new += '1'
			if s[i] == '0':
				new = '0' + new
				check = True
				break
		print(new)


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	o = s.find('1')
	z = s.rfind('0')
	if o > z:
		print(s)
	else:
		print(s[:o] + s[z:])


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
(t,) = mp()
for _ in range(t):
	(n,) = mp()
	s = cin()[:-1]
	one = s.find('1') % n
	zero = s.rfind('0')
	if zero <= one:
		cout(s + '\n')
	else:
		cout(s[:one] + s[zero:] + '\n')


t = int(input())
for _ in range(0, t):
	n = int(input())
	s = input()
	z = 0
	o = 0
	for i in range(0, n):
		if s[i] == '1':
			break
		else:
			z += 1
	for j in range(n - 1, -1, -1):
		if s[j] == '0':
			break
		else:
			o += 1
	if i < j:
		print('{}{}{}'.format(z * '0', '0', o * '1'))
	else:
		print(s)


for _ in range(int(input())):
	input()
	s = input()
	a = s.rfind('0')
	b = s.find('1')
	if b > a:
		print(s)
	else:
		print(s[:b] + s[a:])


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = stdin.readline()
	ans = ''
	f = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			f += 1
		elif f > 0:
			if f > 1:
				f = 1
		else:
			ans += '1'
	while f > 0:
		ans += '0'
		f -= 1
	stdout.write(ans[::-1] + '\n')


from sys import stdin, stdout
import sys
from math import *
for __ in range(int(input())):
	n = int(input())
	s = input()
	if n == 1:
		print(s)
	elif n == 2:
		if s == '10':
			print('1')
		else:
			print(s)
	elif s[1:-1].count('0') == n - 2:
		if s[0] == '1' and s[-1] == '1':
			print('01')
		elif s[0] == '1' and s[-1] == '0':
			print('0')
		else:
			print(s)
	elif s[1:-1].count('0') == 0:
		if s[0] == '1' and s[-1] == '0':
			print('0')
		elif s[0] == '0' and s[-1] == '0':
			print('00')
		else:
			print(s)
	else:
		x = 0
		for i in range(n):
			x = i
			if s[i] == '1':
				break
		y = n - 1
		for i in range(n - 1, -1, -1):
			y = i
			if s[i] == '0':
				break
		if y < x:
			print(s)
		else:
			ans = ''
			if x > 0:
				ans = s[:x]
			ans += s[y:]
			print(ans)


from math import ceil, inf

def pro(s):
	n = len(s)
	if n == 1:
		print(s[0])
		return
	f = 0
	for i in range(n - 1):
		if int(s[i]) > int(s[i + 1]):
			f = 1
			break
	if f == 0:
		print(s)
		return
	for i in range(n):
		if s[i] == '1':
			lef = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			rig = i
			break
	print(s[:lef] + '0' + s[rig + 1:])
t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	pro(a)


import sys
input = sys.stdin.readline

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

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

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

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

def solve(t):
	if t.count('1') == len(t) or t.count('0') == len(t):
		print(t)
		return
	zeros = 0
	for v in t:
		if v == '0':
			zeros += 1
		else:
			break
	ones = 0
	for v in reversed(t):
		if v == '1':
			ones += 1
		else:
			break
	if zeros + ones == len(t):
		print(t)
		return
	else:
		print('0' * zeros + '0' + '1' * ones)
T = inp()
tests = []
for _ in range(T):
	inp()
	tests.append(insr())
for t in tests:
	solve(t)


for test_case in range(int(input())):
	size = int(input())
	string = input()
	(left, right) = (1, 1)
	increasing = True
	for i in range(size - 1):
		if string[i] > string[i + 1]:
			increasing = False
			break
	if increasing:
		print(string)
		continue
	for i in range(size):
		if string[i] == '1':
			left = i
			break
	for i in range(size - 1, 0, -1):
		if string[i] == '0':
			right = i
			break
	final = string[:left] + '0' + string[right + 1:]
	print(final)


def solve(s):
	nol = ''
	i = 0
	rightNolIdx = -1
	if s[0] == '0':
		while True:
			i += 1
			if i == len(s):
				break
			if s[i] != '0':
				break
		nol = '0' * i
		rightNolIdx = i - 1
	i = len(s) - 1
	satu = ''
	leftSatuIdx = -1
	if s[i] == '1':
		while True:
			i -= 1
			if i < 0:
				break
			if s[i] != '1':
				break
		i += 1
		satu = '1' * (len(s) - 1 - i + 1)
		leftSatuIdx = i
	if rightNolIdx == -1:
		if leftSatuIdx == 0:
			return satu
		if leftSatuIdx != -1:
			return '0' + satu
		return '0'
	if leftSatuIdx == -1:
		if rightNolIdx == len(s) - 1:
			return nol
		if rightNolIdx != -1:
			return nol + '0'
		return '0'
	if rightNolIdx + 1 == leftSatuIdx:
		return nol + satu
	return nol + '0' + satu
t = int(input())
for i in range(t):
	input()
	print(solve(input()))


for _ in range(int(input())):
	i = int(input())
	s = input()
	lo = lz = 0
	o = s.find('1')
	z = s.rfind('0')
	if o > z:
		print(s)
	else:
		t = s[:o] + s[z:]
		print(t)


t = int(input())
for i in range(t):
	l = int(input())
	s = input()
	ans = ''
	for c in s:
		if c == '0':
			ans += '0'
		else:
			break
	l1 = len(ans)
	mid = ''
	for k in range(1, l + 1):
		if s[-k] == '1':
			mid += '1'
		else:
			break
	l2 = len(mid)
	if l == l1 + l2:
		ans += mid
	else:
		ans = ans + '0' + mid
	print(ans)


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

def solve(t):
	k = int(input())
	data = input()
	times = []
	i = 0
	while i < k:
		t = data[i]
		p = 0
		while i < k and data[i] == t:
			i += 1
			p += 1
		times.append((t, p))
	res = ''
	counter = False
	for (i, qq) in enumerate(times):
		(p, l) = qq
		if i == 0 and p == '0':
			res += '0' * l
		elif i == len(times) - 1 and p == '1':
			res += '1' * l
		elif i > 0 and counter == False and (p == '0') and (times[i - 1][0] == '1'):
			res += '0'
			counter = True
	return res

def main():
	tc = int(input().strip())
	for t in range(1, tc + 1):
		print(solve(t))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


def read_int():
	return int(input())

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

def read_int_array():
	return [int(_) for _ in read_string_array()]

def read_line():
	return input()

def solve(s):
	last_zero = max((_ for (_, __) in enumerate(s) if __ == '0')) if '0' in s else None
	first_one = min((_ for (_, __) in enumerate(s) if __ == '1')) if '1' in s else None
	if last_zero is None or first_one is None or first_one > last_zero:
		return s
	head = s[:first_one]
	tail = s[last_zero:]
	return head + tail
T = read_int()
for _ in range(T):
	N = read_int()
	S = read_line()
	print(solve(S))


y = int(input())
ans = []
for j in range(y):
	l = int(input())
	s = list(input())
	a = b = 0
	f1 = f0 = 0
	d = ''
	for i in range(l):
		if s[i] == '1' and f1 == 0:
			f1 = 1
			a = i
		elif s[i] == '0':
			f0 = 1
			b = i
	if f0 == 1 and f1 == 1 and (a < b):
		if a == 0 and b != l - 1:
			ans.append('0' + d.join(s[b + 1:]))
		elif b == l - 1 and a != 0:
			ans.append(d.join(s[:a]) + '0')
		elif a == 0 and b == l - 1:
			ans.append('0')
		else:
			ans.append(d.join(s[:a]) + '0' + d.join(s[b + 1:]))
	else:
		ans.append(d.join(s))
for i in ans:
	print(i)


for _ in range(int(input())):
	n = int(input())
	s = input()
	zCT = 0
	ans = ''
	for i in range(1, n + 1):
		if s[-i] == '1' and zCT == 0:
			ans += '1'
		elif s[-i] == '1':
			zCT = 1
		else:
			zCT += 1
	ans += zCT * '0'
	print(ans[::-1])


import sys
from bisect import bisect_left
from collections import defaultdict
input = lambda : sys.stdin.readline().rstrip()
R = lambda : map(int, input().split())
(T,) = R()
for _ in range(T):
	(n,) = R()
	s = input()
	ans = ''
	idx = n
	for i in range(n):
		if s[i] == '0':
			ans += '0'
		else:
			idx = i
			break
	allone = True
	for i in range(idx, n, 1):
		if s[i] == '0':
			allone = False
			break
	if allone:
		ans += '1' * (n - idx)
	else:
		ans += '0'
		for i in range(n - 1, idx - 1, -1):
			if s[i] == '1':
				ans += '1'
			else:
				break
	print(ans)


import sys
read = lambda : sys.stdin.readline()
T = int(read())
for t in range(T):
	n = int(read())
	s = read()
	result = ''
	i = 0
	while s[i] == '0':
		result += s[i]
		i += 1
	if '0' not in s[len(result):]:
		print(s[:-1])
		continue
	result += '0'
	i = n - 1
	while s[i] == '1':
		result += s[i]
		i -= 1
	print(result)


def compute(n, arr):
	if n == 1:
		return ''.join(arr)
	i = n - 1
	while i > -1:
		if i + 1 < n and arr[i] == '1' and (arr[i + 1] == '0'):
			if i + 2 < n and arr[i + 2] == '0':
				arr.pop(i + 1)
			else:
				arr.pop(i)
			n -= 1
		else:
			i -= 1
	return ''.join(arr)
global n
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(input())
	print(compute(n, arr))


def solve():
	n = int(input())
	p = ''
	s = input()
	z = 0
	o = 0
	for i in range(n):
		if s[i] == '1':
			o += 1
		else:
			z += 1
	f0 = 0
	f1 = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '1' and f0 == 0:
			p += '1'
		elif s[i] == '0' and f0 == 0:
			p += s[i]
			f0 = 1
		elif s[i] == '0' and o == 0:
			p += s[i]
		if s[i] == '0':
			z -= 1
		else:
			o -= 1
	print(p[::-1])
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	l = 0
	r = n - 1
	while l < n and s[l] == '0':
		l += 1
	while r >= 0 and s[r] == '1':
		r -= 1
	if l < r:
		print(s[:l] + s[r:])
	else:
		print(s)


import math
t = int(input())
for g in range(t):
	n = int(input())
	s = input()
	d = list(s)
	c = list(s)
	c.sort()
	if d == c:
		print(s)
		continue
	if d == c[::-1]:
		print('0')
		continue
	ans = ''
	for i in range(n):
		if s[i] == '1':
			d = i
			break
		ans += s[i]
	s = s[d:]
	s = s[::-1]
	a = ''
	f = 0
	for i in range(len(s)):
		if s[i] == '0':
			f = 1
			break
		a += s[i]
	if f == 1:
		ans += '0'
	ans += a
	print(ans)


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	s = input()
	if n == 1:
		print(s)
		continue
	else:
		osn = False
		(f1, f0) = (-1, -1)
		for i in range(n):
			if f1 == -1 and s[i] == '1':
				f1 = i
			if s[i] == '0':
				f0 = i
		if f1 != -1 and f0 != -1 and (f0 > f1):
			ans = s[:f1] + '0' + s[f0 + 1:]
		else:
			ans = s
		print(ans)


from math import *

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

def main():
	n = int(input())
	s = input()
	i = 0
	while i < n and s[i] == '0':
		i = i + 1
	zero = i
	i = n - 1
	one = 0
	while i >= zero and s[i] == '1':
		i = i - 1
		one = one + 1
	if zero + one != n:
		zero = zero + 1
	print('0' * zero, end='')
	print('1' * one)
tt = 1
tt = int(input())
for _ in range(tt):
	main()


from math import ceil
from math import radians
from heapq import heapify, heappush, heappop
import bisect
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

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

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

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

def li1():
	return list(mi())

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

def fsi():
	return str(stdin.readline())

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

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

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

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0 and i % 2 == 1:
			s.add(i)
			n = n // i
	if n > 2 and n % 2 == 1:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

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

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def treeOrderByDepth(n, adj, root=0):
	parent = [-2] + [-1] * (n - 1)
	ordered = []
	q = deque()
	q.append(root)
	depth = [0] * n
	while q:
		c = q.popleft()
		ordered.append(c)
		for a in adj[c]:
			if parent[a] == -1:
				parent[a] = c
				depth[a] = depth[c] + 1
				q.append(a)
	return (ordered, parent, depth)

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

def nextPowerOf2(n):
	count = 0
	if n and (not n & n - 1):
		return n
	while n != 0:
		n >>= 1
		count += 1
	return 1 << count

def cou(n):
	c = 0
	while n > 1:
		c += 1
		n //= 2
	return c

def dfsques(d, x, visited, a, b, m):
	visited[x] = 1
	q = [x]
	c = 1
	cost = m
	pro = [x]
	while q:
		y = q.pop(0)
		for i in d[y]:
			if visited[i] == 0 and (cost * c + a[i - 1]) / (c + b[i - 1]) >= cost:
				q.append(i)
				cost = (cost * c + a[i - 1]) / (c + 1)
				visited[i] = 1
				pro.append(i)
	return (cost, pro)
for _ in range(ii()):
	n = ii()
	s = si()
	stack = []
	x = ''
	c = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			if c == 0:
				x += '1'
			elif c > 1:
				stack = ['0']
				c = 1
		else:
			stack.append('0')
			c += 1
	print(''.join(stack) + x)


import sys
input = sys.stdin.readline
ans = []
for kek in range(int(input())):
	n = int(input())
	s = input()
	b = []
	zero = 0
	one = n
	for i in range(n):
		if s[i] == '1':
			one = min(i, one)
		else:
			zero = max(i, zero)
	if one > zero:
		ans.append(s[0:one - 1] + s[zero:-1])
	else:
		ans.append(s[0:one] + s[zero:-1])
print(*ans, sep='\n')


def solve():
	n = int(input())
	s = input()
	zero = 0
	for c in s:
		if c == '1':
			break
		zero += 1
	ones = 0
	for c in reversed(s):
		if c == '0':
			break
		ones += 1
	print('0' * zero, end='')
	if zero + ones < n:
		print('0', end='')
	print('1' * ones)
t = int(input())
for test in range(t):
	solve()


import sys
sys.setrecursionlimit(10000000)

def read():
	return list(map(int, sys.stdin.readline().split()))
for i in range(int(input())):
	n = int(input())
	s = input()
	lz = -1
	f1 = n
	for i in range(n):
		if s[i] == '0':
			lz = i
		else:
			f1 = min(i, f1)
	if f1 > lz:
		print(s)
	else:
		try:
			last = s[lz + 1:]
		except:
			last = ''
		print(s[:f1] + '0' + last)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	f = '10'
	if f not in s:
		print(s)
	else:
		zero = 0
		one = 0
		for i in s:
			if i == '0':
				zero += 1
			else:
				break
		for i in range(len(s)):
			if s[n - (i + 1)] == '1':
				one += 1
			else:
				break
		res = ''
		for _ in range(zero):
			res += '0'
		res += '0'
		for _ in range(one):
			res += '1'
		print(res)


for x in range(int(input())):
	n = int(input())
	s = input()
	flag = 1
	s1 = ''
	s2 = ''
	for x in s:
		if flag == 1 and x == '0':
			s1 += x
		elif x == '1':
			flag = 0
			s2 += x
		elif flag == 0 and x == '0':
			s2 = '0'
	print(s1 + s2)


for i in range(int(input())):
	n = int(input())
	s = list(input())
	s = [int(x) for x in s]
	u = []
	z = []
	for j in s:
		if j == 0:
			u.append('0')
		else:
			break
	for j in s[::-1]:
		if j == 0:
			z.append('0')
			break
		else:
			z.append(str(j))
	if s == sorted(s) and s.count(0) != 0:
		del z[-1]
	print(''.join(u) + ''.join(z[::-1]))


t = int(input())
while t:
	n = int(input())
	s = input()
	a = ''
	for i in s:
		a += i
	ans = ''
	f = 0
	for (i, v) in enumerate(s):
		if v == '1':
			f = 1
			break
		ans += v
	if f == 1:
		idx = i
		s = s[i:]
	else:
		print(s)
		t -= 1
		continue
	flag = 0
	y = s[::-1]
	l = len(y)
	for (i, v) in enumerate(y):
		if v == '0':
			flag = 1
			break
	if flag == 1:
		idx2 = i
		idx2 = l - idx2 - 1
		x = s[idx2:]
	else:
		x = s
	ans += x
	print(ans)
	t -= 1


for testcase in range(int(input())):
	n = int(input())
	s = input()
	(l, r, flag) = (1, 1, 0)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			flag = 1
			break
	if flag == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			l = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			r = i
			break
	print(s[:l] + '0' + s[r + 1:])


from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
sqrt = math.sqrt

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

def LF():
	return list(map(float, input().split()))

def LI_():
	return list(map(lambda x: int(x) - 1, input().split()))

def II():
	return int(input())

def IF():
	return float(input())

def S():
	return input().rstrip()

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

def IR(n):
	res = [None] * n
	for i in range(n):
		res[i] = II()
	return res

def LIR(n):
	res = [None] * n
	for i in range(n):
		res[i] = LI()
	return res

def FR(n):
	res = [None] * n
	for i in range(n):
		res[i] = IF()
	return res

def LIR(n):
	res = [None] * n
	for i in range(n):
		res[i] = IF()
	return res

def LIR_(n):
	res = [None] * n
	for i in range(n):
		res[i] = LI_()
	return res

def SR(n):
	res = [None] * n
	for i in range(n):
		res[i] = S()
	return res

def LSR(n):
	res = [None] * n
	for i in range(n):
		res[i] = LS()
	return res
mod = 1000000007
inf = float('INF')

def solve():
	t = II()
	for i in range(t):
		n = II()
		s = S()
		f = 0
		ans = []
		if s[0] == '1':
			tmp = [1, 1]
		else:
			tmp = [0, 1]
		for si in s[1:]:
			if si == '1':
				if tmp[0] == 1:
					tmp[1] += 1
				else:
					ans.append(tmp)
					tmp = [1, 1]
			elif tmp[0] == 0:
				tmp[1] += 1
			else:
				ans.append(tmp)
				tmp = [0, 1]
		ans.append(tmp)
		aa = []
		pre = ans[0]
		if pre[0] == 0:
			aa.append(str(pre[0]) * pre[1])
			a = 0
		elif len(ans[1:]):
			pass
		else:
			print(s)
			continue
		tmp = 0
		for (a, b) in ans[1:]:
			if a == 1:
				pre = [a, b]
			else:
				pre = 0
				tmp = 1
		if tmp:
			aa.append('0')
		if a:
			aa.append(str(pre[0]) * pre[1])
		if aa:
			print(''.join(aa))
		else:
			print(0)
	return
solve()


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

def main():
	for case in range(int(input())):
		n = int(input())
		s = input()
		s = s.rstrip('1')
		right = '1' * (n - len(s))
		n = len(s)
		s = s.lstrip('0')
		left = '0' * (n - len(s))
		n = len(s)
		if n == 0:
			print(left + right)
		else:
			print(left + '0' + right)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

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

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

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

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

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

class IOWrapper(IOBase):

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


for _ in range(int(input())):
	n = int(input())
	s = input()
	res = ''
	has_1 = has_0 = False
	z = 0
	fixed_z = 0
	o = 0
	count = 0
	for i in s:
		if i == '1':
			has_1 = True
			o += 1
		else:
			o = 0
			if not has_1:
				fixed_z += 1
			else:
				z = 1
	print('0' * (z + fixed_z) + '1' * o)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	if '10' in s:
		zero = 0
		one = 0
		for j in range(len(s)):
			if s[j] == '0':
				zero += 1
			else:
				break
		for j in range(len(s) - 1, -1, -1):
			if s[j] == '1':
				one += 1
			else:
				break
		st1 = '0' * (zero + 1)
		st2 = '1' * one
		print(st1 + st2)
	else:
		print(s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	w = list(s)
	(f1, l0) = (-1, -1)
	for i in range(n):
		if s[i] == '1' and f1 == -1:
			f1 = i
		if s[i] == '0' and f1 != -1:
			l0 = i
	if f1 != -1 and l0 != -1:
		print(s[:f1] + s[l0:])
	else:
		print(s)


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input()))
	i = 0
	ans = []
	count = [0, 0, 0]
	start1 = -1
	s1 = -1
	lock = False
	while i < n:
		if start1 == -1:
			if l[i] == 1:
				start1 = i
				if lock == False:
					s1 = i
				count[1] += 1
			elif lock == False:
				count[0] += 1
		else:
			lock = True
			if l[i] == 1:
				for y in range(i, n):
					if l[y] == 0:
						start1 = -1
						count[1] = 0
						break
					else:
						count[1] += 1
						i = y
			else:
				start1 = -1
				count[1] = 0
		i += 1
	mid = start1 - count[0]
	if mid == -1 and count[0] == 0:
		print(0)
		continue
	print(count[0] * '0', end='')
	if mid <= -1 and s1 != -1:
		print('0')
		continue
	if mid == 2:
		print('0', end='')
	if mid > 2:
		print('0', end='')
	print('1' * count[1])


n = int(input())
for i in range(n):
	p = int(input())
	s = input()
	j = p - 1
	cntz = 0
	to = 0
	while j >= 0:
		if s[j] == '0':
			cntz += 1
		elif cntz == 0:
			to += 1
		else:
			cntz = 1
		j -= 1
	z = ['0'] * cntz
	o = ['1'] * to
	print(''.join(z + o))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	i1 = -1
	for i in range(n):
		if s[i] == '1':
			i1 = i
			break
	i0 = -1
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			i0 = i
			break
	if i0 == -1 or i1 == -1 or i1 > i0:
		print(s)
	else:
		print(s[:i1] + '0' + s[i0 + 1:])


from sys import stdin, stdout
n = int(stdin.readline())
for i in range(n):
	a = int(stdin.readline())
	s = stdin.readline()
	indx = 0
	zero = one = 0
	just = True
	last = first = -1
	for i in s:
		if i == '0':
			last = indx
		if i == '1':
			if just:
				just = False
				first = indx
		indx += 1
	if last == -1 or first == -1 or first > last:
		stdout.write(s)
		continue
	stdout.write(s[:first] + s[last:])


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
for _ in range(int(input())):
	n = int(input())
	l = list(input())
	ans = []
	i = 0
	while i < n and l[i] == '0':
		ans.append('0')
		i += 1
	x = n - 1
	ans1 = []
	while x >= 0 and l[x] == '1':
		ans1.append('1')
		x -= 1
	if i < x:
		ans.append('0')
	print(''.join(ans), end='')
	print(''.join(ans1))


import heapq

def read_list():
	return list(map(int, input().strip().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
N = int(input())
for _ in range(N):
	n = int(input())
	s = input()
	(a, b) = (0, n - 1)
	while a < n and s[a] == '0':
		a += 1
	while b >= 0 and s[b] == '1':
		b -= 1
	if b <= a:
		print(s)
	else:
		print('0' * (a + 1) + '1' * (n - b - 1))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ch1 = '1' * n
	ch2 = '0' * n
	if s == ch1 or s == ch2:
		print(s)
	else:
		for i in range(n):
			if s[i] == '1':
				first = i
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				zero = i
				break
		if first > zero:
			print(s)
		else:
			s = s[:first] + s[zero:]
			print(s)


inp = lambda : int(input())
inpm = lambda : map(int, input().split())
inpl = lambda : list(inpm())
l2mn = lambda _n, _m: [[0 for __ in range(_m)] for _ in range(_n)]
l2n = lambda _n: l2mn(_n, _n)
INF = int(1e+18)
MOD = int(1000000000.0) + 7

def solve():
	n = inp()
	s = input()
	k1 = 0
	k0 = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			k1 += 1
		else:
			break
	for i in range(n):
		if s[i] == '0':
			k0 += 1
		else:
			break
	if n == 1:
		print(s)
		return
	if k0 + k1 == n:
		print(s)
		return
	print('0' * k0 + '0' + '1' * k1)

def main():
	t = inp()
	for i in range(t):
		solve()
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input().strip()
	t = ''
	ans = s[-1]
	if s[-1] == '0':
		k = 1
	else:
		k = 0
	for i in range(n - 2, -1, -1):
		if k == 0:
			if s[i] == '1':
				ans += '1'
			else:
				ans += '0'
				k = 1
		elif s[i] == '0':
			t += '0'
		else:
			t = ''
	ans += t
	print(ans[::-1])


t = int(input())
for _ in range(t):
	n = int(input())
	s = input().rstrip()
	t = ''
	idx1 = idx2 = -1
	for i in range(n):
		if s[i] == '1':
			idx1 = i
			break
		else:
			t += s[i]
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			idx2 = i
			break
	if idx1 >= idx2:
		print(s)
	elif idx1 == -1:
		print(s)
	else:
		for i in range(idx2, n):
			t += s[i]
		print(t)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	s = input()
	if s.count('0') == len(s):
		print(s)
	else:
		ss = str(s)
		zrrrs = str(int(ss))
		si = ss.replace(zrrrs, '')
		if '0' in zrrrs:
			for i in reversed(range(len(zrrrs))):
				if zrrrs[i] == '0':
					ans = zrrrs[i:]
					break
			print(si + ans)
		else:
			print(si + zrrrs)


def Solve(s):
	check = 0
	for i in range(len(s) - 1):
		j = i + 1
		if s[i] == '1' and s[j] == '0':
			check = 1
			break
	if check == 0:
		return s
	one = s.index('1')
	zero = s.rindex('0')
	new = s[:one] + s[zero:]
	return new
T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	print(Solve(s))


for i in range(int(input())):
	n = int(input())
	str1 = input()
	k = -1
	j = 0
	for i in range(len(str1)):
		if str1[i] == '1':
			k = i
			break
	for i in range(len(str1)):
		if str1[i] == '0':
			j = max(j, i)
	if k == -1 or k > j:
		print(str1)
	else:
		final = str1[0:k] + str1[j:]
		print(final)


def help():
	n = int(input())
	stri = input()
	n1 = stri.find('1')
	n0 = stri.rfind('0')
	if n0 == -1 or n1 == -1 or n1 == n0 + 1:
		print(stri)
		return
	print(stri[:n1] + stri[n0:])
for _ in range(int(input())):
	help()


for _ in range(int(input())):
	n = int(input())
	s = input()
	count0 = count1 = 0
	for i in range(n):
		if s[i] == '0':
			count0 += 1
		else:
			break
	for i in range(n):
		if s[n - i - 1] == '1':
			count1 += 1
		else:
			break
	if count0 + count1 == n:
		print(s)
	else:
		s1 = '0' * (count0 + 1) + '1' * count1
		print(s1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	one = -1
	zero = 0
	result = ''
	for i in range(n):
		if s[i] == '1':
			one = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			zero = i
			break
	if one == -1:
		print(s)
	elif one > zero:
		print(s)
	else:
		for i in range(0, one):
			result += s[i]
		for i in range(zero, n):
			result += s[i]
		print(result)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	lz = 0
	to = 0
	for i in range(n):
		if s[i] == '0':
			lz += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			to += 1
		else:
			break
	if lz + to == n:
		print(s)
	else:
		ans = ''
		for i in range(lz):
			ans += '0'
		ans += '0'
		for i in range(to):
			ans += '1'
		print(ans)


def solve(n, s):
	(count_zero, count_one) = (0, 0)
	for i in s:
		if i == '0':
			count_zero += 1
		else:
			break
	for i in range(1, n + 1):
		if s[-i] == '1':
			count_one += 1
		else:
			break
	if count_zero + count_one == n:
		return s
	else:
		return '0' * (count_zero + 1) + '1' * count_one
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	print(solve(n, s))


import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline

def r():
	return int(input())

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

def rl():
	return list(map(int, input().split()))
for _ in range(r()):
	n = r()
	a = input()
	b = [[a[0], 1]]
	for i in range(1, n):
		if a[i] == b[-1][0]:
			b[-1][1] += 1
		else:
			b.append([a[i], 1])
	if len(b) == 1:
		print(a)
	elif len(b) == 2:
		if b[0][0] == '0' and b[1][0] == '1':
			print(a)
		else:
			print(0)
	elif b[-2][0] == '0' and b[-1][0] == '1':
		if b[0][0] == '0':
			print('0' * b[0][1] + '0' + '1' * b[-1][1])
		else:
			print('0' + '1' * b[-1][1])
	elif b[0][0] == '0':
		print('0' * b[0][1] + '0')
	else:
		print('0')


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	string = input()
	f1 = string.find('1')
	l0 = len(string) - 1 - string[::-1].find('0')
	if f1 == -1 or l0 == len(string) or f1 > l0:
		print(string)
	else:
		print(string[:f1] + '0' + string[l0 + 1:])


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	n = int(inp())
	s = list(inp())
	oneStart = -1
	lastZero = -1
	for i in range(n):
		if s[i] == '1' and oneStart == -1:
			oneStart = i
		elif s[i] == '0' and oneStart != -1:
			lastZero = i
	ans = []
	for i in range(n):
		if oneStart <= i < lastZero:
			continue
		elif i == lastZero:
			ans.append(0)
		else:
			ans.append(s[i])
	print(''.join(map(str, ans)))


for _ in range(int(input())):
	n = int(input())
	num = input()
	if list(num) == list(sorted(num)):
		print(num)
	else:
		print('0' * (num.index('1') + 1) + '1' * num[::-1].index('0'))


test = int(input())
for x in range(test):
	n = int(input())
	s = input()
	f1 = -1
	lz = -1
	for i in range(len(s)):
		if s[i] == '1':
			f1 = i
			break
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '0':
			lz = j
			break
	if (f1 == -1 or lz == -1) or lz < f1:
		print(s)
		continue
	written = False
	for j in range(0, len(s)):
		if j < f1 or j > lz:
			print(s[j], end='')
		elif written == False:
			print('0', end='')
			written = True
	print()


t = input()
for _ in range(int(t)):
	n = int(input())
	s = input()
	c = 0
	oz = 0
	zo = 0
	one = 0
	zero = 0
	for i in range(n):
		if s[i] == '0':
			zero += 1
		else:
			one += 1
		if i > 0:
			if s[i] != s[i - 1]:
				c += 1
				if s[i] == '0' and s[i - 1] == '1' and (zo == 0):
					zo = 1
				elif s[i] == '1' and s[i - 1] == '0' and (oz == 0):
					oz = 1
	if one == n or zero == n or n == 1:
		print(s)
	elif c <= 1:
		if oz == 1:
			print(s)
		else:
			print('0')
	else:
		start = -1
		for i in range(0, n - 1):
			if s[i] == '1' and s[i + 1] == '0':
				start = i
				break
		i = n - 1
		while i > start:
			if s[i] == '0':
				end = i
				break
			i -= 1
		ans = '0'
		for i in range(end + 1, n):
			ans += s[i]
		temp = ''
		i = start - 1
		while i >= 0:
			if s[i] == '0':
				temp += '0'
			i -= 1
		ans = temp + ans
		print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if n == 1:
		print(s)
		continue
	zero = -1
	one = -1
	for i in range(n):
		if s[i] == '0':
			zero = i
		if s[i] == '1' and one < 0:
			one = i
	if zero < one or one == -1 or zero == -1:
		print(s)
	else:
		print((one + 1) * '0' + (n - zero - 1) * '1')


for _ in range(int(input())):
	n = int(input())
	s = str(input())
	a1 = ''
	a2 = ''
	flag = 0
	for i in s:
		if flag == 0:
			if i == '0':
				a1 += i
			else:
				a2 += i
				flag = 1
		elif flag == 1:
			if i == '0':
				a2 = ''
			else:
				a2 += i
				flag = 2
		elif flag == 2:
			if i == '0':
				a2 = ''
			else:
				a2 += i
				flag = 1
	ans = a1 + '0' + a2
	if a1 + a2 == s:
		print(a1 + a2)
	else:
		print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	bi = [int(x) for x in list(input())]
	sim = []
	if bi[0] == 1:
		sim = [0]
	count = 0
	prev = None
	for num in bi:
		if prev == num or prev == None:
			count += 1
		else:
			sim.append(count)
			count = 1
		prev = num
	sim.append(count)
	l = len(sim)
	if l > 2:
		sim[0] += 1
		if l % 2 == 0:
			last = sim[-1]
			sim[1] = last
			sim = sim[0:2]
		else:
			sim = sim[0:1]
	ans = []
	for y in range(sim[0]):
		ans.append('0')
	if len(sim) == 2:
		for z in range(sim[1]):
			ans.append('1')
	if len(ans) > 0:
		print(''.join(ans))
	else:
		print(0)


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = ''
	f = list(s)
	f.reverse()
	if s.count('1') == 0 or s.count('1') == n:
		print(s)
	else:
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				ans += '1'
			else:
				break
		if s[-1] == '1':
			last = n - 1
		else:
			last = n
		ind = s.index('1')
		g = '0' * ind
		if last < n:
			if '0' in s[ind:last + 1]:
				print(g + '0' + ans)
			else:
				print(s)
		else:
			print(g + '0')


for _ in range(int(input())):
	n = int(input())
	s = input()
	stack = []
	i = 0
	ans = ''
	idx = -1
	for i in range(n):
		if s[i] == '0':
			ans += '0'
		else:
			idx = i
			break
	temp = ''
	if idx != -1:
		for i in range(n - 1, idx - 1, -1):
			if s[i] == '0':
				ans += '0'
				break
			else:
				temp += '1'
	ans += temp
	print(ans)


t = int(input())
for p in range(0, t):
	n = int(input())
	s = input()
	flag = 0
	(zero, one) = (1, 1)
	for i in range(0, n - 1):
		if s[i] > s[i + 1]:
			flag = 1
			break
	if flag == 0:
		print(s)
		continue
	for i in range(0, len(s)):
		if s[i] == '1':
			one = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			zero = i
			break
	ans = s[:one] + '0' + s[zero + 1:]
	print(ans)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
for _ in range(int(input())):
	q = int(input())
	w = input()
	l = 0
	e = []
	r = []
	k = 0
	t = []
	for i in range(q):
		if w[i] == '0':
			t.append(w[i])
		else:
			w = w[i:]
			break
	if '1' not in w:
		print(w)
	else:
		for i in range(len(w) - 1, -1, -1):
			if w[i] == '1' and k == 0:
				l = 1
				e.append(w[i])
			elif w[i] == '0':
				k = 1
				e.append('0')
				break
		print(''.join(t + e[::-1]))


import sys
import math

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

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	s = list(SI())
	if '0' in s and '1' in s:
		ind = n - s[:][::-1].index('0') - 1
		ind2 = s.index('1')
		if ind2 < ind:
			s = ['0'] * s[:ind2].count('0') + s[ind:]
	print(''.join(s))


t = int(input())
while t:
	t = t - 1
	n = int(input())
	s = list(input())
	z = [s[n - 1]]
	for i in range(n - 2, -1, -1):
		if s[i] == '0':
			z.append('0')
		if s[i] == '1':
			if z[-1] == '1':
				z.append('1')
				continue
			while len(z) >= 2 and z[len(z) - 2] != '1':
				z.pop()
	out = ''
	for i in range(len(z) - 1, -1, -1):
		out += z[i]
	print(out)


for _ in range(int(input())):
	n = int(input())
	s = input()
	first_1 = s.find('1')
	last_0 = s.rfind('0')
	if last_0 < first_1:
		print(s)
	else:
		ans = ''
		ans = s[0:first_1] + s[last_0:]
		print(ans)


def main():
	for t in range(int(input())):
		n = int(input())
		s = input()
		l = s
		ans = ''
		flag = False
		visited = [0 for i in range(n)]
		for i in range(n):
			visited[i] = 1
			if not flag:
				if l[i] == '1':
					flag = True
					ans += '0'
					break
				else:
					ans += '0'
		tmp = ''
		if flag:
			for i in range(n - 1, -1, -1):
				if visited[i]:
					ans = ans[:-1] + '1'
					break
				if l[i] == '1':
					tmp += '1'
				else:
					break
		print(ans + tmp[::-1])
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


for _ in range(int(input())):
	n = int(input())
	s = input().strip()
	if n == 1:
		print(s)
	else:
		ans = []
		prev = s[n - 1]
		ans.append(prev)
		b = n
		for i in range(0, n):
			if s[i] == '1':
				b = i
				break
		for i in range(n - 2, -1, -1):
			if s[i] == '1' and prev == '1':
				ans.append('1')
			elif s[i] == '0' and prev == '0':
				if b > i:
					ans.append('0')
			elif s[i] == '0' and prev == '1':
				ans.append('0')
			prev = ans[len(ans) - 1]
		for i in range(len(ans) - 1, -1, -1):
			print(ans[i], end='')
		print()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	changed = 0
	for i in range(1, n):
		if s[i] < s[i - 1]:
			changed += 1
			break
	if not changed:
		print(s)
	else:
		left = 0
		right = 0
		for i in range(n):
			if s[i] == '1':
				left = i
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				right += 1
			else:
				break
		print((left + 1) * '0' + '1' * right)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = []
	flag = 1
	c = 0
	c1 = 0
	c2 = 0
	for el in s:
		if flag == 1 and el == '0':
			c1 += 1
		elif el == '1':
			flag = 2
			c2 += 1
		elif flag == 2 and el == '0':
			c2 = 0
			c = 1
	print('0' * (c1 + c) + '1' * c2)


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = input()
		first = 0
		while first < n and s[first] == '0':
			first += 1
		last_0 = 0
		for i in range(n):
			if s[i] == '0':
				last_0 = i
		if last_0 == first - 1:
			print(s)
		else:
			for i in range(first):
				print(0, end='')
			for j in range(last_0, n):
				print(s[j], end='')
		print()
main()


for cas in range(int(input())):
	n = int(input())
	s = str(input())
	(a, b, j) = map(int, [-1, -1, 0])
	for i in s:
		if i == '0':
			b = j
		elif a == -1:
			a = j
		j += 1
	if b > a:
		s = s[:a] + s[b:]
	print(s)


t = int(input())
resposta = []
for k in range(t):
	n = int(input())
	s = input()
	n0 = 0
	n1 = 0
	i = 0
	trobat0 = False
	ind0 = -1
	ind1 = -10
	while i < n and trobat0 is False:
		if s[i] == '0':
			n0 += 1
		else:
			trobat0 = True
			ind0 = i
		i += 1
	i = n - 1
	trobat1 = False
	while i > 0 and trobat1 is False:
		if s[i] == '1':
			n1 += 1
		else:
			trobat1 = True
			ind1 = i
		i -= 1
	if ind0 == ind1 + 1 or trobat1 is False or trobat0 is False:
		cadena = s
	else:
		cadena = s[0:n0] + '0' + s[n - n1:n]
	resposta.append(cadena)
for i in range(t):
	print(resposta[i])


t = int(input())
for you in range(t):
	n = int(input())
	s = input()
	first1 = n + 2
	for i in range(n):
		if s[i] == '1':
			first1 = i
			break
	last0 = -1
	for i in range(n):
		if s[i] == '0':
			last0 = i
	l = []
	done = 0
	for i in range(n):
		if i >= first1 and i <= last0:
			if done:
				continue
			done = 1
			l.append(0)
		else:
			l.append(s[i])
	for i in l:
		print(i, end='')
	print()


t = int(input())
for ty in range(t):
	n = int(input())
	kp = input()
	rt = ''
	bool0 = False
	bool1 = True
	last = -1
	for xy in range(n):
		if bool1 and kp[xy] == '0':
			rt += '0'
		if kp[xy] == '0':
			last = xy
		if kp[xy] == '0' and (not bool1):
			bool0 = True
		if kp[xy] == '1':
			bool1 = False
	if bool0:
		rt += '0'
	rt += '1' * (n - last - 1)
	print(rt)


def solve(n, s):
	stack = []
	for i in range(n - 1, -1, -1):
		if not stack or stack[-1] == s[i] or (stack[-1] == '1' and s[i] == '0'):
			stack.append(s[i])
		elif stack[-1] == '0' and s[i] == '1':
			while stack and stack[-1] == '0':
				stack.pop()
			stack.append('0')
	return ''.join(reversed(stack))
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	print(solve(n, s))


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	a = []
	prev = s[0]
	i = 0
	count = 0
	while i < n:
		if prev == s[i]:
			count += 1
		else:
			a.append((prev, count))
			prev = s[i]
			count = 1
		i += 1
	a.append((prev, count))
	if len(a) == 1:
		print(a[0][0] * a[0][1])
	elif a[0][0] == '0' and a[-1][0] == '0':
		ans = a[0][0] * a[0][1] + '0'
		print(ans)
	elif a[0][0] == '0' and a[-1][0] == '1':
		if len(a) == 2:
			print(a[0][0] * a[0][1] + a[1][0] * a[1][1])
		else:
			print(a[0][0] * a[0][1] + '0' + a[-1][0] * a[-1][1])
	elif a[0][0] == '1' and a[-1][0] == '0':
		print('0')
	elif a[0][0] == '1' and a[-1][0] == '1':
		print('0' + a[-1][0] * a[-1][1])


from sys import stdin, stdout
import math
input = stdin.readline

def print(x='', end='\n'):
	stdout.write(str(x) + end)

def solve():
	n = int(input())
	s = list(input())
	i = n - 1
	end = ''
	while i >= 0 and s[i] == '1':
		i -= 1
		end += '1'
	st = ''
	j = 0
	while j < n and s[j] == '0':
		st += '0'
		j += 1
	if j < i:
		st += '0'
	print(st + end)
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


n = int(input())
for i in range(n):
	n = int(input())
	a = input()
	s = set(a)
	if len(s) != 2:
		print(a)
	else:
		x = a.index('1')
		p = a[::-1]
		y = p.index('0')
		y = n - 1 - y
		r = ''
		if x > y:
			print(a)
		else:
			r = a[:x] + a[y:]
			print(r)


for t in range(int(input())):
	n = int(input())
	a = input()
	if a.count('1') == 0 or a.count('1') == n:
		print(a)
	else:
		b = a.find('1')
		c = a.rfind('0')
		if b > c:
			print(a)
		else:
			r = '0' * b + a[c:]
			print(r)


n = int(input())
for w in range(n):
	x = int(input())
	s = input()
	p = ''
	(c1, c2, flag) = (-1, -1, 0)
	for i in range(x):
		if s[i] == '1' and flag == 0:
			c1 = i
			flag = 1
		elif s[i] == '0':
			c2 = i
	if c2 > c1 and c1 != -1 and (c2 != -1):
		for i in range(c1):
			p = p + '0'
		p = p + '0'
		for j in range(x - c2 - 1):
			p = p + '1'
	else:
		p = s
	print(p)


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

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

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

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

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

def mod():
	return 10 ** 9 + 7
for i in range(INT()):
	n = INT()
	s = input()
	arr = [str(i) for i in s]
	i = 0
	ans = []
	ind = 0
	flag = 0
	for i in range(n):
		if s[i] == '0':
			ans.append('0')
		else:
			ind = i
			flag = 1
			break
	if flag == 0:
		ind = n
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			ans.append('1')
		elif ind != i + 1:
			ans.insert(0, '0')
			break
		else:
			break
	fans = ''
	for i in ans:
		fans += i
	print(fans)


for _ in range(int(input())):
	n = int(input())
	x = input()
	ans = ''
	flag = 0
	if len(x) <= 1:
		print(x)
		continue
	for i in range(1, n):
		if flag == 1:
			break
		if x[i] == '0' and x[i - 1] == '1':
			j = 0
			while x[j] == '0':
				ans += '0'
				j += 1
			ans += '0'
			j = -1
			while x[j] == '1':
				ans += '1'
				j -= 1
			flag = 1
	if flag == 1:
		print(ans)
	else:
		print(x)


for _ in range(int(input())):
	(n, s) = (int(input()), input())
	found_z = False
	i = n - 1
	while i >= 0:
		if s[i] == '0':
			found_z = True
			i -= 1
		elif not found_z:
			i -= 1
		else:
			try:
				if s[i + 1] == '0' and s[i + 2] == '0':
					s = s[:i + 1] + s[i + 2:]
				else:
					s = s[:i] + s[i + 1:]
					i -= 1
			except:
				s = s[:i] + s[i + 1:]
				i -= 1
	print(s)


tc = int(input())
for _ in range(tc):
	n = int(input())
	a = input()
	if a.count('1') == 0 or a.count('1') == n:
		print(a)
	else:
		start = a.find('1')
		end = a.rfind('0')
		if start > end:
			print(a)
		else:
			print(start * '0' + a[end:])


for _ in range(int(input())):
	n = int(input())
	string = input()
	intial0 = 0
	end1 = 0
	for i in range(n):
		if string[i] == '0':
			intial0 += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if string[i] == '1':
			end1 += 1
		else:
			break
	new = ''
	if intial0 + end1 == n:
		print(string)
	else:
		new = '0' * intial0 + '0' + '1' * end1
		print(new)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if '0' in s and '1' in s:
		g = s.rindex('0')
		h = s.index('1')
		if g > h:
			s = list(s)
			s[h:g + 1] = '0'
			print(''.join(s))
		else:
			print(''.join(s))
	else:
		print(s)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if '1' not in s:
		print(s)
		continue
	if '0' not in s:
		print(s)
		continue
	if n == 1:
		print(s)
		continue
	z1 = n - s[::-1].index('0') - 1
	z2 = s.index('1')
	if z1 > z2:
		print(s[:z2] + '0' + s[z1 + 1:])
	else:
		print(s)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	count0 = 0
	count1 = 0
	for j in range(n):
		if s[j] == '1':
			break
		else:
			count0 += 1
	for j in range(n - 1, count0 - 1, -1):
		if s[j] == '0':
			break
		else:
			count1 += 1
	if count1 + count0 < n:
		print('0' * count0 + '0' + '1' * count1)
	else:
		print('0' * count0 + '1' * count1)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

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

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

def val():
	return int(input().rstrip('\n'))

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

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

def make(l):
	l1 = [[l[0], 1]]
	for i in range(1, len(l)):
		if l[i] == l1[-1][0]:
			l1[-1][1] += 1
		else:
			l1.append([l[i], 1])
	return l1[:]
for _ in range(val()):
	n = val()
	s = li3()
	ans = ''
	i = 0
	l = make(s)
	ans = ''
	last = ''
	i = 0
	if l[0][0] == 0:
		ans += str(l[0][0]) * l[i][1]
		l = l[1:]
	if len(l) and l[-1][0] == 1:
		last = str(l[-1][0]) * l[-1][1]
		l = l[:-1]
	if len(l):
		ans += '0'
	print(ans + last)


for i in range(int(input())):
	n = int(input())
	s = input()
	if list(s) == sorted(s):
		print(s)
	else:
		print('0' * (s.index('1') + 1) + '1' * s[::-1].index('0'))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = [i for i in s]
	l = 0
	r = n
	res = ''
	cnt = 0
	for i in a:
		if i == '0':
			res += i
			l += 1
		else:
			break
	tmp = ''
	check = 1
	for i in a[::-1]:
		if i == '1':
			tmp += i
			r -= 1
		else:
			break
	res += tmp[::-1]
	if len(res) == 0:
		if '0' in a[l:r]:
			print('0')
			continue
		print(a[0])
	else:
		if l < r:
			res = '0' + res
		print(res)


import sys
import math
from math import *
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from collections import deque

def main():
	n = int(input())
	s = input()
	ans = ''
	i = n - 1
	while s[i] == '1':
		ans += s[i]
		i -= 1
		if i == -1:
			break
	cnt = 0
	if i != -1:
		ans = '0' + ans
	temp = ''
	for j in range(i):
		if s[j] == '1':
			break
		cnt += 1
	temp = '0' * cnt
	print(temp + ans)
for i in range(int(input())):
	main()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	A = []
	for i in range(n):
		if s[i] == '1':
			A.append(1)
		else:
			A.append(0)
	B = [i for i in A]
	B.sort()
	if B == A:
		for i in range(n):
			print(A[i], end='')
		print()
	else:
		x = 0
		for i in range(n):
			if A[i] == 0:
				x += 1
			else:
				break
		y = 0
		for i in range(n - 1, -1, -1):
			if A[i] == 1:
				y += 1
			else:
				break
		for i in range(x + 1):
			print(0, end='')
		for i in range(y):
			print(1, end='')
		print()


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = ''
	i = 0
	ans1 = ''
	while s[i] == '0':
		ans += s[i]
		i += 1
		if i == n:
			break
	while i < n:
		a = 0
		b = 0
		while s[i] == '1':
			a += 1
			i += 1
			if i == n:
				break
		if i == n:
			break
		while s[i] == '0':
			b += 1
			i += 1
			if i == n:
				break
		if a != 0 and b != 0:
			ans1 += '10'
	if len(ans1) != 0:
		ans += '0'
	i = n - 1
	while s[i] == '1':
		ans += s[i]
		i -= 1
		if i == -1:
			break
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = -1
	r = -1
	c = ''
	d = ''
	for i in range(n):
		if s[i] == '0':
			c += '0'
		else:
			l = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			d += '1'
		else:
			r = i
			break
	if l >= r:
		print(s)
	elif l == -1 or r == -1:
		print(s)
	else:
		print(c + '0' + d)


for _ in range(int(input())):
	a = int(input())
	s = input()
	x = s[::-1]
	z = o = 0
	if len(s) == 1:
		print(s)
	else:
		for i in s:
			if i == '0':
				z += 1
			else:
				break
		for i in x:
			if i == '1':
				o += 1
			else:
				break
		if z + o == a:
			print('0' * z + '1' * o)
		else:
			print('0' * z + '0' + '1' * o)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	c = 0
	d = 0
	flag = 0
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			flag = 1
			break
	if flag == 0:
		print(s)
	else:
		for i in range(len(s)):
			if s[i] == '1':
				break
			else:
				c += 1
		for i in range(len(s) - 1, 0, -1):
			if s[i] == '0':
				break
			else:
				d += 1
		s1 = ''
		s1 += '0' * c
		s1 += '0'
		s1 += '1' * d
		print(s1)


x = int(input())
for t in range(x):
	a = int(input())
	b = input()
	k = b
	lastZero = b.rfind('0')
	firstOne = b.find('1')
	if lastZero < firstOne:
		print(b)
	else:
		k = b.replace(b[firstOne:lastZero + 1], '0')
		print(k)


t = int(input())
for isc in range(t):
	n = int(input())
	s = input()
	(s1, s2) = ('', '')
	for c in s:
		if c == '0':
			s1 += c
		else:
			break
	for c in s[::-1]:
		if c == '1':
			s2 += c
		else:
			break
	if len(s1) + len(s2) != len(s):
		s1 += '0'
	print(s1 + s2)


def ip():
	nos = list(map(int, input().split()))
	return nos
for tc in range(int(input())):
	n = int(input())
	s = input()[::-1]
	i = s.find('01')
	while i != -1:
		if i - 1 >= 0 and s[i - 1] == '0':
			s = s.replace('01', '1', 1)
		else:
			s = s.replace('01', '0', 1)
		n -= 1
		i = s.find('01')
	print(s[::-1])


def solution(s):
	i = -1
	j = -1
	cond1 = True
	for p in range(len(s)):
		if cond1 and s[p] == '1':
			i = p
			cond1 = False
	cond = True
	for p in range(len(s) - 1, -1, -1):
		if cond and s[p] == '0':
			j = p
			cond = False
	if j < i:
		return s
	else:
		new = s[:i] + s[j:]
		return new
for _ in range(int(input())):
	n = int(input())
	s = input()
	print(solution(s))


for i in range(int(input())):
	n = int(input())
	s = input()
	(new_index, old_index, sw) = (1, 1, 0)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			sw = 1
			break
	if sw == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			new_index = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			old_index = i
			break
	st = s[:new_index] + '0' + s[old_index + 1:]
	print(st)


t = int(input())
for i in range(t):
	n = int(input())
	binstr = list(input())
	flag = False
	scndzero = False
	hadzero = False
	startzero = 0
	onecntr = 0
	for j in binstr:
		if flag == False:
			if j == '0':
				startzero += 1
			else:
				flag = True
				onecntr += 1
		elif j == '0':
			onecntr = 0
			if hadzero == False:
				hadzero = True
				startzero += 1
		else:
			onecntr += 1
	print(startzero * '0' + onecntr * '1')


for _ in range(int(input())):
	n = int(input())
	a = input()
	if n == 1:
		print(a)
		continue
	ans = ''
	i1 = 0
	if a[0] == '0':
		while i1 < n and a[i1] == '0':
			ans = ans + '0'
			i1 += 1
	if i1 == n:
		print(ans)
		continue
	i = n - 1
	str1 = ''
	if a[-1] != '0':
		while a[i] != '0' and i > -1:
			str1 = '1' + str1
			i = i - 1
	if i == -1:
		print(ans + str1)
		continue
	if i + 1 == i1:
		ans = ans + str1
	else:
		ans = ans + '0' + str1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	f = 0
	if len(set(s)) == 1:
		print(s)
	else:
		left = 0
		right = n - 1
		for i in range(n):
			if s[i] == '1':
				left = i
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				right = i
				break
		if right > left:
			print(s[:left] + s[right:])
		else:
			print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	flag = 0
	arr = []
	for i in range(n):
		k = s[i]
		arr.append(k)
		if flag == 0 and i >= 1:
			if arr[i] == '0' and arr[i - 1] == '1':
				flag = 1
	if flag == 0:
		print(''.join(s))
	else:
		one_index = 0
		zero_index = 0
		for i in range(n):
			if arr[i] == '1':
				one_index = i
				break
		for i in range(n - 1, -1, -1):
			if arr[i] == '0':
				zero_index = i
				break
		ans = ''
		for i in range(one_index):
			ans += arr[i]
		for i in range(zero_index, n):
			ans += arr[i]
		print(ans)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input()
		k = 0 if s[0] == '0' else 1
		cnt = 0
		a = []
		for (i, v) in enumerate(s):
			if k == 0:
				if v == '0':
					cnt += 1
				else:
					a.append((cnt, k))
					k = 1
					cnt = 1
			elif v == '1':
				cnt += 1
			else:
				a.append((cnt, k))
				k = 0
				cnt = 1
		a.append((cnt, k))
		if len(a) == 1:
			print('0' * n if k == 0 else '1' * n)
		else:
			startz = a[0][0] if a[0][1] == 0 else 0
			endone = a[-1][0] if a[-1][1] == 1 else 0
			cnt = 0
			a = a[::-1]
			a = a[:len(a) - 1]
			for i in a[::-1]:
				if i[1] == 0:
					cnt = 1
					break
			print('0' * (startz + cnt) + '1' * endone)
	return
main()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	co = 0
	for i in range(n):
		if s[i] == '1':
			break
		print('0', end='')
		co += 1
	ind = n
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			break
		ind = i
	if co - 1 < ind - 1:
		print('0', end='')
	for i in range(ind, n):
		print('1', end='')
	print()


from collections import *
import sys
input = sys.stdin.readline
from math import *
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = input().rstrip('\n')
	if a.count('1') == n or a.count('0') == n:
		print(a)
		continue
	r = ''
	i = 0
	while a[i] == '0':
		r += '0'
		i += 1
	p = a[i]
	cz = []
	co = 0
	glo = 0
	flag = 0
	while i < n:
		if a[i] == '1':
			glo += 1
			cz.append(co)
			co = 0
			i += 1
			continue
		else:
			flag = 1
			glo = 0
			co += 1
		i += 1
	if co != 0:
		cz.append(co)
	if flag == 0:
		print(r + '1' * glo)
	else:
		if cz[-1] == 1:
			cla = 1
		else:
			cla = 1
		print(r + '0' * cla + '1' * glo)


import math
for i in range(int(input())):
	n = int(input())
	s = input()
	while True:
		ind = s.rfind('10')
		if ind == -1:
			break
		if s[ind + 2:].count('0') > 0:
			s = s[:ind + 1] + s[ind + 2:]
		else:
			s = s[:ind] + s[ind + 1:]
	print(s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	r = list(s)
	flag = 1
	while True:
		f = []
		n = len(r)
		for i in range(0, n - 2):
			if r[i] == '1' and r[i + 1] == '0':
				if r[i + 2] == '0':
					f.append(i + 1)
		if len(f) == 0:
			break
		f.sort(reverse=True)
		for i in f:
			r.pop(i)
	flag = 1
	while flag == 1:
		n = len(r)
		i = n - 1
		while i > 0:
			if r[i] == '0' and r[i - 1] == '1':
				flag = 1
				if i != n - 1 and r[i + 1] == '0':
					r.pop(i)
				else:
					r.pop(i - 1)
				break
			else:
				flag = 0
			i -= 1
		else:
			break
	print(''.join(r))


for _ in range(int(input())):
	dlug = int(input())
	ciag = input()
	(gdzie_0, gdzie_1) = (ciag[::-1].find('0'), ciag.find('1'))
	if gdzie_0 != -1:
		gdzie_0 = dlug - 1 - gdzie_0
	if gdzie_1 > gdzie_0 or dlug == 1 or gdzie_0 == -1 or (gdzie_1 == -1):
		print(ciag)
		continue
	print(ciag[:gdzie_1] + '0' + ciag[gdzie_0 + 1:])


for _ in range(int(input())):
	n = int(input())
	s = input()
	L = ''
	prev = -1
	if n == 1:
		print(s)
		continue
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			prev = i
			break
	for i in range(n):
		if s[i] != '0':
			break
		else:
			L += '0'
	if i != prev + 1 and i != n - 1:
		L += '0'
	for i in range(prev + 1, n):
		L += '1'
	print(L)


for _ in [0] * int(input()):
	n = int(input())
	s = input()
	t = len([i for i in range(n - 1) if s[i] != s[i + 1]])
	if t == 0 or (t == 1 and s[-1] == '1'):
		print(s)
		continue
	if t == 1 and s[-1] == '0':
		print('0')
		continue
	print('0' * (n - len(s.lstrip('0')) + 1) + '1' * (n - len(s.rstrip('1'))))


from sys import stdin, stdout
import math
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	s = stdin.readline().strip()
	(st, end) = (float('inf'), -1)
	for i in range(n):
		if s[i] == '1':
			st = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			end = i
			break
	if st < end:
		print(s[:st] + '0' + s[end + 1:])
	else:
		print(s)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	m = -1
	l = 10000000
	for j in range(len(s)):
		if s[j] == '1':
			m = j
			break
	if m == -1:
		print(s)
		continue
	s1 = m * '0'
	for j in range(len(s) - 1, m, -1):
		if s[j] == '0':
			l = j
			break
	if l == 10000000:
		print(s)
		continue
	s2 = '1' * (len(s) - l - 1)
	print(s1, end='')
	print(0, end='')
	print(s2)


t = int(input())
while t > 0:
	l = int(input())
	s = input()
	j = 0
	k = l - 1
	while j < l:
		if s[j] == '1':
			break
		j += 1
	while k > -1:
		if s[k] == '0':
			break
		k -= 1
	if j == k + 1:
		print(s)
	else:
		for i in range(j + 1):
			print('0', end='')
		for i in range(l - 1, k, -1):
			print('1', end='')
		print()
	t -= 1


from sys import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()
	cn1 = 0
	cn0 = 0
	i = n - 1
	while i >= 0:
		if s[i] == '1' and cn0 == 0:
			cn1 += 1
		elif s[i] == '1' and cn0 != 0:
			cn0 = 1
		if s[i] == '0':
			cn0 += 1
		i -= 1
	ans = '0' * cn0 + '1' * cn1
	stdout.write(ans + '\n')


for _ in range(int(input())):
	n = int(input())
	s = input()
	non_dec = False
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			non_dec = True
			break
	if not non_dec:
		print(s)
	else:
		first_zero = 0
		last_one = n - 1
		while first_zero < n and s[first_zero] == '0':
			first_zero += 1
		while last_one >= 0 and s[last_one] == '1':
			last_one -= 1
		print(s[:first_zero] + '0' + s[last_one + 1:])


for _ in range(int(input())):
	lens = int(input())
	inps = input()
	left = inps.find('1')
	rite = inps.rfind('0')
	if rite < left:
		print(inps)
	else:
		print('0' + inps[:left] + inps[rite + 1:])


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	i = len(s) - 1
	while i >= 0 and s[i] == '1':
		i -= 1
	i += 1
	j = 0
	while j <= len(s) - 1 and s[j] == '0':
		j += 1
	j -= 1
	ans = s[i:]
	ans = s[:j + 1] + '0' * int(i > j + 1) + ans
	print(ans)


from collections import defaultdict, Counter
import copy, math
from copy import deepcopy
for _ in range(int(input())):
	n = int(input())
	s = input()
	sw = 0
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			sw = 1
			break
	if sw == 0:
		print(s)
		continue
	rg = 1
	sw = 1
	for i in range(n):
		if s[i] == '1':
			sw = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			rg = i
			break
	print(s[:sw] + '0' + s[rg + 1:])


def solve():
	n = int(input())
	l = list(input())
	i = 0
	while i < n and l[i] == '0':
		i += 1
	while i < n and l[i] == '1':
		i += 1
	if i == n:
		print(''.join(l))
	else:
		i = 0
		while i < n and l[i] == '1':
			i += 1
		while i < n and l[i] == '0':
			i += 1
		if i == n:
			print('0')
		else:
			i = 0
			res = ''
			while i < n and l[i] == '0':
				res += '0'
				i += 1
			res += '0'
			i = n - 1
			while i >= 0 and l[i] == '1':
				res += '1'
				i -= 1
			print(res)
for _ in range(int(input())):
	solve()


t = int(input())
while t > 0:
	N = int(input())
	s = input()
	ans = ''
	first1 = 0
	for char in s:
		if char == '0':
			ans += char
			first1 += 1
		else:
			break
	s = s[first1:]
	group = 0
	for i in range(len(s) - 1):
		if s[i] == '1' and s[i + 1] == '0':
			group += 1
	if group > 0:
		ans += '0'
	s = s[::-1]
	j = 0
	while j < len(s) and s[j] == '1':
		j += 1
	ans += '1' * j
	print(ans)
	t -= 1


t = int(input())
for k in range(t):
	a = []
	n = int(input())
	s = input()
	j = 0
	c = 0
	i = 0
	x = 0
	f = 0
	while i < n:
		if s[i] == '0':
			print('0', end='')
			j = i + 1
			x = i
			f = 1
			while j < n:
				if s[j] == '0':
					print('0', end='')
				elif s[j] == '1':
					break
				x = j
				j = j + 1
		if s[i] == '1':
			j = i + 1
			while j < n:
				if s[j] == '0':
					c = j
				j = j + 1
			if c == 0 and f == 0:
				x = -1
		i = j
	if c == 0:
		for i in range(x + 1, n):
			print('1', end='')
			x += 1
	else:
		print('0', end='')
		while c + 1 < n:
			print('1', end='')
			c = c + 1
	print()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	c1 = 0
	for j in range(n):
		if s[j] == '0':
			c1 += 1
		else:
			break
	c2 = 0
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			c2 += 1
		else:
			break
	if c1 + c2 == n:
		s_string = s
	else:
		s_string = s[:c1] + '0' + s[n - c2:]
	print(s_string)


input_length = int(input())
while input_length != 0:
	stringlength = int(input())
	stringnow = str(input())
	input_length -= 1
	i = 0
	currentstate = 'init'
	final = ''
	cur1 = 0
	cur0 = 0
	temp = 0
	for i in range(0, len(stringnow)):
		if currentstate == 'init':
			if stringnow[i] == '0':
				final += '0'
			elif stringnow[i] == '1':
				currentstate = 'ones'
				cur1 += 1
		elif currentstate == 'ones':
			if stringnow[i] == '0':
				cur1 = 0
				cur0 = 1
				if temp != cur0:
					final += '0'
				currentstate = 'zeroafterones'
			elif stringnow[i] == '1':
				cur1 += 1
		elif currentstate == 'zeroafterones':
			if stringnow[i] == '1':
				currentstate = 'onesafterzeros'
				cur1 = 1
		elif currentstate == 'onesafterzeros':
			if stringnow[i] == '0':
				currentstate = 'zeroafterones'
				cur1 = 0
				if cur0 != 1:
					final += '0'
			elif stringnow[i] == '1':
				cur1 += 1
	if cur1 != 0:
		for j in range(0, cur1):
			final += '1'
	print(final)


t = int(input())
for i in range(t):
	n = int(input())
	a = str(input())
	c1 = 0
	for k in a:
		if k != '0':
			break
		c1 += 1
	c2 = 0
	for k in range(len(a) - 1, -1, -1):
		if a[k] != '1':
			break
		c2 += 1
	res = ''
	if c1 + c2 < len(a):
		res = '0'
	if c1 > 0:
		res = a[0:c1] + res
	if c2 > 0:
		res = res + a[len(a) - c2:len(a)]
	print(res)


import os, sys
T = int(input())
for t in range(T):
	OUT = ''
	flag = -1
	check0 = 0
	check1 = 0
	cnt0 = 0
	cnt1 = 0
	L = int(input())
	S = str(input())
	for l in range(L):
		if S[l] == '1':
			check1 = 1
		if S[L - l - 1] == '0':
			check0 = 1
		if check1 == 0 and S[l] == '0':
			cnt0 += 1
		if check0 == 0 and S[L - l - 1] == '1':
			cnt1 += 1
	for i in range(cnt0):
		OUT = OUT + '0'
	flag = S.find('10')
	if flag != -1:
		OUT = OUT + '0'
	for j in range(cnt1):
		OUT = OUT + '1'
	print(OUT)


for _ in range(int(input())):
	n = int(input())
	b = input()
	out = ''
	i1 = b.find('1')
	i0 = b.rfind('0')
	if i1 == -1 or i0 == -1 or i1 > i0:
		out = b
	else:
		out = b[:i1] + '0' + b[i0 + 1:]
	print(out)


for i in ' ' * int(input()):
	n = int(input())
	s = input()
	count = 0
	j = 0
	while '10' in s:
		a = s.index('1')
		b = s.rfind('0')
		s = list(s)
		del s[a:b]
		s = ''.join(s)
	print(s)


import math

def reverse(string):
	string = string[::-1]
	return string
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ans = ''
	last = -1
	first = n
	for j in range(n - 1, -1, -1):
		if s[j] == '0':
			last = j
			break
	for j in range(n):
		if s[j] == '1':
			first = j
			break
	if last < first:
		print(s)
	else:
		ans = s[:first] + s[last:]
		print(ans)


nb_cases = int(input())
answer = []
while nb_cases > 0:
	nb_cases -= 1
	n = int(input())
	s = input()
	mot_binaire = []
	for x in range(n):
		mot_binaire.append(int(s[x]))
	nb_zero_debut = 0
	nb_un_fin = 0
	for x in range(n):
		if mot_binaire[x] == 0:
			nb_zero_debut += 1
		else:
			break
	for x in range(n):
		if mot_binaire[n - x - 1] == 1:
			nb_un_fin += 1
		else:
			break
	if nb_zero_debut + nb_un_fin == n:
		answer.append(s)
	else:
		answer.append('0' * nb_zero_debut + '0' + '1' * nb_un_fin)
for x in answer:
	print(x)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	j = n - 1
	while j > 0:
		if s[j] == '0' and s[j - 1] == '1':
			if j + 1 < len(s):
				if s[j + 1] == '0':
					del s[j + 1]
				else:
					del s[j - 1]
			else:
				del s[j - 1]
				j -= 1
		else:
			j -= 1
	for i in s:
		print(i, end='')
	print()


for _ in range(int(input())):
	n = int(input())
	s = input()
	z = s.count('0')
	o = s.count('1')
	s1 = '0' * z + '1' * o
	s2 = '1' * o + '0' * z
	if s1 == s:
		print(s)
	elif s2 == s:
		print('0')
	else:
		p1 = 0
		p2 = n - 1
		for i in range(n):
			if s[i] == '1':
				p1 = i
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				p2 = i
				break
		a1 = '0' * (p1 + 1)
		a2 = '1' * (n - (p2 + 1))
		print(a1 + a2)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		S = input().strip()
		lz = 0
		for i in range(N):
			if S[i] == '0':
				lz += 1
			else:
				break
		ro = 0
		for i in range(N - 1, -1, -1):
			if S[i] == '1':
				ro += 1
			else:
				break
		if N == lz + ro:
			print(S)
		else:
			print('0' * lz + '0' + '1' * ro)
main()


import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

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

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

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def solve():
	pass

def main():
	for _ in range(iin()):
		n = iin()
		s = sin()
		d = deque([])
		i = n - 1
		while i >= 0:
			flag = 1
			while flag:
				if len(d) == 0:
					d.append(s[i])
					flag = 0
				elif s[i] == '1':
					if d[-1] == '0':
						if len(d) > 1:
							if d[-2] == '0':
								d.pop()
							else:
								d.pop()
								d.append('0')
								flag = 0
						else:
							d.pop()
							d.append('0')
							flag = 0
					else:
						d.append('1')
						flag = 0
				else:
					d.append('0')
					flag = 0
			i -= 1
		x = ''
		for j in range(len(d) - 1, -1, -1):
			x += d[j]
		print(x)
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()


t = int(input())
for k in range(t):
	n = int(input())
	s = input()
	c = 1
	for i in range(0, n, 1):
		if s[i] == '0':
			c += 1
		else:
			break
	j = n - 1
	y = 0
	while j >= 0:
		if s[j] == '1':
			y += 1
		else:
			break
		j -= 1
	if c + y == n + 1:
		print(s)
	else:
		r = ''
		r += '0' * c
		r += '1' * y
		print(r)


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	l = []
	for i in range(len(s)):
		l.append(int(s[i]))
	a = l[0]
	count = 1
	b = []
	for c in range(1, n):
		if l[c] == a:
			count += 1
		else:
			b.append(count)
			count = 1
			a = l[c]
	if count > 0:
		b.append(count)
	fin = ''
	if l[0] == 0:
		for i in range(b[0]):
			fin += '0'
	if len(b) > 2 or (len(b) == 2 and l[0] == 1):
		fin += '0'
	if l[n - 1] == 1:
		for i in range(b[-1]):
			fin += '1'
	print(fin)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(tp1, tp2) = (0, 0)
	for j in range(n):
		if s[j] == '1':
			tp1 = j
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			tp2 = i
			break
	if j < i:
		s = s[0:j] + s[i:]
		print(s)
	else:
		print(s)


import sys

def input():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(int(input())):
		n = int(input())
		s = [int(x) for x in input()]
		(h, o) = (0, 0)
		for k in range(n):
			if s[k] == 0:
				h += 1
			else:
				break
		for k in range(n - 1, -1, -1):
			if s[k] == 1:
				o += 1
			else:
				break
		t = []
		for k in range(h, n - o):
			t.append(s[k])
		if h == o == 0:
			print(0)
		elif t.count(1) > 0 and t.count(0) > 0:
			print('0' * h + '0' + '1' * o)
		else:
			print('0' * h + '1' * o)
main()


def main():
	n = int(input())
	s1 = str(input())
	index = -1
	index2 = n + 10
	for i in range(len(s1)):
		if s1[i] == '1':
			index = i
			break
	for i in range(n - 1, -1, -1):
		if s1[i] == '0':
			index2 = i
			break
	if index > index2:
		print(s1)
		return
	if index == -1:
		print(s1)
	elif index2 > n:
		print(s1)
	else:
		res = s1[:index] + s1[index2:]
		print(res)
	return

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


import logging, sys
logging.basicConfig(level=logging.INFO)

def main():
	test = int(sys.stdin.readline())
	while test > 0:
		test -= 1
		n = int(sys.stdin.readline())
		s = sys.stdin.readline()
		i = n - 1
		ans = list()
		while i >= 0:
			if s[i] == '1':
				ans.append('1')
				i -= 1
			else:
				kt = -1
				for k in range(i):
					if s[k] == '1':
						kt = k
						break
				if kt == -1:
					for k in range(i + 1):
						ans.append('0')
				else:
					for k in range(kt + 1):
						ans.append('0')
				break
		ans.reverse()
		print(*ans, sep='')
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
main()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	if '0' not in s or '1' not in s:
		print(s)
	else:
		r = s.index('1')
		q = s[::-1].index('0')
		if r + q == n:
			print(s)
		else:
			print(s[:r] + '0' + s[n - q:])


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	for _ in range(ii()):
		n = ii()
		s = si()
		f = -1
		c = 0
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				f = i
				break
			else:
				c += 1
		if f == -1:
			print(s)
		else:
			c1 = 1
			f1 = 0
			for i in range(f + 1):
				if s[i] == '0':
					c1 += 1
				else:
					f1 = 1
					break
			if f1 == 0:
				c1 -= 1
			print('0' * c1 + '1' * c)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


t = int(input())
for zz in range(t):
	n = int(input())
	st = input()
	arr = []
	flag = True
	for i in range(n - 1):
		if st[i] == '1' and st[i + 1] == '0':
			flag = False
	if flag or int(st, 2) == 0:
		print(st)
		continue
	for i in range(n):
		arr.append(st[i])
	i = n - 1
	res = ''
	while i >= 0:
		res = arr[i] + res
		if arr[i] == '0':
			break
		i -= 1
	i = 0
	while i < n and arr[i] == '0':
		res = arr[i] + res
		i += 1
	print(res)


t = int(input())
while t:
	n = int(input())
	s = input()
	firstOne = s.find('1')
	lastZero = s.rfind('0')
	if firstOne > lastZero:
		print(s)
	else:
		print(s[0:firstOne] + s[lastZero:])
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	(l, r) = (1, 1)
	sw = 0
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			sw = 1
			break
	if sw == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			l = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			r = i
			break
	st = s[:l] + '0' + s[r + 1:]
	print(st)


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = str()
	first = False
	i = 0
	while i < n:
		if s[i] == '0':
			x += s[i]
		else:
			j = 1
			check = False
			while i + j < n:
				if s[i + j] == '1' and check:
					break
				if s[i + j] == '0':
					check = True
				j += 1
			if i + j == n and s[n - 1] == '1':
				x += s[i::1]
			if i + j < n and (not first) or (i + j == n and s[n - 1] == '0' and (not first)):
				x += '0'
				first = True
			i = i + j - 1
		i += 1
	print(x)


for lo in range(int(input())):
	n = int(input())
	st = input()
	ans = ''
	ans2 = ''
	j = n - 1
	k = 0
	for i in range(n):
		if st[i] == '0':
			ans += '0'
		else:
			j = i
			break
	for i in range(n - 1, -1, -1):
		if st[i] == '1':
			ans2 += '1'
		else:
			k = i
			break
	if k <= j:
		print(ans + ans2)
	else:
		print(ans + '0' + ans2)


for nt in range(int(input())):
	n = int(input())
	s = input()
	if '1' not in s:
		print(s)
		continue
	ans = ''
	for i in range(n):
		if s[i] == '0':
			ans += s[i]
		else:
			ind = i
			break
	temp = ''
	for i in range(n - 1, ind - 1, -1):
		if s[i] == '0':
			ans += '0'
			break
		else:
			temp += '1'
	ans += temp
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	f1 = -1
	l0 = n
	for i in range(n):
		if s[i] == '1':
			f1 = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			l0 = i
			break
	if f1 == -1 or l0 == n:
		print(s)
	elif f1 > l0:
		print(s)
	else:
		ans = s[0:f1] + '0' + s[l0 + 1:]
		print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	st = input()
	list1 = list(st)
	start = 0
	end = 0
	index1 = len(list1)
	index2 = -1
	for i in range(len(list1)):
		if list1[i] == '0':
			start += 1
		else:
			index1 = i
			break
	for i in range(len(list1) - 1, 0 - 1, -1):
		if list1[i] == '1':
			end += 1
		else:
			index2 = i
			break
	if index2 + 1 == index1:
		for _ in range(start):
			print('0', end='')
		for _ in range(end):
			print('1', end='')
		print()
	else:
		for _ in range(start):
			print('0', end='')
		print('0', end='')
		for _ in range(end):
			print('1', end='')
		print()


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	if '1' in s and '0' in s:
		c_0 = s.index('1')
		s.reverse()
		if c_0 + s.index('0') == n:
			print(''.join(reversed(s)))
		else:
			print(c_0 * '0' + '0' + s.index('0') * '1')
	else:
		print(''.join(s))


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline
mo = 10 ** 9 + 7

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

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

def sin():
	return input()

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

def pref(a, n, f):
	pre = [0] * n
	if f == 0:
		pre[0] = a[0]
		for i in range(1, n):
			pre[i] = a[i] + pre[i - 1]
	else:
		pre[-1] = a[-1]
		for i in range(n - 2, -1, -1):
			pre[i] = pre[i + 1] + a[i]
	return pre

def dfs(node, ans):
	vi[node] = 1
	ans += [node + 1]
	for j in adj[node]:
		if vi[j] == 0:
			dfs(j, ans)
	return ans
for i in range(inin()):
	n = inin()
	s = sin().strip()
	l = list(s)
	f = ''.join(l[::-1])
	ans = ''
	ans2 = ''
	for i in s:
		if i == '0':
			ans += i
		else:
			break
	for i in f:
		if i == '1':
			ans2 += i
		else:
			break
	if len(ans) + len(ans2) == n:
		print(s)
	else:
		print(ans + '0' + ans2)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	f = 0
	for i in range(1, n):
		if s[i] < s[i - 1]:
			f = 1
			break
	if f == 0:
		print(s)
	else:
		on = 1
		ze = 1
		for i in range(n):
			if s[i] == '1':
				on = i
				break
		for i in range(n - 1, 0, -1):
			if s[i] == '0':
				ze = i
				break
		ans = s[:on] + '0' + s[ze + 1:]
		print(ans)


def main():
	t = int(input())
	for case in range(t):
		n = int(input())
		s = list(input())
		i = len(s) - 2
		while i > -1:
			if s[i] == '1' and s[i + 1] == '0':
				if i + 2 < len(s) and s[i + 2] == '0':
					s.pop(i + 1)
				else:
					s.pop(i)
					i -= 1
			else:
				i -= 1
		st = ''
		for i in s:
			st += i
		print(st)
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	if s.count('1') == 0 or s.count('0') == 0:
		print(s)
	else:
		r = s[::-1]
		arr = [False for i in range(n)]
		for i in range(n):
			if r[i] == '1':
				arr[n - 1 - i] = True
			else:
				break
		for i in range(n):
			if s[i] == '0':
				arr[i] = True
			else:
				break
		ans = ''
		for i in range(n):
			if arr[i]:
				ans += s[i]
			elif i == n - 1 or arr[i + 1]:
				ans += '0'
		print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	c = 0
	c2 = 0
	c3 = 0
	for j in range(len(s)):
		if s[0] == '0':
			if s[j] != '1':
				c += 1
			else:
				break
		else:
			break
	for j in range(len(s) - 1, -1, -1):
		if s[n - 1] == '1':
			if s[j] != '0':
				c2 += 1
			else:
				break
		else:
			break
	for j in range(len(s) - 1):
		if s[j] == '1' and s[j + 1] == '0':
			print(c * '0' + 1 * '0' + c2 * '1')
			break
	else:
		print(c * '0' + c2 * '1')


import os
import sys
from io import BytesIO, IOBase
profile = 0
pypy = 1

def iin():
	return int(input())

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

def main():
	T = iin()
	while T:
		T -= 1
		n = iin()
		s = input()
		s = list(s)[::-1]
		ans = []
		ch = 0
		for i in s:
			if i == '0':
				ch += 1
			elif ch:
				ch = 1
			else:
				ans.append('1')
		ans += ['0'] * ch
		ans = ans[::-1]
		print(''.join(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')
if pypy:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
if profile:
	import cProfile
	cProfile.run('main()')
else:
	main()


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	s = input().strip()
	an = ''
	k = -1
	c = 0
	for i in range(n):
		if k == -1 and s[i] == '1':
			k = i
		c += 1
		if s[i] == '0':
			c = 0
	if k == -1:
		k = n
	if c + k < n:
		k += 1
	an = '0' * k + '1' * c
	print(an)


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

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

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	n = int(input())
	s = list(input().strip())
	start = int(s[0])
	counts = []
	this = 0
	prev = None
	for i in range(n):
		if prev == None:
			prev = s[i]
			this += 1
		else:
			if prev == s[i]:
				this += 1
			else:
				counts.append(this)
				this = 1
			prev = s[i]
		if i == n - 1:
			counts.append(this)
	ans1 = []
	ans2 = []
	if start == 0:
		ans1 = ['0'] * counts[0]
		if len(counts) % 2 == 0:
			ans2 = ['1'] * counts[-1]
			if len(counts) > 2:
				ans = ans1 + ['0'] + ans2
			else:
				ans = ans1 + ans2
		elif len(counts) > 1:
			ans = ans1 + ['0'] + ans2
		else:
			ans = ans1 + ans2
	elif len(counts) & 1:
		if len(counts) == 1:
			ans = ['1'] * counts[-1]
		else:
			ans = ['0'] + ['1'] * counts[-1]
	else:
		ans = ['0']
	ans = ''.join(ans)
	print(ans)


from itertools import groupby
from math import sqrt
from math import floor

def solve():
	n = int(input())
	s = input()
	res = ''
	i = 0
	j = n - 1
	while s[i] == '0':
		res += '0'
		i += 1
		if i >= n:
			break
	while s[j] == '1':
		res += '1'
		j -= 1
		if j < 0:
			break
	s = s[i:j + 1]
	if s.__contains__('0'):
		res = '0' + res
	print(res)
for cnt in range(int(input())):
	solve()


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	s = [int(i) for i in input() if i != '\n']
	if n == 1:
		print(s[0])
	else:
		ans = []
		ind = 0
		for i in range(n - 1, -1, -1):
			ans.append(s[i])
			if s[i] == 0:
				ind = i
				break
		for i in range(ind):
			if s[i] == 0:
				ans.append(s[i])
			else:
				break
		ans.reverse()
		ans = ''.join(map(str, ans))
		print(ans)


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input().strip()
	ans = []
	i = 0
	while i < n and s[i] != '1':
		ans.append(s[i])
		i += 1
	ok = False
	for j in range(n - 1, i, -1):
		if s[j] == '0':
			ok = True
			break
	if ok:
		for q in range(j, n):
			ans.append(s[q])
	else:
		for t in range(i, n):
			ans.append(s[t])
	for i in ans:
		print(i, end='')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	for l in range(n):
		if s[l] == '1':
			break
	else:
		print(s)
		continue
	for r in range(n - 1, -1, -1):
		if s[r] == '0':
			break
	else:
		print(s)
		continue
	if l - 1 == r:
		print(s)
	else:
		print(s[:l] + '0' + s[r + 1:])


num = int(input())
for i in range(num):
	l = 0
	r = 0
	n = int(input())
	bin = input()
	if '10' in bin:
		for i in range(n):
			if bin[i] == '1':
				l = i
				break
		for i in range(n - 1, 0, -1):
			if bin[i] == '0':
				r = i
				break
		bin = bin[:l] + '0' + bin[r + 1:]
	print(bin)


t = int(input())
for testcase in range(t):
	n = int(input())
	s = input()
	(lef, rit, s1) = (0, 0, 0)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			s1 = 1
			break
	if s1 == 0:
		print(s)
	else:
		for i in range(n):
			if s[i] == '1':
				lef = i
				break
		for i in range(n - 1, 0, -1):
			if s[i] == '0':
				rit = i
				break
		print(s[:lef] + '0' + s[rit + 1:])


n = int(input())
for i in range(n):
	x = int(input())
	s = input()
	l = list(s)
	if '10' not in s:
		print(s)
	elif l.count('1') == x or l.count('1') == x:
		print(s)
	else:
		c = 0
		for j in range(x - 1):
			if l[j] == '0' and l[j] == '0':
				c += 1
			else:
				break
		l.reverse()
		c1 = 0
		for j in range(x - 1):
			if l[j] == '1' and l[j] == '1':
				c1 += 1
			else:
				break
		print('0' * (c + 1) + '1' * c1)


t = int(input())
while t:
	n = int(input())
	s = input()
	k = s
	r = list(s)
	r.sort()
	if list(s) == r:
		print(s)
	else:
		x = 0
		y = 0
		for i in range(n):
			if k[i] == '1':
				x = i
				break
		for i in range(n - 1, 0, -1):
			if k[i] == '0':
				y = i
				break
		st = k[:x] + '0' + k[y + 1:]
		print(st)
	t = t - 1


import sys
from collections import deque
readline = sys.stdin.readline

def solve():
	N = int(readline())
	S = readline().rstrip()
	q1 = deque(map(int, S))
	q2 = deque()
	i = 0
	while True:
		if len(q1) == 0:
			break
		if len(q2) == 0:
			q2.appendleft(q1.pop())
			continue
		if q2[0] == 0 and q1[-1] == 1:
			if len(q1) >= 2 and q1[-2] == 1:
				q1.pop()
				continue
			if len(q2) >= 2 and q2[1] == 0:
				q2.popleft()
				continue
			q1.pop()
			continue
		else:
			q2.appendleft(q1.pop())
	print(''.join(map(str, q2)))
T = int(readline())
for i in range(T):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	stri = input()
	res = ''
	ss = ''
	for i in range(n):
		if stri[i] == '0':
			res += '0'
		else:
			break
	for i in range(n - 1, -1, -1):
		if stri[i] == '1':
			ss += '1'
		else:
			break
	if len(res) + len(ss) == n:
		print(res + ss)
	else:
		res += '0'
		print(res + ss)


def main():
	t = int(input())
	for i in range(t):
		solve()

def solve():
	n = int(input())
	arr = [int(x) for x in input()]
	if sum(arr) == 0 or sum(arr) == len(arr):
		print(''.join([str(x) for x in arr]))
		return
	final = [arr[0]]
	prev = arr[0]
	for i in range(len(arr)):
		if arr[i] == prev:
			continue
		prev = arr[i]
		final.append(arr[i])
	if len(final) == 2:
		if final[0] == 1:
			print('0')
		else:
			print(''.join([str(x) for x in arr]))
		return
	end_ones = 0
	start_zeroes = 0
	index = len(arr) - 1
	while index >= 0 and arr[index] == 1:
		end_ones += 1
		index -= 1
	index = 0
	while index < len(arr) and arr[index] == 0:
		start_zeroes += 1
		index += 1
	if final[0] == 1:
		print('0', end='')
		print('1' * end_ones)
	else:
		print('0' * start_zeroes, end='')
		if final[len(final) - 1] == 1:
			print('0', end='')
			print('1' * end_ones)
			return
		print('0')
main()


def main():
	for _ in range(int(input())):
		x = int(input())
		a = input()
		ans = ''
		i = 0
		while i < x and a[i] != '1':
			ans += '0'
			i += 1
		l = i - 1
		if i == x:
			print(ans)
		else:
			j = x - 1
			ss = ''
			while j >= 0 and a[j] != '0':
				ss += '1'
				j -= 1
			if j == l:
				ans += ss
			else:
				ans += '0' + ss
			print(ans)
main()


t = int(input())
for i in range(t):
	n = int(input())
	lst = input()
	lst = list(str(lst))
	lst = lst[::-1]
	if lst.count('0') == 0:
		p = ''.join(map(str, lst))
		print(p)
	else:
		k = 0
		for i in range(n):
			if lst[i] == '0':
				k = i
				break
		modified_lst = lst[k + 1:n]
		c = 0
		for i in range(len(modified_lst)):
			if modified_lst[i] == '1':
				c = 0
			else:
				c += 1
		zero = []
		for i in range(c):
			zero.append('0')
		lst1 = lst[0:k + 1]
		lst1 = lst1[::-1]
		m = zero + lst1
		a = ''.join(map(str, m))
		print(a)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	indexofz = -1
	stk = []
	flag1 = -1
	prevflag = -1
	countz = 0
	for i in range(n - 1, -1, -1):
		if indexofz == -1:
			if s[i] == '0':
				if prevflag != '0':
					stk.append('0')
				prevflag = 0
				indexofz = i
			else:
				prevflag = 1
				stk.append(s[i])
		elif s[i] == '0':
			countz += 1
		else:
			countz = 0
	for i in range(countz):
		stk.append('0')
	stk = stk[::-1]
	print(''.join(stk))


for _ in range(int(input())):
	n = int(input())
	l = list(input())
	ln = len(l)
	if ln == 1:
		print(''.join(l))
	elif ln == 2:
		if l[0] == '1' and l[1] == '0':
			print(0)
		else:
			print(''.join(l))
	else:
		for i in range(ln):
			if l[i] == '1':
				break
		a = l[:i]
		b = l[i:]
		lb = len(b)
		i = lb - 1
		for i in range(lb - 1, 0, -1):
			if b[i] == '0':
				b = b[i:]
				break
		k = a + b
		print(''.join(k))


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	on = -1
	zr = -1
	for i in range(n):
		if s[i] == '1':
			on = i
			break
	if on == -1:
		print(''.join(s))
	else:
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				zr = i
				break
		if zr == -1:
			print(''.join(s))
		else:
			if on < zr:
				x = 1
			else:
				x = 0
			print('0' * (on + x) + '1' * (n - zr - 1))


def solve():
	n = int(input())
	arr = list(input())
	length = len(arr)
	index = length - 1
	while index >= 1:
		if arr[index] == '0' and arr[index - 1] == '1':
			if index >= 2 and arr[index - 2] == '1':
				arr.pop(index - 1)
				index -= 1
				continue
			elif index <= len(arr) - 2 and arr[index + 1] == '0':
				arr.pop(index)
				continue
			else:
				arr.pop(index - 1)
				index -= 1
		else:
			index -= 1
	print(''.join(arr))

def main():
	t = int(input())
	while t > 0:
		solve()
		t -= 1
main()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	n = int(input())
	string = [x for x in input()]
	ones = string.count('1')
	zeros = string.count('0')
	if not ones or not zeros:
		print(''.join(string))
	else:
		(ans1, ans2) = ([], [])
		(l, r) = (0, n - 1)
		for x in range(n):
			if string[x] == '0':
				ans1.append('0')
				l += 1
			else:
				break
		for x in range(n - 1, -1, -1):
			if string[x] == '1':
				ans2.append('1')
				r -= 1
			else:
				break
		if l < r:
			ans1 += '0'
		print(''.join(ans1 + ans2))


t = int(input())
for i in range(t):
	ww = int(input())
	s = str(input())
	d = []
	(count, cc, x, xx) = (0, 0, 0, 0)
	ans = ''
	g = []
	(mm, tt) = (0, 0)
	for j in range(len(s)):
		if s[j] == '0':
			count += 1
		else:
			break
	for b in range(len(s)):
		if s[b] == '1':
			g.append(b)
	if len(g) >= 1:
		x += g[0]
		xx += g[-1]
	for f in range(x, xx + 1):
		if s[f] == '0':
			mm += 1
	for l in range(xx, len(s)):
		if s[l] == '0':
			tt += 1
	x = s[::-1]
	for h in range(len(x)):
		if x[h] == '1':
			cc += 1
		else:
			break
	if mm == 0 and tt == 0 or g == [] or len(s) == 1:
		print(s)
	else:
		ans += count * str('0') + str('0') + cc * str('1')
		print(ans)


ans = []
for _ in range(int(input())):
	n = int(input())
	u = list(map(int, list(input())))
	for i in range(n):
		if u[i] == 1:
			i1 = i
			break
	else:
		ans.append(''.join(map(str, u)))
		continue
	for i in range(n - 1, -1, -1):
		if u[i] == 0:
			i2 = i
			break
	else:
		ans.append(''.join(map(str, u)))
		continue
	if i2 < i1:
		ans.append(''.join(map(str, u)))
		continue
	u1 = '0' * i1 + '0' + '1' * (n - i2 - 1)
	ans.append(u1)
print('\n'.join(ans))


for i in range(int(input())):
	n = int(input())
	s = input()
	s = list(s)
	i = len(s) - 2
	while i >= 0:
		if s[i] == '1' and s[i + 1] == '0' and (i + 2 < len(s) and s[i + 2] == '0'):
			s.pop(i + 1)
			i += 1
		elif s[i] == '1' and s[i + 1] == '0':
			s.pop(i)
			i += 1
		i -= 1
	print(''.join(s))


t = int(input())
for k in range(t):
	n = int(input())
	s = input()
	l = 0
	q = 0
	for i in s[::-1]:
		if i == '0':
			break
		else:
			l += 1
	for i in s:
		if i == '0':
			q += 1
		else:
			break
	if l == n:
		print('1' * n)
		continue
	if s[0] == '1' and l != n:
		print('0' + '1' * l)
		continue
	if l == 0 and q == 0:
		print('0')
		continue
	if q + l == n:
		print('0' * q + '1' * l)
		continue
	print('0' * q + '0' + '1' * l)


import string
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	list_s = list(s)
	l = list_s
	if set(l) == {'1'} or set(l) == {'0'}:
		print(s)
	else:
		s_reverse = list_s[:]
		s_reverse.reverse()
		last_0 = s_reverse.index('0')
		last_0 = n - last_0 - 1
		first_1 = list_s.index('1')
		ans = []
		if last_0 + 1 == first_1:
			print(s)
		else:
			first_0 = list_s.index('0')
			last_1 = n - s_reverse.index('1') - 1
			if first_0 == last_1 + 1:
				print(0)
			else:
				ans = []
				s = list_s
				ans = ans + s[:first_1]
				ans = ans + s[last_0:]
				a = ''
				for i in ans:
					a += i
				print(a)


for _ in range(int(input())):
	n = int(input())
	ar = input()
	ls = 0
	gv = []
	sw = 0
	for i in range(1, n):
		if ar[i - 1] != ar[i]:
			gv.append(ar[ls:i])
			ls = i
		if ar[i - 1] > ar[i]:
			sw = 1
	if sw == 0:
		print(ar)
		continue
	gv.append(ar[ls:n])
	if len(gv) == 1:
		print(ar)
	elif '1' in gv[0]:
		if '0' in gv[-1]:
			print('0')
		else:
			print('0' + gv[-1])
	else:
		print(gv[0], end='')
		if '0' in gv[-1]:
			print('0')
		else:
			if len(gv) > 2:
				print('0', end='')
			print(gv[-1])


import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda : readline().rstrip()
IP = lambda : int(readline().rstrip())
MP = lambda : map(int, readline().split())
LS = lambda : list(map(int, readline().split()))

def solve():
	for _ in range(IP()):
		n = IP()
		st = IPS()
		(pos1, pos2) = (-1, -1)
		for i in range(n):
			if st[i] == '1':
				pos1 = i
				break
		for i in range(n - 1, -1, -1):
			if st[i] == '0':
				pos2 = i
				break
		if (pos1 == -1 or pos2 == -1) or pos2 < pos1:
			print(st)
		else:
			ans = st[:pos1] + st[pos2:]
			print(ans)
solve()


def solve(n, binstring):
	(zeroes, ones) = (0, 0)
	while zeroes <= n - 1 and binstring[zeroes] == '0':
		zeroes += 1
	while ones <= n - 1 and binstring[n - ones - 1] == '1':
		ones += 1
	if zeroes + ones == n:
		return '0' * zeroes + '1' * ones
	return '0' * (zeroes + 1) + '1' * ones
t = int(input())
for i in range(t):
	n = int(input())
	binstring = input()
	print(solve(n, binstring))


t_ = int(input())
for t in range(t_):
	length = int(input())
	s = input()
	out = ''
	lst = []
	(L, R) = (-2, -2)
	for i in range(length - 1):
		if s[i] == '1' and s[i + 1] == '0':
			l = i - 1
			r = i + 2
			while l >= 0 and s[l] == '1':
				l -= 1
			while r < length and s[r] == '0':
				r += 1
			if L == -2:
				(L, R) = (l + 1, r - 1)
				lst.append((L, R))
			elif l == R:
				(L, R) = lst.pop(len(lst) - 1)
				R = r - 1
				lst.append((L, R))
			else:
				(L, R) = (l + 1, r - 1)
				lst.append((L, R))
	for (L, R) in lst:
		s = ''.join((s[:L], '0', s[R + 1:]))
	print(s)


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

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

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
entries = inp()
for i in range(entries):
	n = inp()
	s = insr()
	res = []
	one = 0
	zero = 0
	flag = 0
	prev = -1
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			one += 1
		else:
			break
	for j in range(len(s)):
		if s[j] == '0':
			zero += 1
		else:
			break
	for i in range(zero):
		res.append('0')
	if zero + one != len(s):
		res.append('0')
	for j in range(one):
		res.append('1')
	ans = ''
	for x in res:
		ans += x
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = input()
	i = 0
	j = n - 1
	c = 0
	count = 0
	while i < n and l[i] != '1':
		c += 1
		i += 1
	while j >= 0 and l[j] != '0':
		count += 1
		j -= 1
	if c + count != n:
		print('0' * (c + 1) + '1' * count)
	else:
		print('0' * c + '1' * count)


for _ in range(int(input())):
	n = int(input())
	str = input()
	len = n
	ans = ''
	flag = 0
	post = []
	for i in range(n + 20):
		post.append(0)
	postt = []
	for i in range(n + 20):
		postt.append(0)
	if str[0] == '1':
		post[0] = 1
	for i in range(1, len):
		if str[i] == '1':
			post[i] = post[i - 1] + 1
		else:
			post[i] = post[i - 1]
	for i in range(len - 1, -1, -1):
		if str[i] == '0':
			postt[i] = postt[i + 1] + 1
		else:
			postt[i] = postt[i + 1]
	flag = 0
	for i in range(0, len):
		if str[i] == '0' and post[i] == 0:
			ans += '0'
		elif str[i] == '1' and postt[i] == 0:
			ans += '1'
		elif str[i] == '1' and postt[i] != 0:
			if flag == 0:
				ans += '0'
			flag = 1
	print(ans)


from sys import stdin

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

def r_t(tp):
	return map(tp, r().strip().split())

def r_a(tp):
	return list(r_t(tp))

def solve(n, p):
	change = False
	for i in range(n - 1):
		if p[i] == '1' and p[i + 1] == '0':
			change = True
			break
	if not change:
		return p
	A = []
	for c in p:
		A.append(c)
	A.reverse()
	ans = ''
	while A[-1] == '0':
		ans += A.pop()
	A.reverse()
	if A[-1] == '0':
		ans += '0'
	else:
		ones_cnt = 0
		while A[-1] == '1':
			ones_cnt += 1
			A.pop()
		ans += '0' + '1' * ones_cnt
	return ans

def main():
	cases = int(r())
	for case in range(cases):
		n = int(r())
		p = r()
		print(solve(n, p))
main()


for t in range(int(input())):
	n = int(input())
	s = input()
	arr = list(s)
	arr1 = arr.copy()
	arr1.sort()
	arr2 = arr1.copy()
	arr2.reverse()
	if arr1 == arr:
		print(s)
	elif arr2 == arr and set(arr) == {'0', '1'}:
		print(0)
	elif arr1 != arr and arr2 != arr and (set(arr) == {'0', '1'}):
		if s[n - 1] == '0':
			for i in range(len(s)):
				if s[i] == '1':
					break
			ans = '0' * i
			print(ans + '0')
		else:
			for i in range(len(s)):
				if s[i] == '1':
					break
			ans = '0' * i
			count = 0
			for i in range(n - 1, -1, -1):
				if s[i] == '0':
					break
			ans2 = '1' * (n - i - 1)
			print(ans + '0' + ans2)


for _ in range(int(input())):
	n = int(input())
	s = input()
	right_ones = 0
	ind1 = ind2 = -1
	left_zeros = 0
	first_zero = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			right_ones += 1
		else:
			first_zero += 1
			ind2 = i
			break
	for i in range(n):
		if s[i] == '0':
			left_zeros += 1
			ind1 = i
		else:
			break
	if ind1 == ind2:
		print('0' * left_zeros + '1' * right_ones)
	else:
		print('0' * (left_zeros + first_zero) + '1' * right_ones)


t = int(input())
for x in range(t):
	n = int(input())
	s = input()
	if s.count('0') == 0 or s.count('1') == 0:
		print(s)
	else:
		start = s.index('1')
		end = s[::-1].index('0')
		if start + end < len(s):
			start += 1
		print(start * '0' + end * '1')


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		n = II()
		s = SI()
		c0 = s.find('1')
		if c0 == -1:
			c0 = n
		i = s.rfind('0')
		c1 = n if i == -1 else n - i - 1
		if c0 + c1 == n:
			print(s)
		else:
			print('0' * (c0 + 1) + '1' * c1)
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()[:-1]
	(a, b) = ('', '')
	for i in s:
		if i == '0':
			a += '0'
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			b += '1'
		else:
			break
	if len(a) + len(b) == n:
		print(a + b)
	else:
		print(a + '0' + b)


t = int(input())
for qu in range(t):
	n = int(input())
	a = list(input())
	l = 0
	r = 0
	for i in range(n):
		if a[i] == '0':
			l += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if a[i] == '1':
			r += 1
		else:
			break
	if l + r == n:
		print(''.join(a))
	else:
		print('0' * l + '0' + '1' * r)


for _ in range(int(input())):
	n = int(input())
	s = input()
	z = -1
	o = -1
	for i in range(n):
		if s[i] == '1':
			o = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			z = i
			break
	if z == -1 or o == -1:
		print(s)
		continue
	if z < o:
		print(s)
		continue
	ans = s[:o] + '0' + s[z + 1:]
	print(ans)


import sys
input = sys.stdin.readline
for f in range(int(input())):
	n = int(input())
	s = input()
	f1 = n
	l0 = -1
	for i in range(n):
		if s[i] == '0':
			l0 = i
		else:
			f1 = min(f1, i)
	if f1 < l0:
		sol = '0' * f1
		sol += '0'
		sol += '1' * (n - 1 - l0)
		print(sol)
	else:
		print(s)


T = int(input())
while T > 0:
	n = int(input())
	s = input()
	find_zero = False
	res = []
	index = 0
	ones = 0
	while index < n and s[index] == '0':
		res.append('0')
		index += 1
	has = [False] * n
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			has[i] = True
		if i < n - 1:
			has[i] |= has[i + 1]
	while index < n:
		if s[index] == '1':
			if find_zero is True:
				ones = 1
				find_zero = False
				if has[index]:
					ones += 1
				else:
					res.append('0')
			else:
				ones += 1
		else:
			find_zero = True
		index += 1
	if find_zero is True:
		res.append('0')
	else:
		res += ['1'] * ones
	print(''.join(res))
	T -= 1


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	if set(s) == {'1'} or set(s) == {'0'}:
		print(s)
	else:
		for _ in range(n):
			if s[_] == '1':
				ins = _
				break
		for _ in range(n - 1, -1, -1):
			if s[_] == '0':
				inr = _
				break
		if inr > ins:
			x = s.replace(s[ins:inr + 1], '0')
			print(x)
		else:
			print(s)


import math
import sys
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	p = s[0]
	l = []
	for i in range(1, n):
		if s[i] != s[i - 1]:
			l.append(p)
			p = ''
		p += s[i]
	l.append(p)
	ans = ''
	if l[0][0] == '0':
		ans += l[0]
		p = len(l) - 1
		if p == 0:
			lol = 0
		elif p == 1:
			ans += l[-1]
		else:
			ans += '0'
			if p % 2 != 0:
				ans += l[-1]
	else:
		p = len(l)
		if p == 1:
			ans += l[-1]
		else:
			ans += '0'
			if p % 2 != 0:
				ans += l[-1]
	print(ans)


def solve():
	n = int(input())
	S = input().strip()
	i = 0
	j = n - 1
	while i <= j and S[i] == '0':
		i += 1
	while i <= j and S[j] == '1':
		j -= 1
	if i > j:
		return S
	return '0' * i + '0' + '1' * (n - j - 1)
T = int(input())
for _ in range(T):
	print(solve())


for i in range(int(input())):
	k = int(input())
	s = str(input())
	if '10' not in s:
		print(s)
		continue
	for j in range(k):
		if s[j] == '1':
			i1 = j
			break
	for j in range(k):
		if s[k - 1 - j] == '0':
			i0 = k - j - 1
			break
	if i1 > i0:
		print(str(s))
	else:
		print(s[:i1] + '0' + s[i0 + 1:])


for _ in range(int(input())):
	n = int(input())
	string = input()
	if string.count('0') == 0:
		print(string)
		continue
	if string.count('10') == 0:
		print(string)
		continue
	ans = ''
	rz = string.rindex('0')
	if string[:rz].count('10') == 0:
		if string[:rz].count('1') == rz:
			ans = string[rz:]
		else:
			zeros = string[:rz].count('0')
			ans = '0' * zeros
			ans += string[rz:]
	else:
		left1 = string.index('1')
		leftzeros = left1
		ans = '0' * leftzeros + string[rz:]
	print(ans)


MAX = 1000000
t = int(input())
for tt in range(t):
	n = int(input())
	s = input()
	val = False
	cnt = 0
	res = list()
	last0 = -1
	first1 = MAX
	for c in s:
		if val == False and c == '1':
			first1 = cnt
			val = True
		if c == '0':
			last0 = cnt
		cnt += 1
	if last0 < first1:
		print(s)
	else:
		for i in range(n):
			if i < first1:
				res.append(s[i])
			elif i == first1:
				res.append('0')
			elif i > last0:
				res.append(s[i])
		print(''.join(res))


from fractions import Fraction
from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	i = 0
	j = n - 1
	c0 = 0
	c2 = 0
	while i < n:
		if s[i] == '1':
			break
		i += 1
		c0 += 1
	while j >= 0:
		if s[j] == '0':
			break
		j -= 1
		c2 += 1
	c1 = 0
	for k in range(0, n - 1):
		if s[k] == '1' and s[k + 1] == '0':
			c1 += 1
	for k in range(0, c0):
		print('0', end='')
	if c1:
		print('0', end='')
	for k in range(0, c2):
		print('1', end='')
	print()


import sys
input = sys.stdin.readline
tc = int(input())
for _ in range(tc):
	n = int(input())
	string = input().rstrip()
	ans = ''
	for i in range(n - 1):
		if string[i] == '1' and string[i + 1] == '0':
			ans += '0'
			break
		if string[i] != '1':
			ans += '0'
	for i in range(n - 1, 0, -1):
		if string[i] == '0' and string[i - 1] == '1':
			break
		if string[i] != '0':
			ans += '1'
	if '10' in string:
		print(ans)
	else:
		print(string)


def accuratelee():
	n = int(input())
	s = input()
	x = '.'.join(s)
	p = x.split('.')
	y = sorted(p)
	if p == y:
		print(s)
		return
	else:
		(c, d) = (0, 0)
		for i in s:
			if i == '1':
				break
			c = c + 1
		for i in s[::-1]:
			if i == '0':
				break
			d = d + 1
		print('0' * (c + 1) + '1' * d)
		return
for i in range(int(input())):
	accuratelee()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	t1 = 0
	t2 = 0
	f = 0
	ones = 0
	zeros = 0
	for j in range(n):
		if s[j] == '1':
			ones += 1
			if f == 0:
				t1 = j
			f = 1
		else:
			zeros += 1
			t2 = j
	if ones == 0 or zeros == 0:
		print(s)
	elif t2 < t1:
		print(s)
	else:
		print(s[0:t1] + '0' + s[t2 + 1:n])


def solve():
	n = input()
	string = input()
	rle = []
	for i in string:
		if len(rle) == 0:
			rle.append([i, 1])
		elif rle[-1][0] == i:
			rle[-1][1] += 1
		else:
			rle.append([i, 1])
	prefix = ''
	suffix = ''
	main = ''
	if len(rle) == 1:
		print(string)
		return
	if rle[0][0] == '0':
		prefix = '0' * rle[0][1]
		rle = rle[1:]
	if rle[-1][0] == '1':
		suffix = '1' * rle[-1][1]
		rle = rle[:-1]
	if len(rle) == 1:
		main = rle[0][0] * rle[0][1]
	elif len(rle) == 0:
		main = ''
	else:
		main = '0'
	final = prefix + main + suffix
	print(final)
	return

def main():
	t = int(input())
	for _ in range(t):
		solve()
	return
main()


t = int(input())
for i in range(t):
	n = int(input())
	ch = input()
	ch2 = ch[::-1]
	ans = ''
	ans1 = ''
	z = -1
	for i in range(n):
		if ch[i] == '0':
			ans1 = ans1 + ch[i]
		else:
			break
	for i in range(n - 1):
		if ch2[i] == '0' and ch2[i + 1] == '1':
			z = i
			break
	if z == -1:
		ans = ch
	else:
		ans = ch2[0:z + 1]
		ans = ans[::-1]
		k = -1
		for i in range(len(ans) - 1):
			if ans[i] == '0' and ans[i + 1] == '1':
				k = i
				break
		if k == -1:
			ans = '0'
		else:
			ans = ans[k:]
		ans = ans1 + ans
	print(ans)


cases = int(input())
for i in range(cases):
	length = int(input())
	string = list(input())
	temp = []
	c = ''.join(string)
	if '10' not in c:
		print(c)
		continue
	else:
		x_count = 0
		for k in range(len(string)):
			ele = string[k]
			if ele == '0':
				x_count += 1
			elif ele == '1':
				index1 = k
				break
		y_count = 0
		for j in range(len(string) - 1, -1, -1):
			back = string[j]
			if back == '1':
				y_count += 1
			elif back == '0':
				index2 = j
				break
		if index1 < index2:
			x_count += 1
		print(x_count * '0' + y_count * '1')


for _ in range(int(input())):
	n = int(input())
	import sys
	se = input()
	s = list(se)
	ans = []
	if s[0] == '0':
		i = 0
		while i < len(s) and s[i] != '1':
			i += 1
		ans = s[:i]
		if '10' in se:
			ans.append('0')
		j = len(s) - 1
		while j >= 0 and s[j] != '0':
			ans.append('1')
			j -= 1
		print(''.join(ans))
	else:
		if '10' in se:
			ans.append('0')
		j = len(s) - 1
		while j >= 0 and s[j] != '0':
			ans.append('1')
			j -= 1
		print(''.join(ans))


t = int(input())
for i in range(t):
	n = int(input())
	str = input()
	if str.find('10') >= 0:
		be1 = str.find('1')
		af0 = str.rindex('0')
		print(str[0:be1] + str[af0:])
	else:
		print(str)


from sys import stdin

def main():
	for _ in range(int(stdin.readline())):
		stdin.readline()
		string = stdin.readline()
		start = 0
		end = len(string) - 1
		flag1 = False
		flag2 = False
		while start < end:
			if string[start] != '1':
				start += 1
			else:
				flag1 = True
			if string[end] != '0':
				end -= 1
			else:
				flag2 = True
			if flag1 and flag2:
				print(string[:start] + '0' + string[end + 1:].strip())
				break
		if not (flag1 and flag2):
			print(string.strip())
main()


T = int(input())
for i in range(0, T):
	n = int(input())
	S = str(input())
	S_l = list(S)
	k = 0
	while k < n:
		if S[k] == '1':
			tar = k
			last_upd = k
			while tar < n:
				if S[tar] == '0':
					last_upd = tar
				tar += 1
			if last_upd == k:
				k = tar
				break
			else:
				del S_l[k:last_upd + 1]
				S_l.insert(k, '0')
				break
		else:
			k += 1
	X = ''
	X = X.join(S_l)
	print(X)


import sys
input = sys.stdin.readline
t = int(input())

def can(nList):
	if n == 1:
		return False
	for i in range(len(nList) - 1):
		if nList[i] > nList[i + 1]:
			return True
	return False

def acc(nList):
	first_zero = 0
	for i in nList:
		if i == 1:
			break
		else:
			first_zero += 1
	last_one = 0
	for i in nList[::-1]:
		if i == 0:
			break
		else:
			last_one += 1
	ans = first_zero * '0' + '0' + last_one * '1'
	return ans
for _ in range(t):
	n = int(input())
	nList = list(map(int, input().rstrip()))
	if can(nList):
		print(acc(nList))
	else:
		print(''.join(map(str, nList)))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if n == 1:
		print(s)
		continue
	if n == 2:
		if s[0] == '1' and s[1] == '0':
			print('0')
		else:
			print(s)
		continue
	count1 = 0
	count0 = 0
	for i in s:
		if i == '1':
			count1 += 1
		else:
			count0 += 1
	if count1 == n or count0 == n:
		print(s)
		continue
	firstOne = -1
	lastZero = -1
	for i in range(n):
		if s[i] == '1' and firstOne == -1:
			firstOne = i
		elif s[i] == '0':
			lastZero = i
	if firstOne > lastZero:
		print(s)
		continue
	ans = '0' * firstOne + '0' + '1' * (n - 1 - lastZero)
	print(ans)


for i in range(int(input())):
	n = int(input())
	s = input()
	if '10' not in s or '1' not in s:
		print(s)
		continue
	m = s.index('1')
	s = s[::-1]
	k = s.index('0')
	if n > m + k:
		print('0' * m + '0' + '1' * k)
	else:
		print('0' * m + '1' * k)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()[:-1]
	(a, b) = (s.find('1'), s.rfind('0'))
	if a == -1 or b == -1:
		print(s)
		continue
	if a - 1 >= b + 1:
		print('0')
	elif a - 1 == b:
		print(s)
	else:
		print(s[:a] + '0' + s[b + 1:])


def op(s):
	n = len(s)
	res = ''
	l = 0
	r = n - 1
	while l < n and s[l] == '0':
		l += 1
	while r >= 0 and s[r] == '1':
		r -= 1
	if l >= r:
		return s
	num_1 = 0
	num_0 = 0
	return s[:l] + '0' + s[r + 1:]
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	res = op(s)
	print(res)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().rstrip()
	ans = []
	has_one_left = False
	temp = []
	suffix = []
	for ch in s[::-1]:
		if ch == '1':
			suffix.append(ch)
		else:
			break
	prefix = []
	for ch in s:
		if ch == '0':
			prefix.append(ch)
		else:
			break
	if len(prefix) + len(suffix) < n:
		print(''.join([str(item) for item in prefix + ['0'] + suffix]))
	else:
		print(''.join([str(item) for item in prefix + suffix]))


n = int(input())
for k in range(n):
	input()
	s = input()
	count_zero = 0
	count_one = 0
	i = 0
	while i < len(s) and s[i] != '1':
		i += 1
	count_zero = i
	i = len(s) - 1
	while i >= 0 and s[i] != '0':
		i -= 1
	count_one = len(s) - i - 1
	if count_zero + count_one != len(s):
		count_zero += 1
	res = '0' * count_zero + '1' * count_one
	print(res)


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = 0
	y = 0
	a = ''.join(map(str, sorted(s)))
	if s == a:
		print(s)
		continue
	for i in range(n):
		if s[i] == '0':
			x += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			y += 1
		else:
			break
	for j in range(x + 1):
		print('0', end='')
	for j in range(y):
		print('1', end='')
	print()


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	li = stdin.readline()
	c0 = 0
	c1 = 0
	for i in range(0, n):
		if li[i] == '1':
			break
		c0 += 1
	for j in reversed(range(0, n)):
		if li[j] == '0':
			break
		c1 += 1
	if c1 + c0 == n:
		print('0' * c0 + '1' * c1)
	else:
		print('0' * (c0 + 1) + '1' * c1)


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY

def player1():
	print('')

def player2():
	print('')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		zeroes = 0
		ans = []
		r = n - 1
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				r = i
				break
			ans.append('1')
		for i in range(r, -1, -1):
			if s[i] == '0':
				zeroes += 1
				continue
			if zeroes > 1:
				zeroes = 1
		ans += ['0'] * zeroes
		print(''.join(ans[::-1]))
main()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	i = 0
	c0 = 1
	flag = 1
	while flag:
		flag = 0
		c0 = 1
		for i in reversed(range(1, n)):
			if s[i] == '0':
				if s[i - 1] == '0':
					c0 += 1
				elif c0 > 1:
					s = s[:i] + s[i + 1:]
					flag = 1
					n -= 1
					break
				else:
					s = s[:i - 1] + s[i:]
					flag = 1
					n -= 1
					break
	print(s)


cases = int(input())
for _ in range(cases):
	s = int(input())
	st = input()
	A = st
	done = False
	tens = 0
	for i in range(len(st) - 1):
		left = st[i]
		right = st[i + 1]
		if left == '1' and right == '0':
			tens += 1
	while not done:
		st = A
		count = 0
		for i in range(len(st) - 1):
			count += 1
			left = st[i]
			right = st[i + 1]
			if left == '1' and right == '0':
				j = i - 1
				while j >= 0 and st[j] == '1':
					j -= 1
				k = i + 2
				while k < len(st) and st[k] == '0':
					k += 1
				if tens > 1:
					A = st[0:j + 1] + st[i] + st[k:len(st)]
					tens -= 1
				else:
					A = st[0:j + 1] + st[i + 1] + st[k:len(st)]
				break
		if count == len(st) - 1:
			print(A)
			break


def answer(n, s):
	f1 = s.find('1')
	if f1 == -1:
		return s
	l0 = s.rfind('0')
	if l0 == -1:
		return s
	if f1 > l0:
		return s
	ans = s[:f1] + '0' + s[l0 + 1:]
	return ans

def main():
	t = int(input())
	while t:
		n = int(input())
		s = input()
		print(answer(n, s))
		t -= 1
	return
main()


def ans(s):
	i = 0
	while i < len(s) and s[i] == '0':
		i += 1
	s = s[i:][::-1]
	k = 0
	while k < len(s) and s[k] == '1':
		k += 1
	s = s[k:][::-1]
	j = s.count('10')
	if j == 0:
		return '0' * i + '1' * k
	return '0' * (i + 1) + '1' * k
	return (i, j, k)
T = int(input())
for _ in range(T):
	input()
	s = input()
	print(ans(s))


for _ in range(int(input())):
	n = int(input())
	st = input()
	pos1 = None
	pos0 = None
	for i in range(n):
		if st[i] == '1':
			pos1 = i
			break
	if pos1 == None:
		print(st)
		continue
	for i in range(n - 1, pos1, -1):
		if st[i] == '0':
			pos0 = i
			break
	if pos0 == None:
		print(st)
		continue
	print(st[:pos1] + '0' + st[pos0 + 1:])


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

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

def si():
	return input()

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

def msi():
	return map(str, input().strip().split(' '))

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

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

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

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

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

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		n = ii()
		s = si()
		x = -1
		flag = -1
		for i in range(n):
			if s[i] != '0':
				x = i - 1
				flag = 1
				break
		y = -1
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				y = i
				break
		if flag == -1:
			print(s)
		else:
			for i in range(x + 1):
				print('0', end='')
			if x != y:
				print('0', end='')
			for i in range(n - y - 1):
				print('1', end='')
			print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


import sys
input = sys.stdin.readline

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

def instr():
	return str(input())

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

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

def invr():
	return map(int, input().split())
from collections import Counter

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		s = insr()
		l = 0
		for (i, c) in enumerate(s):
			if c == '1':
				l = i
				break
			if i == n - 1:
				l = n
		r = 0
		for (i, c) in enumerate(s[::-1]):
			if c == '0':
				r = i
				break
			if i == n - 1:
				r = n
		m = n - (l + r)
		mid = []
		if m > 0:
			mid = ['0']
		if r > 0:
			print(''.join(s[:l] + mid + s[-r:]))
		else:
			print(''.join(s[:l] + mid))
main()


t = int(input())
while t:
	n = int(input())
	s = input()
	count = 0
	count1 = 0
	for i in range(len(s)):
		if s[i] == '0':
			count += 1
		else:
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			count1 += 1
		else:
			break
	if count + count1 != n:
		ans = '0' * count + '0' + '1' * count1
	else:
		ans = s
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	a1 = len(s)
	s = s.lstrip('0')
	a1 -= len(s)
	a2 = len(s)
	s = s.rstrip('1')
	a2 -= len(s)
	try:
		a = [s[0]]
	except:
		a = []
	i = 1
	for (i, x) in enumerate(s[1:]):
		if x != s[i]:
			a += (x,)
		else:
			a[-1] += x
	b = '0' * a1 + '0' * (len(a) > 0) + '1' * a2
	print(b)


from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	s = stdin.readline().strip()
	front = ''
	for i in s:
		if i == '0':
			front += '0'
		else:
			break
	back = ''
	for i in s[::-1]:
		if i == '1':
			back += '1'
		else:
			break
	if '10' in s:
		print(front + '0' + back)
	else:
		print(front + back)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

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

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(input().strip())
	if n == 1 or sorted(a) == a:
		print(''.join(a))
		continue
	i = 0
	while i < n and a[i] == '0':
		i += 1
	j = n - 1
	while j >= 0 and a[j] == '1':
		j -= 1
	print((i + 1) * '0' + (n - j - 1) * '1')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	(zero, one) = (0, 0)
	i = 0
	while i < n and s[i] == '0':
		zero += 1
		i += 1
	i = n - 1
	while i >= 0 and s[i] == '1':
		one += 1
		i -= 1
	lastzero = i
	if zero + one == n:
		print(s)
	else:
		res = '0' * (zero + 1) + '1' * one
		print(res)


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

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

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

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

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

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

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	n = inin()
	s = stin()
	(l, r, flag) = (1, 1, 0)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			flag = 1
			break
	if flag == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			l = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			r = i
			break
	s = s[:l] + '0' + s[r + 1:]
	print(s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	d = list(s)
	c = list(s)
	c.sort()
	if d == c:
		print(s)
		continue
	if d == c[::-1]:
		print('0')
		continue
	ans = ''
	for i in range(n):
		if s[i] == '1':
			d = i
			break
		ans += s[i]
	s = s[d:]
	s = s[::-1]
	a = ''
	flag = 0
	for i in range(len(s)):
		if s[i] == '0':
			flag = 1
			break
		a += s[i]
	if flag == 1:
		ans += '0'
	ans += a
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ch1 = -1
	idd = -1
	first = -1
	for j in range(len(s)):
		i = s[j]
		if i == '1':
			ch1 = 1
			if first == -1:
				first = j
		elif ch1 == 1:
			idd = j
	if idd == -1:
		print(s)
	else:
		for i in range(0, first):
			print(s[i], end='')
		print(0, end='')
		for k in range(idd + 1, len(s)):
			print(s[k], end='')
		print()


t = int(input())
while t:
	t += -1
	n = int(input())
	s = input()
	ind1 = -2
	ind2 = -1
	for i in range(n):
		if s[i] == '1':
			ind1 = i - 1
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			ind2 = i
			break
	if ind1 == -2 or ind2 == -1:
		print(s)
	elif ind1 == ind2:
		print(s)
	else:
		print(s[:ind1 + 1] + s[ind2:])


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

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

def si():
	return input()

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

def msi():
	return map(str, input().strip().split(' '))

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

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

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

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

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

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(arr):
	return collections.Counter(arr)

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

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

def main():
	for _ in range(ii()):
		n = ii()
		a = si()
		count_zero = 0
		count_one = 0
		b = []
		for i in range(n):
			if a[i] == '1':
				break
			else:
				count_zero += 1
		for i in range(n):
			if a[n - i - 1] == '0':
				break
			else:
				count_one += 1
		j1 = [0] * count_zero
		j2 = [1] * count_one
		if n == 1:
			print(a)
		elif a.count('10'):
			for i in range(count_zero):
				b.append('0')
			b.append('0')
			for i in range(count_one):
				b.append('1')
			print(''.join(b))
		else:
			print(a)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


for h in range(int(input())):
	n = int(input())
	s = input()
	fOne = -1
	lZero = -1
	for i in range(n):
		if s[i] == '1' and fOne == -1:
			fOne = i
		if s[i] == '0':
			lZero = i
	ans = []
	if fOne == -1 or lZero == -1 or lZero < fOne:
		print(s)
	else:
		for i in range(fOne):
			ans.append(s[i])
		for i in range(lZero, n):
			ans.append(s[i])
		print(''.join((i for i in ans)))


for _ in range(int(input())):
	n = int(input())
	s = input()
	p1 = s.find('1')
	p2 = s[::-1].find('0')
	ans = ''
	ans += s[0:p1] if 0 <= p1 < n else ''
	ans += '0' if 0 <= p1 < n and 0 <= p2 < n and (p1 <= n - p2 - 1) else ''
	ans += s[n - p2:] if 0 <= p2 < n else ''
	if p1 == -1 or p2 == -1:
		ans = s
	print(ans)


for _ in range(int(input())):
	N = int(input())
	s = input()
	l = 0
	r = 0
	flag = 0
	for i in range(1, N):
		if int(s[i]) < int(s[i - 1]):
			flag = 1
			break
	for i in range(N):
		if s[i] == '0':
			l += 1
		else:
			break
	for j in range(N - 1, -1, -1):
		if s[j] == '1':
			r += 1
		else:
			break
	print(s[:l] + '0' + s[N - r:] if flag == 1 else s)


from collections import deque
from sys import stdin, stdout
import math
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	x = input()
	l = 0
	r = n - 1
	while x[l] == '0' and l + 1 < n:
		l += 1
	while x[r] == '1' and r >= 0 and (r > l):
		r -= 1
	for i in range(l):
		print(x[i], end='')
	for i in range(r, n):
		print(x[i], end='')
	print()


for _ in range(int(input())):
	n = int(input())
	s = input()
	curi = 0
	ans = ''
	f = True
	while curi < n:
		len1 = 0
		len2 = 0
		while curi < n and s[curi] == '1':
			curi += 1
			len1 += 1
		if curi == n:
			ans += s[n - len1:]
		elif len1 == 0:
			ans += s[curi]
			curi += 1
		else:
			while curi < n and s[curi] == '0':
				curi += 1
				len2 += 1
			if f:
				f = False
				ans += '0'
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	(c, d, x, y) = (-1, -1, 0, 0)
	for i in range(n):
		if s[i] == '1' and x == 0:
			(c, x) = (i, 1)
		if s[i] == '0':
			d = i
	if d >= 0 and c >= 0 and (c < d):
		print(s[:c] + s[d:])
	else:
		print(s)


T = int(input())
for t in range(T):
	n = int(input())
	s = list(input())
	i = n - 1
	while i > 0:
		flag = 0
		if s[i] == '0' and s[i - 1] == '1':
			if i + 1 < len(s) and s[i + 1] == '0':
				del s[i]
				flag = 1
			elif i - 2 >= 0 and s[i - 2] == '1':
				del s[i - 1]
				flag = 1
			else:
				del s[i - 1]
				flag = 1
		if flag == 0 or i == len(s):
			i -= 1
	for i in range(len(s)):
		print(s[i], end='')
	print()


t = int(input())
for case in range(t):
	length = int(input())
	string = input()
	first_one = string.find('1')
	if first_one == -1:
		print(string)
	else:
		first_zero_chunk = first_one - 1
		last_zero = length - 1
		while string[last_zero] != '0' and last_zero >= 0:
			last_zero -= 1
		if last_zero == -1:
			print(string)
		elif last_zero == first_zero_chunk:
			print(string)
		else:
			print(string[:first_zero_chunk + 1] + string[last_zero:])


import sys
import math
from collections import defaultdict, deque
import heapq
mod = 998244353
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	s = sys.stdin.readline()[:-1]
	(l, r) = (-1, -1)
	for i in range(n):
		if s[i] == '0':
			l = i
		else:
			l = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			r = i
		else:
			r = i
			break
	if l >= r:
		print(s)
		continue
	ans = s[:l] + '0' + s[r + 1:]
	print(ans)


def char_arr(string, n):
	arr = []
	for i in range(0, n):
		arr.append(string[i])
	return arr

def find_first_one(arr, n):
	for i in range(0, n):
		if arr[i] == '1':
			return i
	return -1

def find_last_zero(arr, n):
	for i in range(n - 1, 0, -1):
		if arr[i] == '0':
			return i
	return -1

def counts(arr, i, j):
	(c0, c1) = 0
	for k in range(i, j + 1):
		if arr[k] == '0':
			c0 += 1
		if arr[k] == '1':
			c1 += 1
	return [c0, c1]
t = int(input())
for some_var in range(0, t):
	n = int(input())
	string = input()
	arr = char_arr(string, n)
	i = find_first_one(arr, n)
	j = find_last_zero(arr, n)
	if n == 1 or i == -1 or j == -1 or (i > j):
		print(string)
	else:
		some_str = ''
		some_str = string[0:i] + '0' + string[j + 1:]
		print(some_str)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(beg, end) = (0, n - 1)
	flag = 0
	for i in range(1, n):
		if s[i - 1] > s[i]:
			flag = 1
			break
	if flag == 0:
		print(s)
	else:
		for i in range(n):
			if s[i] == '1':
				beg = i
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				end = i
				break
		print(s[:beg] + '0' + s[end + 1:])


for _ in range(int(input())):
	n = int(input())
	s = input()
	for i in range(n):
		if s[i] == '1':
			break
	for j in range(len(s) - 1, -1, -1):
		if s[j] == '0':
			break
	if j > i:
		ans = ''
		ans += s[:i]
		ans += s[j:]
	else:
		ans = s
	print(ans)


for i in range(int(input())):
	n = int(input())
	s = input()
	if '10' not in s:
		print(s)
	else:
		a = s.index('1')
		if s[-1] == '0':
			print(s[:a] + '0')
		else:
			x = 2
			while True:
				if s[-x] == '0':
					m = x - 1
					break
				x += 1
			print('0' + s[:a] + '1' * m)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

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

def oint():
	return int(input())
t = oint()
for _ in range(t):
	n = oint()
	s = get_str()
	ans = ''
	one = -1
	zero = -1
	for i in range(n):
		if s[i] == '1':
			one = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			zero = i
			break
	if one != -1 and zero != -1 and (one < zero):
		ans = s[:one] + s[zero:]
		print(ans)
	else:
		print(s)


t = int(input())
for _ in range(0, t):
	n = int(input())
	s = input()
	s = list(s)
	i1 = 0
	i2 = 0
	for i in range(n):
		if s[i] == '0':
			i1 += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			i2 += 1
		else:
			break
	flag = False
	if n > i1 + i2:
		flag = True
	ans = ''
	if flag:
		for i in range(i1 + 1):
			ans += '0'
		for i in range(i2):
			ans += '1'
	else:
		for i in range(i1):
			ans += '0'
		for i in range(i2):
			ans += '1'
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	resl = ''
	for i in range(n):
		if s[i] == '0':
			resl += '0'
		else:
			break
	resr = ''
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			resr += '1'
		else:
			break
	if len(resl) + len(resr) == len(s):
		print(s)
	else:
		print(resl + '0' + resr)


n = int(input())
for i in range(n):
	a = int(input())
	m = input()
	d = 0
	for i in range(a):
		if m[a - i - 1] == '1':
			d = d + 1
		else:
			break
	c = a - len(str(int(m)))
	if d != 0:
		m = m[:a - d]
	m = m[c:]
	if a == c + d:
		print(c * '0' + d * '1')
	else:
		print(c * '0' + '0' + d * '1')


for _ in range(int(input())):
	n = int(input())
	arr = input()
	s = []
	if arr.count('0') == 0 or arr.count('1') == 0:
		print(arr)
		continue
	for i in range(n):
		if arr[i] == '1':
			k = i
			break
	for i in range(n - 1, -1, -1):
		if arr[i] == '0':
			a = i
			break
	if a < k:
		print(arr)
	else:
		ans = ''
		for i in range(k):
			ans += arr[i]
		for i in range(a, n):
			ans += arr[i]
		print(ans)


from itertools import groupby
for _ in range(int(input())):
	n = int(input())
	s = input()
	s1 = ''
	s2 = ''
	for i in range(n):
		if s[i] == '0':
			s1 = s1 + '0'
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			s2 = s2 + '1'
		else:
			break
	if s1 + s2 == s:
		print(s)
	else:
		print(s1 + '0' + s2)


for _ in range(int(input())):
	n = int(input())
	s = [int(i) for i in input()]
	if n == 1:
		print(*s)
	else:
		ind = -1
		while ind >= -n and n > 1:
			if ind == -1:
				if s[ind] == 1:
					ind -= 1
				elif s[ind] == 0:
					if s[ind - 1] == 0:
						ind -= 1
					elif s[ind - 1] == 1:
						s[ind - 1] = 0
						del s[ind]
						n -= 1
			elif ind == -n:
				if s[ind] == 1:
					if s[ind + 1] == 0 and len(s) == 2:
						del s[ind]
						break
					elif s[ind + 1] == 0 and s[ind + 2] == 1:
						del s[ind]
						break
					elif s[ind + 1] == 0 and s[ind + 2] == 0:
						s[ind + 1] = 1
						del s[ind]
						n -= 1
						ind += 1
					elif s[ind + 1] == 1:
						break
				if s[ind] == 0:
					break
			elif s[ind] == 1:
				if s[ind + 1] == 1:
					ind -= 1
				elif s[ind + 1] == 0:
					if ind + 2 != 0:
						if s[ind + 2] == 1:
							del s[ind]
							n -= 1
						if s[ind + 2] == 0:
							del s[ind + 1]
							ind += 1
							n -= 1
					elif ind + 2 == 0:
						del s[ind]
						n -= 1
			elif s[ind] == 0:
				ind -= 1
		for el in s:
			print(el, end='')
		print()


tests = int(input())
for i in range(tests):
	n = int(input())
	line = input()
	zero_pos = -1
	one_pos = -1
	for x in range(n):
		if line[x] == '0':
			zero_pos = x
		if one_pos == -1 and line[x] == '1':
			one_pos = x
	if zero_pos == -1 or one_pos == -1 or zero_pos < one_pos:
		print(line)
	else:
		res_line = line[:one_pos] + line[zero_pos:]
		print(res_line)


t = int(input())
while t:
	n = int(input())
	s = input()
	i = len(s) - 1
	j = 0
	while i > 0:
		if s[i] == '0':
			while j < i:
				if s[j] == '1':
					break
				j += 1
			break
		i -= 1
	print(s[:j] + s[i:])
	t -= 1


for _ in range(int(input())):
	int(input())
	arr = list(map(int, list(input())))
	am = len(arr)
	out = ''
	for i in range(am):
		if arr[i] == 0:
			out += '0'
		else:
			break
	preOut = ''
	for i in range(am - 1, -1, -1):
		if arr[i] == 1:
			preOut += '1'
		else:
			break
	if len(out) + len(preOut) == am:
		print(out + preOut)
	else:
		print(out + '0' + preOut)


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	l = -1
	for (i, x) in enumerate(s):
		if x == '0':
			l = i
		else:
			break
	ans = []
	for i in range(l + 1):
		ans.append(s[i])
	if s[n - 1] == '0':
		if l != n - 1:
			ans.append(s[n - 1])
	else:
		r = n
		for (i, x) in enumerate(s[::-1]):
			if x == '1':
				r = n - i - 1
			else:
				break
		if l != r - 1:
			ans.append(s[r - 1])
		for i in range(r, n):
			ans.append(s[i])
	print(''.join(ans))


n = int(input())
for _ in range(n):
	b = int(input())
	a = input()
	k = 0
	s = ''
	r = ''
	for i in range(len(a)):
		if a[i] == '0' and k == 0:
			s = s + '0'
		elif a[i] == '1':
			k = 1
			r = r + '1'
		elif a[i] == '0' and k == 1:
			r = '0'
	print(s + r)


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = float('inf')
mod = 998244353
for t in range(int(data())):
	n = int(data())
	s = data()
	ans = ''
	d = set()
	k = 0
	ind = -1
	for i in range(n):
		if s[i] == '1':
			ind = i
			break
	if ind == -1:
		out(s)
		continue
	i1 = n - 1
	for i in range(n - 2, -1, -1):
		if s[i] == '0':
			if s[i1] == '0' and ind < i:
				d.add(i1)
			i1 = i
		elif s[i1] == '0':
			d.add(i)
		else:
			i1 = i
	for i in range(n):
		if i not in d:
			ans += s[i]
	out(ans)


for _ in range(int(input())):
	input()
	l = list(input())
	lf = list()
	i = 0
	while l[i] == str(0):
		lf.append(0)
		i += 1
		if i == len(l):
			break
	j = len(l) - 1
	while l[j] == str(1):
		lf.append(1)
		j -= 1
		if j == -1:
			break
	if i <= j:
		lf.insert(i, 0)
	print(*lf, sep='')


for _ in range(int(input())):
	n = int(input())
	x = input()
	a = list(x)
	j = n - 1
	b = []
	b.append(0)
	z = []
	o = []
	for i in range(n):
		if a[i] == '0':
			z.append(a[i])
		else:
			break
	while j >= 0:
		if a[j] == '1':
			o.append(a[j])
		else:
			break
		j = j - 1
	c = z + o
	y = []
	y.extend(z)
	y.extend(b)
	y.extend(o)
	if len(c) != n:
		print(''.join(map(str, y)))
	else:
		print(''.join(map(str, c)))


t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	zero_pos1 = s.rfind('0')
	one_pos1 = s.find('1')
	ans1 = str(s)
	if zero_pos1 != -11 and one_pos1 != -1 and (one_pos1 < zero_pos1):
		ans1 = s[:one_pos1] + s[zero_pos1:]
	print(ans1)


t = int(input())
for _ in range(0, t):
	n = input()
	s = input()
	fz = 0
	lu = 0
	for i in range(0, len(s)):
		if s[i] == '0':
			fz += 1
		else:
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			lu += 1
		else:
			break
	if len(s) - fz - lu != 0:
		fz += 1
	print('0' * fz + '1' * lu)


n = int(input())
for k in range(n):
	m = int(input())
	s = input()
	p1 = 0
	for i in s:
		if i == '0':
			p1 = p1 + 1
		else:
			break
	p2 = 0
	for j in reversed(s):
		if j == '1':
			p2 = p2 + 1
		else:
			break
	if p1 + p2 == m:
		s1 = ''
	else:
		s1 = '0'
	print('0' * p1 + s1 + '1' * p2)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	p = 0
	yaha = 0
	vaha = 0
	if s[0] == '0':
		p = 1
		for i in range(1, len(s)):
			if s[i] == '0':
				p += 1
			else:
				yaha = 1
				break
	q = 0
	if s[-1] == '1':
		j = n - 1
		while j >= 0 and s[j] != '0':
			q += 1
			j -= 1
		if j > 0 and s[j] != 0:
			vaha = 1
	a = ''
	if p > 0 and q > 0:
		for x in range(p):
			a += '0'
		if yaha == 1 and vaha == 1 and (i != j + 1):
			a += '0'
		for x in range(q):
			a += '1'
	else:
		if p > 0 and q == 0:
			for x in range(p):
				a += '0'
			if i < n - 1:
				a += '0'
		if p == 0 and q > 0:
			for x in range(q):
				a += '1'
			if j > -1:
				a = '0' + a
		if p == 0 and q == 0:
			a = '0'
	print(a)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

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

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

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

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

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

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

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

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	n = ii()
	s = input()
	if s[0] == '1' and s[-1] == '0':
		print('0')
	elif s[0] == '1' and s[-1] == '1':
		if '0' in s:
			i = 1
			one = 0
			while i < n + 1 and s[-i] == '1':
				one += 1
				i += 1
			print('0' + '1' * one)
		else:
			print(s)
	elif s[0] == '0' and s[-1] == '1':
		i = 0
		while i < n and s[i] == '0':
			i += 1
		j = n - 1
		one = 0
		while j > 0 and s[j] == '1':
			one += 1
			j -= 1
		if i > j:
			print(s)
		else:
			print('0' * (i + 1) + '1' * one)
	elif '1' in s:
		i = 0
		while i < n and s[i] == '0':
			i += 1
		print('0' * (i + 1))
	else:
		print(s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(le, ri) = (0, 0)
	if s.count('0') == 0 or s.count('1') == 0:
		print(s)
	elif s[s.index('1'):].count('0') == 0:
		print(s)
	else:
		for i in range(n):
			if s[i] == '1':
				le = i
				break
		for i in range(n - 1, 0, -1):
			if s[i] == '0':
				ri = i
				break
		print(s[:le] + '0' + s[ri + 1:])


t = int(input())
p = []
o = []
for i in range(t):
	r = int(input())
	p.append(r)
	r = list(input())
	o.append(r)

def lee(n, arr):
	flag = 0
	one = 0
	zero = 0
	for i in range(n - 1):
		if int(arr[i]) == 1 and int(arr[i + 1]) == 0:
			flag = 1
			break
	if flag:
		for i in range(n):
			if int(arr[i]) == 1:
				one = i
				break
		for i in range(n - 1, -1, -1):
			if int(arr[i]) == 0:
				zero = i
				break
		r = []
		for i in range(one + 1):
			r.append(0)
		for i in range(n - zero - 1):
			r.append(1)
		return r
	else:
		return arr
for i in range(t):
	w = lee(p[i], o[i])
	for j in range(len(w)):
		if j != len(w) - 1:
			print(w[j], end='')
		else:
			print(w[j])


import math
t = int(input())
for helloworld in range(t):
	n = int(input())
	s = list(map(int, list(input())))
	r = ''
	c = 0
	cr = 0
	for i in range(n):
		if s[n - i - 1] == 1:
			c += 1
		else:
			break
	for i in range(n):
		if s[i] == 0:
			cr += 1
		else:
			break
	if cr + c == n:
		for i in range(cr):
			r += '0'
		for i in range(c):
			r += '1'
	else:
		for i in range(cr):
			r += '0'
		r += '0'
		for i in range(c):
			r += '1'
	print(r)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	cz = 0
	for i in s:
		if i == '0':
			cz += 1
		else:
			break
	co = 0
	for i in s[::-1]:
		if i == '1':
			co += 1
		else:
			break
	if co + cz == n:
		ans = '0' * cz + '1' * co
	else:
		ans = '0' * cz + '0' + '1' * co
	print(ans)


import sys
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
for _ in range(I()):
	n = I()
	l = input()
	lz = -1
	ans = []
	i = 0
	while i < n and l[i] == '0':
		ans.append('0')
		i += 1
	t = i - 1
	lz = i - 1
	while i < n:
		if l[i] == '0':
			lz = i
		i += 1
	ans = ''.join(ans)
	if lz != t:
		print(ans + l[lz:])
	elif lz + 1 < n:
		print(ans + l[lz + 1:])
	else:
		print(ans)


def solve(s):
	sg = 0
	n = len(s)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			sg = 1
	if sg == 0:
		return s
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			right = i + 1
			break
	for i in range(0, n):
		if s[i] == '1':
			left = i
			break
	return s[:left] + '0' + s[right:]
for i in range(int(input())):
	n = input()
	s = input()
	print(solve(s))


def accurateLee(n, array):
	array = list(array)
	for x in range(n):
		if array[x] == '1':
			break
	for y in reversed(range(n)):
		if array[y] == '0':
			break
	if y > x:
		ans = array[:x] + ['0'] + array[y + 1:]
	else:
		return array
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	l = input()
	ans = accurateLee(n, l)
	for x in ans:
		print(x, end='')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	flag = True
	lef = 0
	rig = 0
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			flag = False
			break
	if flag == True:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			lef = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			rig = i
			break
	st = s[:lef] + '0' + s[rig + 1:]
	print(st)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = 0
	b = 0
	c = 0
	d = 0
	for i in range(n):
		if s[i] == '0':
			a += 1
		else:
			c = i
			break
	else:
		print(s)
		continue
	for j in range(n):
		if s[n - j - 1] == '1':
			b += 1
		else:
			d = n - j - 1
			break
	if d <= c:
		print(s)
	else:
		for i in range(a + 1):
			print(0, end='')
		for i in range(b):
			print(1, end='')
		print()


def answer(n, s):
	if s == '0' * n or s == '1' * n:
		return s
	last = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			last = i
			break
	first = 0
	for i in range(n):
		if s[i] == '1':
			first = i
			break
	if last > first:
		return s[:first] + s[last:]
	else:
		return s
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	print(answer(n, s))


for i in range(int(input())):
	a = int(input())
	b = input()
	r = 0
	z = ''
	x = ''
	for j in range(a):
		if b[j] == '0':
			z += '0'
		else:
			x = ''
			for k in range(a - 1, j - 1, -1):
				if b[k] == '1':
					x = x + '1'
				else:
					x = '0' + x
					break
			break
	print(z + x)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input()
		count_zeros = 0
		for c in s:
			if c == '0':
				count_zeros += 1
			else:
				break
		count_ones = 0
		met = False
		for i in range(-1, -n - 1, -1):
			if not met and s[i] == '1':
				count_ones += 1
			elif not met:
				met = True
			elif met and s[i] == '1':
				count_zeros += 1
				break
		print('0' * count_zeros + '1' * count_ones)
main()


T = int(input())
for t in range(T):
	n = int(input())
	s = input()
	bi = s.rfind('0')
	if bi == -1:
		print(s)
		continue
	ai = s.find('1')
	if ai == -1:
		print(s)
		continue
	if s.find('10') == -1:
		print(s)
		continue
	b = s[bi:]
	a = s[:ai]
	print(a + b)


def solve():
	n = int(input())
	s = input()
	x = [i for i in s]
	p = sorted(x)
	count = 0
	if x == p:
		count = 1
		print(s)
		return
	(c, d) = (0, 0)
	for i in s:
		if i == '1':
			break
		c += 1
	for i in reversed(range(n)):
		if s[i] == '0':
			break
		d += 1
	if count == 0:
		print('0' * (c + 1) + '1' * d)
for _ in range(int(input())):
	solve()


T = int(input())
for t in range(T):
	n = int(input())
	s = input()
	first_one = -1
	last_zero = -1
	for i in range(n):
		if s[i] == '1':
			first_one = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			last_zero = i
			break
	if min(first_one, last_zero) < 0 or last_zero < first_one:
		print(s)
	else:
		print('0' * (first_one + 1) + '1' * (n - 1 - last_zero))


for _ in range(int(input())):
	n = int(input())
	a = input()
	i = 0
	x = 0
	y = 0
	j = n - 1
	while i < n and a[i] == '0':
		x += 1
		i += 1
	while j >= 0 and a[j] == '1':
		y += 1
		j -= 1
	if j > i:
		x += 1
	for i in range(x):
		print(0, end='')
	for j in range(y):
		print(1, end='')
	print()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
from copy import deepcopy

def gift():
	for _ in range(t):
		n = int(input())
		arry = input()
		startp = None
		for i in range(n - 1):
			if arry[i] == '1' and arry[i + 1] == '0':
				startp = i
				break
		if startp == None:
			yield arry
		else:
			spoint = startp - 1
			while spoint >= 0:
				if arry[spoint] != '1':
					break
				spoint -= 1
			endpoint = n - 1
			while endpoint > startp:
				if arry[endpoint] == '1':
					endpoint -= 1
				else:
					break
			ans = arry[:spoint + 1] + arry[endpoint:]
			yield ans
t = int(input())
ans = gift()
print(*ans, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	bstr = input()
	one = bstr.find('1')
	zero = bstr.rfind('0')
	if one > zero:
		print(bstr)
	else:
		print(bstr[0:one] + bstr[zero:n])


for t in range(int(input())):
	n = int(input())
	s = input().strip()
	if n == 1:
		print(s)
		continue
	(l, r) = (-1, -1)
	for i in range(n):
		if l == -1 and s[i] == '1':
			l = i
		if r == -1 and s[n - i - 1] == '0':
			r = i
	if l == -1 or r == -1:
		print(s)
	elif l + r == n:
		print(s)
	else:
		print('0' * (l + 1) + '1' * r)


for _ in range(int(input())):
	n = int(input())
	s = str(input())
	v = []
	for i in range(len(s) - 1, -1, -1):
		if v and s[i] == '1' and (v[-1] == '0'):
			while len(v) > 1 and v[-2] == '0':
				v.pop()
		else:
			v.append(s[i])
	for i in range(len(v) - 1, -1, -1):
		print(v[i], end='')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	lis = list(map(int, list(input())))
	i = -1
	for a in range(n):
		if lis[a] == 1:
			i = a
			break
	j = -1
	for a in range(n - 1, -1, -1):
		if lis[a] == 0:
			j = a
			break
	if i == -1 or j == -1:
		print(*lis, sep='')
		continue
	else:
		ans = []
		if i != 0:
			ans = ans + lis[:i]
		if i != j + 1:
			ans = ans + [0]
		if j != n - 1:
			ans = ans + lis[j + 1:]
		print(*ans, sep='')
		continue


for _ in range(int(input())):
	n = int(input())
	s = input()
	(l, r, w) = (0, 0, 0)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			w = 1
			break
	if w == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			l = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			r = i
			break
	print(s[:l] + '0' + s[r + 1:])


t = int(input())
for rdj in range(t):
	n = int(input())
	s = input()
	l = list()
	c = 0
	i = 0
	j = n - 1
	p = ''
	q = ''
	if len(s) > 1:
		while s[i] == '0' and i < n - 1:
			p += '0'
			if i == n - 1:
				break
			else:
				i += 1
		while s[j] == '1':
			q += '1'
			if j == 0:
				break
			else:
				j -= 1
		for k in range(i, j + 1):
			if s[k] == '0':
				p += '0'
				break
		p += q
		print(p)
		continue
	else:
		print(s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(l, r, flag) = (1, 1, False)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			flag = True
			break
	if not flag:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			l = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			r = i
			break
	print('{}'.format(s[:l] + '0' + s[r + 1:]))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, sqrt, trunc, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(var, end='\n'):
	sys.stdout.write(var + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	s = data()
	if len(set(s)) == 1:
		out(s)
		continue
	answer = []
	index = 0
	for i in range(n):
		if s[i] == '0':
			answer.append(s[i])
		else:
			index = i
			break
	s = s[index:]
	if '0' not in s:
		out(''.join(answer) + s)
		continue
	temp = len(s) - s[::-1].index('0')
	out(''.join(answer) + '0' + s[temp:])


from __future__ import division, print_function
import math
import os
import sys
from fractions import *
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import *
from collections import *
M = 10 ** 9 + 7
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
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 = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

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 mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

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 binpowmodulus(a, b, m):
	a %= m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def 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 prime(x):
	if x == 1:
		return False
	else:
		for i in range(2, int(math.sqrt(x)) + 1):
			if x % i == 0:
				return False
		else:
			return True

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
res = set()

def solven(p, l, a, b, n):
	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 factorization(n, l):
	c = n
	if prime(n) == True:
		l.append(n)
		return l
	for i in range(2, c):
		if n == 1:
			break
		while n % i == 0:
			l.append(i)
			n = n // i
	return l

def good(b):
	l = []
	i = 0
	while len(b) != 0:
		if b[i] < b[len(b) - 1 - i]:
			l.append(b[i])
			b.remove(b[i])
		else:
			l.append(b[len(b) - 1 - i])
			b.remove(b[len(b) - 1 - i])
	if l == sorted(l):
		return True
	return False

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)
	sub = []
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] < A[i]:
				sub.append(l[k])
		l[i] = 1 + max(sub, default=0)
	return max(l, default=0)

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 main():
	for _ in range(inpu()):
		n = inpu()
		s = inp()
		one = s.find('1')
		zero = s.rfind('0')
		if zero < one:
			print(s)
		else:
			print('0' + s[0:one] + s[zero + 1:])
main()


for i in range(int(input())):
	n = int(input())
	s = input()
	ans = ''
	k = 0
	while k < n and s[k] == '0':
		ans += '0'
		k += 1
	k = n - 1
	while k >= 0 and s[k] == '1':
		ans += '1'
		k -= 1
	if len(ans) < n:
		ans = '0' + ans
	print(ans)


for t in range(int(input())):
	n = int(input())
	s = input()
	s1 = s[::-1]
	i = s1.find('0')
	j = s.find('1')
	flag = 0
	for k in range(n - 1):
		if int(s[k + 1]) < int(s[k]):
			flag = 1
			break
	if flag == 0:
		print(s)
		continue
	s2 = '0' * (j + 1) + '1' * i
	print(s2)


import sys, math, cmath, time
start_time = time.time()

def solve():
	n = inp()
	s = insr()
	i = 0
	j = len(s) - 1
	q = ''
	while i < len(s) and s[i] == '0':
		i = i + 1
	while j >= 0 and s[j] == '1':
		j = j - 1
	if s[i + 1:j + 1] != '':
		q = '0'
	print('0' * i + q + '1' * (len(s) - j - 1))

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

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

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

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

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

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = (q[a[i] - 1], 1)
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = (q[ord(a[i]) - 97], 1)
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


import math as mt
import sys, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	n = I()
	s = input().strip()
	c = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			break
		else:
			c += 1
	d = 0
	for i in range(n):
		if s[i] == '0':
			d += 1
		else:
			break
	flag = 0
	for i in range(d, n):
		if s[i] == '0':
			flag = 1
			break
	print('0' * d + '0' * flag + c * '1')


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	j = n - 1
	ans = ''
	tmp = ''
	while i < n and s[i] == '0':
		i += 1
		ans += '0'
	while j >= 0 and s[j] == '1':
		j -= 1
		tmp += '1'
	if j >= i:
		ans += '0'
	ans += tmp
	print(ans)


def main():
	for case in range(int(input())):
		input()
		s = input().strip()
		leading_0s = 0
		while leading_0s < len(s) and s[leading_0s] == '0':
			leading_0s += 1
		ending_1s = 0
		while ending_1s < len(s) and s[-ending_1s - 1] == '1':
			ending_1s += 1
		if leading_0s + ending_1s >= len(s):
			print(s)
			continue
		print('0' * (leading_0s + 1) + '1' * ending_1s)
main()


from sys import stdin, stdout
import sys
INF = 100000000000.0
import math

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

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

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

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

def op(c):
	return stdout.write(c)
from collections import defaultdict
for _ in range(int(stdin.readline())):
	n = get_int()
	s = get_string()
	s0 = 0
	e1 = 0
	for i in range(n):
		if s[i] == '0':
			s0 += 1
		else:
			break
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			e1 += 1
		else:
			break
	if i < j:
		s0 += 1
	ans = '0' * s0 + '1' * e1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ones = s.count('1')
	zeros = n - ones
	c = []
	prev = s[0]
	t = 0
	for i in range(n):
		if s[i] == prev:
			t += 1
		else:
			prev = s[i]
			c.append(t)
			t = 1
	c.append(t)
	if len(c) == 1:
		print(s)
	elif s[0] == '1':
		if s[-1] == '1':
			print('0' + c[-1] * '1')
		else:
			print('0')
	elif s[-1] == '0':
		print('0' * c[0] + '0')
	elif len(c) > 2:
		print('0' * c[0] + '0' + '1' * c[-1])
	else:
		print('0' * c[0] + '1' * c[-1])


import sys
import math as mt
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	i = 0
	ans = ''
	ans1 = ''
	while i < len(s):
		if s[i] == '1':
			j = i
			p = -1
			ans1 = ''
			while j < len(s):
				ans1 += s[j]
				if s[j] == '0':
					ind1 = j
					p = 1
				j += 1
			i = j
			if p == 1:
				ans += '0'
				for i1 in range(ind1 + 1, len(s)):
					ans += '1'
			else:
				ans += ans1
		else:
			ans += s[i]
			i += 1
	print(ans)


T = int(input())
for _ in range(T):
	N = int(input())
	S = input()
	left_most_1 = float('inf')
	right_most_0 = -1
	for (i, c) in enumerate(S):
		if c == '1':
			left_most_1 = min(i, left_most_1)
		if c == '0':
			right_most_0 = i
	ans = []
	for i in range(N):
		if i <= left_most_1:
			ans.append(S[i])
		elif left_most_1 < i < right_most_0:
			continue
		elif right_most_0 <= i:
			ans.append(S[i])
	ans.append('9')
	ans_ = ''
	for i in range(len(ans) - 1):
		if ans[i] == '1' and ans[i + 1] == '0':
			continue
		else:
			ans_ += ans[i]
	print(ans_)


t = int(input())

def solve():
	n = int(input())
	s = input()
	(left, right) = (0, n - 1)
	while left < n and s[left] == '0':
		left += 1
	while right >= 0 and s[right] == '1':
		right -= 1
	if left - 1 == right:
		return ''.join(s)
	if right == n - 1:
		return s[:left] + '0'
	return s[:left] + '0' + s[right + 1:]
for _ in range(t):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	lis = [int(x) for x in input()]
	flag = 0
	for i in range(n - 1):
		if lis[i] == 1 and lis[i + 1] == 0:
			flag = 1
	if flag == 0:
		lis = [str(x) for x in lis]
		print(''.join(lis))
	else:
		count1 = 0
		count2 = 0
		for i in range(n):
			if lis[i] == 0:
				count1 += 1
			else:
				break
		lis = lis[::-1]
		for i in range(n):
			if lis[i] == 1:
				count2 += 1
			else:
				break
		print('0' * (count1 + 1) + '1' * count2)


t = int(input())
while t:
	n = int(input())
	ip = input()
	s = -1
	e = -1
	for (i, c) in enumerate(ip):
		if c == '1' and s is -1:
			s = i
		if c == '0' and s is not -1 and (i > s):
			e = i
	if s >= 0 and e >= 0 and (e > s):
		print(ip[:s] + '0' + ip[e + 1:])
	else:
		print(ip)
	t -= 1


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	s = input()
	k = 0
	h = 0
	for i in range(len(s)):
		if s[i] == '0':
			k += 1
		else:
			break
	m = s[::-1]
	for i in range(len(m)):
		if m[i] == '1':
			h += 1
		else:
			break
	if k + h == len(s):
		print(s)
	else:
		print(k * '0' + '0' + h * '1')


T = int(input())

def main():
	n = int(input())
	s = input()
	if s.count('0') < 1:
		return s
	if s.count('1') < 1:
		return s
	pointer = s.rfind('0')
	while n > 2:
		if pointer == 0:
			break
		if s[pointer] == '0' and s[pointer - 1] == '1':
			if pointer + 2 <= n:
				if s[pointer - 1:pointer + 2] == '101':
					s = s[:pointer - 1] + s[pointer:]
					n = n - 1
					pointer = pointer - 1
					continue
				else:
					s = s[:pointer] + s[pointer + 1:]
					n = n - 1
					continue
			else:
				s = s[:pointer - 1] + s[pointer:]
				n = n - 1
				pointer = pointer - 1
		else:
			pointer = pointer - 1
	if s == '10':
		return 0
	else:
		return s
for _ in range(T):
	print(main())


import math as ma

def fu(a):
	b = ''
	for i in range(len(a)):
		b += str(a[i])
	print(b)
t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = []
	c = 0
	d = 0
	for i in range(n):
		if a[i] == '1':
			if d != 0:
				b.append([d, 0])
			d = 0
			c += 1
		elif a[i] == '0':
			if c != 0:
				b.append([c, 1])
			c = 0
			d += 1
	if a[-1] == '0':
		b.append([d, 0])
	else:
		b.append([c, 1])
	if b[0][1] == 1:
		if len(b) == 1:
			print(a)
		elif len(b) % 2 != 0:
			c = [0] + [1] * b[-1][0]
			fu(c)
		else:
			print(0)
	elif len(b) == 1:
		print(a)
	elif len(b) % 2 != 0:
		c = [0] * b[0][0] + [0]
		fu(c)
	elif len(b) == 2:
		print(a)
	else:
		c = [0] * b[0][0] + [0] + [1] * b[-1][0]
		fu(c)


from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		n = int(input())
		l = input().strip()
		ind = n - 1
		for i in range(n):
			if l[i] == '1':
				ind = i
				break
		indd = ind
		for j in range(n - 1, ind, -1):
			if l[j] == '0':
				indd = j
				break
		s = l[:ind] + l[indd:]
		print(s)
main()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	pop = s
	ne = ''
	k = 0
	for i in s:
		if i == '0':
			ne += i
			k += 1
		else:
			break
	if k == len(s):
		print(ne)
		continue
	p = 0
	ll = ''
	pop = pop[::-1]
	for i in pop:
		if i == '1':
			ll += '1'
			p += 1
		else:
			break
	print(ne + '0' * min(1, s.count('10')) + ll)


for i in range(int(input())):
	n = int(input())
	st = input()
	zero = 0
	one = 0
	for i in range(n):
		if st[i] == '0':
			zero += 1
		else:
			break
	for i in reversed(range(n)):
		if st[i] == '1':
			one += 1
		else:
			break
	if one + zero == n:
		print('0' * zero + '1' * one)
	else:
		print('0' * zero + '0' + '1' * one)


from sys import stdin
input = stdin.readline
for t in range(int(input())):
	n = int(input())
	s = input().strip()
	i = 0
	b = ''
	while i < n:
		if s[i] == '1':
			break
		b += s[i]
		i += 1
	c = ''
	j = n - 1
	while j >= 0:
		if s[j] == '0':
			break
		c += s[j]
		j -= 1
	if i >= j:
		print(s)
	else:
		print(b + '0' + c)


for _ in range(int(input())):
	lastzero = None
	firstzero = None
	onecame = False
	n = int(input())
	string = input()
	for i in range(n):
		if string[i] == '1':
			onecame = True
		elif string[i] == '0' and onecame is False:
			firstzero = i
		elif i > 0 and string[i] == '0' and (onecame is True):
			lastzero = i
	if firstzero is None:
		newstring = string[lastzero:]
	elif lastzero is None:
		newstring = string
	else:
		newstring = string[0:firstzero + 1] + string[lastzero:]
	print(newstring)


import sys
import math

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

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

def get_string():
	return sys.stdin.readline().strip()
t = int(input())
for _ in range(t):
	n = int(input())
	s = get_string()
	sz = 0
	bo = 0
	for i in range(n):
		if s[i] == '0':
			sz += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			bo += 1
		else:
			break
	if sz + bo == n:
		print(s)
	else:
		print(sz * '0' + '0' + bo * '1')


t = int(input())
for i in range(t):
	f = lambda : map(int, input().split(' '))
	n = int(input())
	s = input()
	(lef, rig, sw) = (1, 1, 0)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			sw = 1
			break
	if sw == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			lef = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			rig = i
			break
	st = s[:lef] + '0' + s[rig + 1:]
	print(st)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	a = s.rfind('0')
	b = s.find('1')
	if b > a:
		print(s)
	else:
		print(s[:b] + s[a:])


for _ in range(int(input())):
	n = int(input())
	s = input()
	s_i = s[::-1]
	flag = 0
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			flag = 1
			break
	if flag == 0:
		print(s)
	else:
		ans = ''
		for i in range(n):
			if s[i] == '1':
				break
			else:
				ans += s[i]
		ans += '0'
		for i in range(n):
			if s_i[i] == '0':
				break
			else:
				ans += s_i[i]
		print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	ans = ''
	while True:
		if s[i] == '0':
			ans += '0'
			i += 1
			if i == n:
				break
		else:
			break
	l = n - i
	j = n - 1
	check = ''
	for i in range(l):
		if s[j - i] == '0' and s[j - i - 1] == '1':
			check = '0' + check
			break
		elif s[j - i] == '1':
			check = s[j - i] + check
	ans = ans + check
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	text = input()
	for i in range(n):
		if text[i] == '1':
			for j in range(n - 1, i, -1):
				if text[j] == '0':
					text = text.replace(text[i:j + 1], '0')
					break
			break
	print(text)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	arr = []
	count = 0
	for i in range(n):
		count += 1
		if i == n - 1 or s[i + 1] != s[i]:
			arr.append([s[i], count])
			count = 0
	ans = ''
	i = len(arr) - 1
	while i >= 0:
		if i > 0 and arr[i][0] == '0':
			if i > 1:
				arr[i - 2][1] += 1
			else:
				ans += '0'
			i -= 1
		else:
			ans += arr[i][0] * arr[i][1]
		i -= 1
	print(ans[::-1])


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

class TreeNode:

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

class AvlTree:

	def __init__(self):
		self._tree = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

class SegmentTree1:

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

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

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

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

	def __len__(self):
		return self._len

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

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

class SegmentTree:

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

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

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

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

	def __len__(self):
		return self._len

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

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

class Factorial:

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

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

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

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

class Combination:

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

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

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

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

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

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

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

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for i in range(int(input())):
	n = int(input())
	s = input()
	if '1' not in s or '0' not in s:
		print(s)
		continue
	e = s.index('1')
	e1 = n - 1 - s[::-1].index('0')
	if e1 < e:
		print(s)
	else:
		s = s[:e] + s[e1:]
		print(s)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	s = input()
	arr = []
	i = 0
	while i < n and s[i] == '0':
		arr.append(s[i])
		i += 1
	trail = ''
	j = n - 1
	while j >= 0 and s[j] == '1':
		trail += s[j]
		j -= 1
	s = s[i:j + 1]
	if '1' in s and '0' in s:
		arr.append('0')
	print(''.join(arr) + trail)


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	c1 = 0
	ar = [i for i in s]
	if ar == sorted(s):
		print(s)
	else:
		for i in s:
			if i == '0':
				c += 1
			else:
				break
		for i in range(n):
			if s[n - i - 1] == '1':
				c1 += 1
			else:
				break
		p = ''
		p += '0' * (c + 1) + '1' * c1
		print(p)


for _ in range(int(input())):
	n = int(input())
	s = input()
	last_zero = -1
	first_one = len(s)
	for i in range(len(s) - 1, -1, -1):
		if s[len(s) - 1 - i] == '1' and first_one == len(s):
			first_one = len(s) - 1 - i
		if s[i] == '0' and last_zero == -1:
			last_zero = i
		if first_one != len(s) and last_zero != -1:
			break
	if last_zero == -1 or first_one == len(s):
		print(s)
	elif first_one > last_zero:
		print(s)
	else:
		print(s[:first_one] + s[last_zero:])


test = int(input())
for _ in range(test):
	n = int(input())
	bits = input()
	left = right = 0
	sw = 0
	for i in range(n - 1):
		if bits[i] > bits[i + 1]:
			sw = 1
			break
	if sw == 0:
		print(bits)
		continue
	for i in range(n):
		if bits[i] == '1':
			left = i
			break
	for j in range(n - 1, 0, -1):
		if bits[j] == '0':
			right = j
			break
	print(bits[:left] + '0' + bits[right + 1:])


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input().rstrip()
		pone = s.find('1')
		pzero = n
		for (i, c) in enumerate(s):
			if c == '0':
				pzero = i
		if pone == -1 or pzero == n:
			print(s)
			continue
		suf = s[pzero + 1:n]
		if pone < pzero:
			suf = s[:pone] + '0' + suf
		else:
			suf = s
		print(suf)
main()


t = int(input())
for i in range(0, t, 1):
	l = int(input())
	s = input()
	s1 = ''
	s2 = ''
	i = 0
	j = l - 1
	while i < l and s[i] == '0':
		s1 = s1 + '0'
		i = i + 1
	while j >= 0 and s[j] == '1':
		s2 = s2 + '1'
		j = j - 1
	if i < j:
		print(s1 + '0' + s2)
	else:
		print(s1 + s2)


t = int(input())
while t != 0:
	n = int(input())
	s = list(input())
	result = s
	lastZero = -1
	firstOne = -1
	subResult = []
	for i in range(n):
		if s[i] == '1':
			firstOne = i
			break
	for i in reversed(range(n)):
		if s[i] == '0':
			lastZero = i
			subResult = s[i:n]
			break
	if lastZero == -1 or lastZero == 0:
		result = s
	elif firstOne != -1 and lastZero != -1 and (lastZero >= firstOne):
		result = s[0:firstOne] + s[lastZero:n]
	strResult = ''
	for i in range(len(result)):
		strResult += result[i]
	print(strResult)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ret = ''
	f = 1
	for j in range(n - 1):
		if s[j] == '1' and s[j + 1] == '0':
			f = 0
			break
	if f:
		print(s)
		continue
	ret = ''
	cnt = 0
	for k in range(n):
		if s[k] == '1':
			ret += '0' * k
			break
	for j in range(k, n - 1):
		if s[j] == '1' and s[j + 1] == '0':
			cnt = 0
		elif s[j] == '1':
			cnt += 1
	if s[-1] == '1':
		cnt += 1
	ret += '0' + '1' * cnt
	print(ret)


t = int(input())
for i in range(0, t):
	n = int(input())
	s = input()
	position = s.rfind('10')
	while position != -1:
		length = len(s)
		if position + 2 < length:
			if s[position + 2] == str(0):
				s = s[0:position + 1] + s[position + 2:length]
				continue
		s = s[0:position] + s[position + 1:length]
		position = s.rfind('10')
	print(s)


t = int(input())
for q in range(t):
	n = int(input())
	ch = input()
	L1 = ch.split('1')
	L2 = ch.split('0')
	s = L1[0]
	nb = 0
	for i in range(1, len(L1)):
		if len(L1[i]) > 0:
			nb += 1
	if nb > 0:
		s += '0'
	s += L2[-1]
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	i_f_o = -1
	i_l_z = -1
	for i in range(n):
		if s[i] == '1':
			i_f_o = i
			break
	for i in reversed(range(i_f_o + 1, n)):
		if s[i] == '0':
			i_l_z = i
			break
	if n == 1:
		print(s)
	elif i_l_z == -1 or i_f_o == -1:
		print(s)
	else:
		ans = s[0:i_f_o] + '0' + s[i_l_z + 1:]
		print(ans)


t = int(input())
for _ in range(0, t):
	n = int(input())
	st = str(input())
	for i in range(n - 1, -1, -1):
		if st[i] == '0':
			break
	for j in range(0, n):
		if st[j] == '1':
			break
	if i > j:
		print(st[:j] + st[i:])
	else:
		print(st)


from itertools import groupby
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = [[x, len(list(y))] for (x, y) in groupby(s)]
	if len(a) == 1:
		print(s)
	elif len(a) == 2:
		if a[0][0] == '0' and a[1][0] == '1':
			print(s)
		else:
			print(0)
	else:
		ans = ''
		n = len(a)
		if a[0][0] == '0':
			ans = ans + '0' * a[0][1]
		if n > 2:
			ans = ans + '0'
		if a[n - 1][0] == '1':
			ans = ans + '1' * a[n - 1][1]
		print(ans)


t = int(input(''))
while t > 0:
	n = int(input(''))
	string = input('')
	beginning = 0
	backward = -1
	start = ''
	end = ''
	middle = ''
	flag1 = 0
	flag2 = 0
	while beginning < n and string[beginning] == '0':
		start += '0'
		beginning += 1
	while backward >= -n and string[backward] == '1':
		end += '1'
		backward -= 1
	if len(start) + len(end) != len(string):
		middle = '0'
	ans = start + middle + end
	print(ans)
	t -= 1


t = int(input())
for i2 in range(t):
	n = int(input())
	l = input()
	k1 = ''
	k2 = ''
	for i in range(n):
		if l[i] == '0':
			k1 += '0'
		else:
			break
	for i in range(n - 1, -1, -1):
		if l[i] == '1':
			k2 += '1'
		else:
			break
	if len(k1) + len(k2) < n:
		k1 += '0'
	print(k1 + k2)


for _ in range(int(input())):
	n = int(input())
	a = input()
	i = -1
	j = -1
	if '1' in a:
		i = a.index('1')
	b = a[::-1]
	if '0' in a:
		j = n - b.index('0') - 1
	if i == -1 or j == -1:
		print(a)
		continue
	t = 0
	c = ''
	for x in range(n):
		if x < i:
			c += a[x]
		elif x < j and t == 0:
			t += 1
			c += '0'
		elif x > j:
			c += a[x]
	print(c)


import sys

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

def idata():
	return [int(x) for x in ii().split()]

def solve():
	n = int(ii())
	s = ii()
	ans = ''
	flag = False
	ans1 = ''
	(l, r) = (-1, n + 1)
	for i in range(n):
		if s[i] == '1':
			l = i
			break
		ans += '0'
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			r = i + 1
			break
		ans1 += '1'
	if l == r or l == -1 or r == n + 1:
		print(ans + ans1)
	else:
		print(ans + '0' + ans1)
	return
for t in range(int(ii())):
	solve()


n = int(input())
for _ in range(n):
	l = int(input())
	s = input()
	i = 0
	notyet = 0
	s1 = ''
	while i < l:
		if s[i] == '0' and notyet == 0:
			s1 += '0'
			i += 1
			if i == l:
				print(s1)
		elif s[i] == '1':
			notyet += 1
			k = 0
			while i < l and s[i] == '1':
				i += 1
				k += 1
			if i == l:
				s1 += '1' * k
				print(s1)
			else:
				j = l - 1
				k = 0
				while j >= 0 and s[j] == '1':
					k += 1
					j -= 1
				s1 += '0' + '1' * k
				print(s1)
				break


count = int(input())
for i in range(count):
	size = int(input())
	s = input()
	one = s.find('1')
	zero = s.rfind('0')
	if one < zero:
		s = s[:one] + s[zero:]
	print(s)


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
(t,) = mp()
for _ in range(t):
	(n,) = mp()
	s = cin()[:-1]
	one = zero = f = -1
	for i in range(n):
		if s[i] == '1' and f == -1:
			one = i
			f = 1
		elif s[i] == '0':
			zero = i
	if zero <= one or zero == -1 or one == -1:
		cout(s + '\n')
	else:
		cout(s[:one] + s[zero:] + '\n')


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	i = 0
	while i < n and s[i] == '0':
		s[i] = '#'
		i += 1
	ans = '0' * i
	i = n - 1
	while i >= 0 and s[i] != '0':
		i -= 1
	if i >= 0 and s[i] == '0':
		ans += '0'
		i -= 1
	i = n - 1
	while i >= 0 and s[i] == '1':
		ans += '1'
		i -= 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	bin_old = input()
	bin = bin_old
	for i in range(n - 2, -1, -1):
		if bin_old[i] == '1' and bin_old[i + 1] == '0':
			first = 0
			last = len(bin)
			for j in range(i + 2, len(bin)):
				if bin[j] == '1':
					last = j
					break
			for j in range(i, -1, -1):
				if bin[j] == '0':
					first = j + 1
					break
			bin = bin[:first] + '0' + bin[last:]
	print(bin)


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

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

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

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

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

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
from math import log, sqrt, factorial, cos, tan, sin, radians, ceil, floor
import bisect
from decimal import *
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		n = ii()
		s = si()
		l = []
		f = 0
		for i in range(n):
			if s[i] == '1':
				l.append(i)
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				l.append(i)
				break
		if len(l) < 2 or l[0] > l[1]:
			print(s)
		else:
			ans = ''
			for i in range(l[0]):
				ans += s[i]
			for i in range(l[1], n):
				ans += s[i]
			print(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')

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


for _ in range(int(input())):
	n = int(input())
	s = str(input())
	(one, zero) = (0, 0)
	r = ''
	t = 0
	for i in range(n - 1, -1, -1):
		if t == 0 and s[i] == '1':
			r = '1' + r
		elif s[i] == '0':
			zero += 1
			t = 1
		elif t == 1 and s[i] == '1':
			zero = 1
	print('0' * zero + r)


for _ in range(int(input())):
	n = int(input())
	s = input().strip()
	ans = []
	i = 0
	while i < n and s[i] == '0':
		ans.append('0')
		i += 1
	t = []
	j = n - 1
	while j >= 0 and s[j] == '1':
		t.append('1')
		j -= 1
	if i <= j:
		ans += ['0']
	ans += t
	print(''.join(ans))


def cleanest_string():
	n = int(input())
	s = str(input()).strip()
	if n == 1:
		print(s)
	else:
		for i in range(n):
			if s[i] != '0':
				break
		for j in range(n - 1, -1, -1):
			if s[j] != '1':
				break
		if i == 0 and j == 0:
			print(n * '1')
		elif j == n - 1 and i == n - 1:
			print(n * '0')
		elif i > j:
			print(i * '0' + (n - j - 1) * '1')
		else:
			print((i + 1) * '0' + (n - j - 1) * '1')
t = int(input())
for _ in range(t):
	cleanest_string()


def leftmostzero(s):
	for i in range(0, len(s)):
		if s[i] == '1':
			return i
	return 0

def rightmostone(s):
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '0':
			return i
	return len(s) - 1
t = int(input())
for i in range(0, t):
	n = int(input())
	s = str(input())
	if n == 1:
		print(s)
	elif list(s) == sorted(s):
		print(s)
	else:
		x = leftmostzero(s)
		y = rightmostone(s)
		u = s[:x] + '0' + s[y + 1:]
		print(u)


a = int(input())
for x in range(a):
	b = int(input())
	c = input()
	p = [-1]
	for y in range(b):
		if c[y] == '0':
			p.append(y)
	n = ''
	if p == [-1]:
		print(c)
	else:
		h = 0
		for y in range(1, len(p)):
			if p[y] - p[y - 1] == 1:
				h += 1
			else:
				break
		if h == len(p) - 1:
			n += '0' * (p[len(p) - 1] + 1)
			n += '1' * (b - (p[len(p) - 1] + 1))
			print(n)
		else:
			if c[0] == '0':
				n += '0' * h
			n += '0'
			n += '1' * (b - p[len(p) - 1] - 1)
			print(n)


t = int(input())
for i in range(t):
	n = int(input())
	s = list(input())
	ans = []
	swt = 0
	for i in range(n):
		if s[i] == '0':
			ans.append('0')
		else:
			first_one = i
			swt = 1
			break
	swt2 = 0
	if swt == 1:
		backans = []
		for i in range(n - first_one):
			if s[n - i - 1] == '1':
				backans.append('1')
			else:
				swt2 = 1
				print(''.join(ans + ['0'] + backans))
				break
		if swt2 == 0:
			print(''.join(s))
	else:
		print(''.join(s))


import math
T = int(input())
for _ in range(T):
	n = int(input())
	S = input()
	for i in range(n + 1):
		if i == n:
			break
		if S[i] == '1':
			break
	for j in range(n - 1, -2, -1):
		if j == -1:
			break
		if S[j] == '0':
			break
	if i < n and j > -1 and (i < j):
		print(S[:i] + S[j:])
	else:
		print(S)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	start = s.find('1')
	end = s[-1::-1].find('0')
	if end >= 0:
		end = n - 1 - end
	if start >= 0 and end >= 0:
		if end > start:
			ans = s[:start] + '0' + s[end + 1:]
			print(ans)
			continue
	print(s)
	t = t - 1


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math

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

def stringListIn():
	return [x for x in stdin.readline().split()]

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

def stringIn():
	return stdin.readline().strip()
t = intIn()
while t > 0:
	t -= 1
	n = intIn()
	s = input()
	ans = ''
	(first, last) = (-1, -1)
	for i in range(n):
		if s[i] == '1':
			if first == -1:
				first = i
		else:
			last = i
	ss = s[first:last + 1]
	if len(ss) == 0:
		print(s)
	else:
		print(s[:first] + '0' + s[last + 1:])


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	news = ''
	zero = s.rfind('0')
	one = s.find('1')
	for i in range(len(s)):
		if s[i] == '0':
			if i < one or one == -1:
				news += s[i]
		if s[i] == '1':
			if i > zero or zero == -1:
				news += s[i]
	if zero > one and zero != one != -1:
		id0 = news.rfind('0')
		if id0 == -1:
			news = '0' + news
		else:
			news = news[:id0 + 1] + '0' + news[id0 + 1:]
	print(news)


import os
from math import *
t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	p1 = -1
	p0 = -1
	for i in range(n):
		if s[i] == '1':
			p1 = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			p0 = i
			break
	if p1 == -1 or p0 == -1:
		print(s)
	elif p1 > p0:
		print(s)
	else:
		print(s[0:p1], end='')
		print('0', end='')
		print(s[p0 + 1:])


import math
for w in range(int(input())):
	n = int(input())
	bi = list(input())
	rep = []
	if '0' not in bi:
		print(''.join(bi))
	for i in range(n - 1, -1, -1):
		if bi[i] == '0':
			if '1' in bi[:i]:
				aux = bi.index('1')
				print(''.join(bi[:aux]) + ''.join(bi[i:]))
				break
			else:
				print(''.join(bi))
				break


from sys import stdin, stdout
q = int(input())
for i in range(q):
	n = int(input())
	a = input()
	flag = 0
	first0 = -1
	first1 = -1
	last0 = -1
	for i in range(len(a)):
		if a[i] == '0':
			if first0 == -1:
				first0 = i
		elif first1 == -1:
			first1 = i
	for i in range(len(a) - 1, -1, -1):
		if a[i] == '0':
			last0 = i
			break
	if last0 != -1:
		if last0 > first1:
			a = a[:first1] + a[last0:]
	elif first0 > first1:
		a = a[:first1] + a[first0:]
	print(a)


for i in range(int(input())):
	n = int(input())
	s = input()
	if all([i == '1' for i in s]) or all([i == '0' for i in s]):
		print(s)
		continue
	(l, r) = (-1, n)
	for i in range(n):
		if s[i] == '1':
			l = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			r = i
			break
	if l > r:
		print(s)
		continue
	print(s[:l] + '0' + s[r + 1:])


import sys

def scanint():
	return int(sys.stdin.readline().rstrip())

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

def scanarr():
	return list(map(int, sys.stdin.readline().rstrip().split()))
from queue import PriorityQueue
import heapq
import math
t = scanint()
for _ in range(t):
	n = scanint()
	s = input()
	prefix0 = 0
	suffix1 = 0
	for i in s:
		if i == '0':
			prefix0 += 1
		else:
			break
	for i in s[::-1]:
		if i == '1':
			suffix1 += 1
		else:
			break
	if prefix0 + suffix1 != len(s):
		prefix0 += 1
	print('0' * prefix0 + '1' * suffix1)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		pop = -1
		temp = ''
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				pos = i
				temp = s[i] + temp
				break
			temp = s[i] + temp
		ok = False
		pos1 = -1
		ans = ''
		for i in range(0, pos):
			if s[i] == '1':
				pos1 = i
				break
			ans += s[i]
		ans += temp
		print(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()


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
for _ in range(int(input())):
	n = int(input())
	s = input()
	l_one = s.find('1')
	r_zero = s[::-1].find('0')
	if l_one == -1 or r_zero == -1 or l_one + r_zero == n:
		print(s)
	else:
		print('0' * (l_one + 1) + '1' * r_zero)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	w = s.find('1')
	ind1 = 0
	if w != -1:
		ind1 = s.index('1')
		ind0 = 0
		for g in range(n - 1, ind1, -1):
			if s[g] == '0':
				ind0 = g
				break
		if ind1 < ind0:
			se = s[:ind1] + s[ind0:]
			print(se)
		else:
			print(s)
	else:
		print(s)


t = int(input())
for _ in range(t):
	l = int(input())
	st = input()
	c = 0
	d = 0
	for i in range(l - 1, -1, -1):
		if st[i] == '1':
			c = c + 1
		else:
			break
	for i in range(l):
		if st[i] == '0':
			d = d + 1
		else:
			break
	if c + d < l:
		ans = '0' * d + '0' + '1' * c
	else:
		ans = st
	print(ans)


def check(str):
	for i in range(len(str) - 1):
		if str[i] == '1' and str[i + 1] == '0':
			return 0
	return 1
for i in range(int(input())):
	n = int(input())
	s = input()
	zc = 0
	oc = 0
	for i in s:
		if i == '0':
			zc += 1
		else:
			break
	for i in s[::-1]:
		if i == '1':
			oc += 1
		else:
			break
	if check(s) == 1:
		print(s)
	else:
		zeroes = ''
		ones = ''
		for i in range(zc + 1):
			zeroes += '0'
		for i in range(oc):
			ones += '1'
		print(zeroes + ones)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	b = []
	for j in s:
		b.append(j)
	j = 0
	c = []
	d = []
	while j < n:
		if b[j] == '0':
			c.append(j)
		else:
			d.append(j)
		j += 1
	j = 0
	s = 0
	d.append(n)
	while j < len(d) - 1:
		if d[j + 1] - d[j] > 1:
			s = 1
			break
		j += 1
	if c == []:
		c.append(-1)
	m = n - 1 - c[-1]
	r = d[0]
	print(''.join(['0'] * r) + ''.join(['0'] * s) + ''.join(['1'] * m))


for _ in range(int(input())):
	n = int(input())
	F = input()
	A = [i for i in F]
	stind0 = -1
	stind1 = -1
	ans = ''
	for i in range(len(A) - 1, -1, -1):
		if A[i] == '0':
			stind0 = i
			break
	for i in range(len(A)):
		if A[i] == '1':
			stind1 = i
			break
	if stind0 == -1:
		print('1' * len(A))
	elif stind1 == -1:
		print('0' * len(A))
	else:
		for i in range(len(A)):
			if i < stind1 and i != stind0:
				ans += '0'
			elif i == stind0:
				ans += '0'
			elif i > stind0 and i >= stind1:
				ans += '1'
		print(ans)


def solve():
	n = int(input())
	s = input()
	t = ''
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			t = t + '1'
		else:
			t = '0' + t
			break
	for i in range(n):
		if s[i] == '0' and len(t) < n:
			t = '0' + t
		else:
			break
	print(t)
numquery = int(input())
while numquery > 0:
	numquery -= 1
	solve()


for _ in range(int(input())):
	n = int(input())
	x = input()
	j = -1
	k = -1
	for i in range(len(x)):
		if x[i] == '1' and j == -1:
			j = i
		if x[i] == '0':
			k = i
	if k == -1 or j == -1 or k < j:
		print(x)
	else:
		x = x[:j] + x[k:]
		print(x)


for _ in range(int(input())):
	x = int(input())
	li = input()
	if li.count('0') == 0 or li.count('1') == 0:
		print(li)
		continue
	li1 = ''
	a = li.index('1')
	b = li[::-1].index('0')
	if a > 0:
		li1 += li[:a]
	if x - b - 1 > a:
		li1 += li[x - b - 1:]
	else:
		li1 += li[a:]
	print(li1)


for test_i in range(int(input())):
	n = int(input())
	s = input()
	l1 = 0
	while l1 < n:
		if s[-l1 - 1] == '1':
			l1 += 1
		else:
			break
	l0 = 0
	while l0 < n:
		if s[l0] == '0':
			l0 += 1
		else:
			break
	if l0 + l1 < len(s):
		print('0' * (l0 + 1) + '1' * l1)
	else:
		print('0' * l0 + '1' * l1)


import sys
from math import sqrt
input = sys.stdin.readline

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

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

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

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

def main():
	t = inp()
	for l in range(t):
		n = inp()
		s = instr()
		ans = []
		i = 0
		while i < len(s) and s[i] == '0':
			ans.append('0')
			i += 1
		l = i
		i = len(s) - 1
		while i >= 0 and s[i] == '1':
			ans.append('1')
			i -= 1
		if i >= l:
			ans.insert(l, '0')
		print(''.join(ans))
main()


t = int(input())
for i10 in range(t):
	n = int(input())
	a = list(map(int, input()))
	b = [1] * n
	i = n - 1
	j = -1
	for h in range(n):
		if a[h] == 1:
			j = h
			break
	while i != -1:
		if a[i] == 0 and i > j and (j != -1):
			if a[i - 1] == 1:
				a[i - 1] = 0
				if i - 1 == j:
					j = n
					b[i - 1] = 0
			else:
				b[i] = 0
				i -= 1
		else:
			i -= 1
	for i in range(n):
		if b[i] == 1:
			print(a[i], end='')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	one = n
	z = -1
	for x in range(n):
		if s[x] == '1':
			if x < one:
				one = x
		else:
			z = x
	if one < z:
		ans = s[:one] + '0' + s[z + 1:]
	else:
		ans = s
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if s.count('0') == 0 or s.count('0') == n:
		print(s)
		continue
	x = s.find('1')
	y = s.rfind('0')
	if x > y:
		print(s)
	else:
		k = '0' * x + s[y:]
		print(k)


import math
import sys
from itertools import permutations
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	s = list(input())
	if s[-1] == '\n':
		s.pop()
	ans = []
	start = -1
	end = -1
	for j in range(n):
		if s[j] == '0':
			ans.append('0')
		else:
			start = j
			break
	ones = 0
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			ones += 1
		else:
			end = j
			break
	if ones + len(ans) < n and end > start:
		ans.append('0')
	for j in range(ones):
		ans.append('1')
	print(''.join(ans))


def solve():
	n = int(input())
	x = input()
	if int(x) == 0:
		print(x)
	elif x.find('0') == -1:
		print(x)
	else:
		one = len(x)
		zero = 0
		for i in range(len(x)):
			if x[i] == '1':
				one = min(i, one)
			else:
				zero = max(zero, i)
		req = ''
		if zero < one:
			print(x)
		else:
			print(x[:one] + '0' + x[zero + 1:])
t = 1
t = int(input())
for _ in range(t):
	solve()


for t in range(int(input())):
	n = int(input())
	s = input()
	lastZero = -1
	firstOne = -1
	for i in range(n):
		if s[i] == '0':
			lastZero = i
	for i in range(n):
		if s[i] == '1':
			firstOne = i
			break
	if lastZero == -1:
		print(s)
	elif firstOne == -1:
		print(s)
	elif s.find('10') == -1:
		print(s)
	else:
		s1 = s[:firstOne]
		s2 = s[lastZero:]
		print(s1 + s2)


import time
import os, sys
from datetime import datetime
from math import floor, sqrt, gcd, factorial, ceil
from collections import Counter, defaultdict
import bisect
from itertools import chain
from collections import deque
from sys import maxsize as INT_MAX
ONLINE_JUDGE = False
if os.path.exists('D:\\Contest'):
	ONLINE_JUDGE = True
	sys.stdin = open('inp.txt', 'r')
	sys.stdout = open('out.txt', 'w')
INF = float('inf')
mod = int(1000000000.0) + 7

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

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

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

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

def mulfloat():
	return map(float, sys.stdin.readline().strip().split())

def flush():
	return sys.stdout.flush()

def power_two(x):
	return 1 << x

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

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

def two_pointer(n, val, *arr):
	(l, r, cnt) = (0, n - 1, 0)
	while l < r:
		if arr[l] + arr[r] > val:
			r -= 1
		else:
			cnt += r - l
			l += 1
	return cnt

def lower(arr, n, val):
	(l, r) = (-1, n)
	while r > l + 1:
		m = int(l + r >> 1)
		if arr[m] < val:
			l = m
		else:
			r = m
	return r

def upper(arr, n, val):
	(l, r) = (-1, n)
	while r > l + 1:
		m = int(l + r >> 1)
		if arr[m] <= val:
			l = m
		else:
			r = m
	return l

def BFS(adj, src, dist, paths, n):
	visited = [False] * n
	dist[src] = 0
	paths[src] = 1
	q = deque()
	q.append(src)
	visited[src] = True
	while q:
		curr = q[0]
		q.popleft()
		for x in adj[curr]:
			if not visited[x]:
				q.append(x)
				visited[x] = True
			if dist[x] > dist[curr] + 1:
				dist[x] = dist[curr] + 1
				paths[x] = paths[curr] % mod
			elif dist[x] == dist[curr] + 1:
				paths[x] = (paths[x] % mod + paths[curr] % mod) % mod

def binpow(a, n, mod):
	res = 1
	while n:
		if n & 1:
			res = res * a % mod
			n -= 1
		a = a * a % mod
		n = n >> 1
	return res

def is_perfect_square(num):
	temp = num ** 0.5
	return temp // 1 == temp

def printmat(l):
	for i in range(0, len(l)):
		print(*l[i], sep=' ')

def john_3_16():
	n = readint()
	s = [i for i in input()]
	(one_ind, zero_ind) = (None, None)
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			zero_ind = i
			break
	for i in range(0, n):
		if s[i] == '1':
			one_ind = i
			break
	if zero_ind != None and one_ind != None and (zero_ind > one_ind):
		ans = s[:one_ind] + s[zero_ind:]
	else:
		ans = s
	print(*ans, sep='')
	return

def main():
	tc = readint()
	start = time.time()
	while tc:
		john_3_16()
		tc -= 1
	if ONLINE_JUDGE:
		print(f'{(time.time() - start) * 1000}ms')
main()


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

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

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	s = list(input())
	index_1 = 0
	index_0 = n - 1
	i = 0
	while i < n and s[i] != '1':
		i += 1
	index_1 = i
	i = n - 1
	while i >= 0 and s[i] != '0':
		i -= 1
	index_0 = i
	if index_0 < index_1:
		print(*s, sep='')
	else:
		print(*s[:index_1], *s[index_0:], sep='')


import math
import os
import random
import re
import sys
import collections

def solve():
	for _ in range(int(input())):
		n = int(input())
		l = input()
		if l.count('0') == 0 or l.count('10') == 0:
			print(''.join(l))
			continue
		(s0, l1) = (0, 0)
		for i in l:
			if i == '0':
				s0 += 1
			else:
				break
		for i in range(n - 1, -1, -1):
			if l[i] == '1':
				l1 += 1
			else:
				break
		print('0' * s0 + '0' + '1' * l1)
solve()


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	if '0' in s:
		x = s.find('1')
		y = s.rfind('0')
		if y < x:
			print(s)
		else:
			a = s[:x] + s[y:]
			print(a)
	else:
		print(s)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ind1 = n
	ind2 = -1
	if '1' in s:
		ind1 = s.index('1')
	ans1 = s[:ind1]
	if '0' in s:
		ind2 = n - s[::-1].index('0') - 1
	ans2 = s[ind2:]
	if ind1 < ind2:
		print(ans1 + ans2)
	else:
		print(s)


import sys

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

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

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

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

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

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

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

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

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	S = input()
	if not S.count('10'):
		print(S)
		continue
	rcnt = 0
	for i in range(N - 1, -1, -1):
		if S[i] == '0':
			break
		else:
			rcnt += 1
	lcnt = 0
	for i in range(N):
		if S[i] == '1':
			break
		else:
			lcnt += 1
	ans = '0' * lcnt + '0' + '1' * rcnt
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input()
		first1 = s.find('1')
		if first1 == -1:
			print(s)
			continue
		last0 = -1
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				last0 = i
				break
		if last0 == -1:
			print(s)
			continue
		if first1 > last0:
			print(s)
			continue
		print(first1 * '0' + '0' + (n - last0 - 1) * '1')
main()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	pre_zero = 0
	post_one = 0
	rem = ''
	j = 0
	while j < len(s) and s[j] == '0':
		j += 1
	pre_zero = j
	j = len(s) - 1
	while j >= 0 and s[j] == '1':
		j -= 1
	post_one = len(s) - 1 - j
	rem = s[pre_zero:len(s) - post_one]
	if len(rem) > 0:
		rem = '0'
	else:
		rem = ''
	print(''.join(['0'] * pre_zero) + rem + ''.join(['1'] * post_one))


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	s = input()
	l = list(s)
	i = n - 1
	c = []
	flag = 0
	if n == 1:
		print(s)
	else:
		while i >= 0:
			if l[i] == '1':
				i = i - 1
				c.append('1')
			else:
				flag = 1
				c.append('0')
				j = 0
				d = 0
				while j < i:
					if l[j] == '0':
						j = j + 1
						d = d + 1
					else:
						break
				break
	if flag == 1:
		c = c + ['0'] * d
	e = c[::-1]
	ans = ''.join(e)
	print(ans)


a = int(input())
for i in range(0, a):
	c = input()
	b = input()
	arr = []
	for i in b:
		arr.append(int(i))
	zc = 0
	for i in range(len(arr) - 1, -1, -1):
		if zc == 1 and arr[i] == 0:
			arr[i] = 2
		if not zc == 1 and arr[i] == 0:
			zc = 1
		if zc == 1 and arr[i] == 1:
			arr[i] = 3
	ans = []
	pivot = 0
	for i in range(0, len(arr)):
		if arr[i] == 0:
			ans.append('0')
		if arr[i] == 1:
			ans.append('1')
		if arr[i] == 2 and pivot == 0:
			ans.append('0')
		if arr[i] == 3:
			pivot = 1
	print(''.join(ans))


T = int(input())
while T:
	T -= 1
	n = int(input())
	s = input()
	if len(s) == 1:
		print(s)
		continue
	ans = []
	cur = ''
	for i in range(n):
		if i + 1 < n and s[i] != s[i + 1]:
			cur += s[i]
			ans.append(cur)
			cur = ''
			continue
		cur += s[i]
	if cur != '':
		ans.append(cur)
	finalAns = ''
	check = False
	if len(ans) > 1 and ans[0][0] == '1' and (ans[1][0] == '0'):
		finalAns += '0'
	if ans[0][0] == '0':
		finalAns += ans[0]
		check = True
	if len(ans) > 2 and ans[1][0] == '1' and (ans[2][0] == '0'):
		finalAns += '0'
		check = True
	if ans[len(ans) - 1][0] == '1':
		finalAns += ans[len(ans) - 1]
		check = True
	if not check:
		print(0)
		continue
	print(finalAns)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	prelen = 0
	suflen = 0
	for c in s:
		if c == '0':
			prelen += 1
		else:
			break
	for c in reversed(s):
		if c == '1':
			suflen += 1
		else:
			break
	out = '0' * prelen
	if prelen + suflen < n:
		out += '0'
	out += '1' * suflen
	print(out)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ns = []
	freq = []
	i = 0
	while i < len(s):
		if s[i] == '1':
			c = 0
			while i < len(s) and s[i] == '1':
				c += 1
				i += 1
			ns += ['1']
			freq += [c]
		else:
			c = 0
			while i < len(s) and s[i] == '0':
				c += 1
				i += 1
			ns += ['0']
			freq += [c]
	if len(ns) == 1:
		print(ns[0] * freq[0])
	else:
		i = len(ns) - 2
		while i >= 0:
			if ns[i] == '1':
				if ns[i + 1] == '0':
					freq[i] = 0
					freq[i + 1] = 1
			i -= 1
		if len(ns) == 2:
			if ns[-1] == '0':
				print(0)
			else:
				ans = ''
				for i in range(len(ns)):
					ans += ns[i] * freq[i]
				print(ans)
		else:
			ans = ''
			if ns[0] == '0':
				ans += ns[0] * freq[0]
			if ns[-1] == '0':
				ans += '0'
				print(ans)
			else:
				ans += '0' * freq[-2] + '1' * freq[-1]
				print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if s[0] == '0':
		if s[-1] == '0':
			if s.count('1') > 0:
				ans = []
				for i in range(len(s)):
					if s[i] == '0':
						ans.append('0')
					else:
						ans.append('0')
						break
				print(''.join(ans))
			else:
				print(s)
		else:
			ans = []
			for i in range(len(s)):
				if s[i] == '0':
					ans.append('0')
				else:
					break
			for i in range(len(s) - 1, -1, -1):
				if s[i] == '1':
					ans.append('1')
				else:
					break
			if len(ans) == len(s):
				print(s)
			else:
				ans.insert(0, '0')
				ans = ''.join(ans)
				print(ans)
	elif s[-1] == '0':
		print('0')
	elif s.count('0') == 0:
		print(s)
	else:
		ans = []
		s = s[::-1]
		for i in range(len(s)):
			if s[i] == '1':
				ans.append('1')
			else:
				ans.append('0')
				break
		ans = ''.join(ans)
		print(ans[::-1])


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if '10' not in s:
		print(s)
	else:
		l = []
		l.append('0')
		for i in range(len(s)):
			if s[i] == '1':
				l.append('1')
			elif l[-1] == '0':
				l.append('0')
			else:
				while l[-1] != '0':
					l.pop()
				l.append('1')
		l = l[1:]
		for i in range(len(l)):
			if l[i] == '1':
				l[i] = '0'
				break
		print(''.join(l))


for _ in range(int(input())):
	input()
	s = input()
	(i, j) = (s.find('1'), s.rfind('0'))
	print([s[:i] + s[j:], s][i == -1 or j == -1 or i >= j])


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
term = l()[0]
for _ in range(term):
	n = l()[0]
	s = list(input())
	i = 0
	while i < n and s[i] != '1':
		i += 1
	j = n - 1
	while j >= 0 and s[j] != '0':
		j -= 1
	if i < j + 1:
		del s[i:j]
	print(''.join(s))


z = int(input())
for _ in range(z):
	size = int(input())
	thestring = input()
	if '10' not in thestring:
		print(thestring)
	else:
		newst = []
		newst.append('0')
		for i in range(len(thestring)):
			if thestring[i] == '1':
				newst.append('1')
			elif newst[-1] == '0':
				newst.append('0')
			else:
				while newst[-1] != '0':
					newst.pop()
				newst.append('1')
		newst = newst[1:]
		for i in range(len(newst)):
			if newst[i] == '1':
				newst[i] = '0'
				break
		print(''.join(newst))


for _ in range(int(input())):
	n = int(input())
	s = input()
	first1 = None
	last0 = None
	for i in range(n):
		if s[i] == '1' and first1 is None:
			first1 = i
			continue
		if s[i] == '0' and first1 is not None:
			last0 = i
	if first1 is None or last0 is None:
		ans = s
	else:
		ans = s[:first1] + s[last0:]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	if n == 1:
		print(s)
		continue
	ans = ''
	i = 0
	while i < n:
		if s[i] == '0':
			ans += '0'
			i += 1
		else:
			break
	ans1 = ''
	j = n - 1
	while j >= 0:
		if s[j] == '1':
			ans1 += '1'
			j -= 1
		else:
			break
	if i == j + 1:
		ans = ans + ans1
	else:
		ans = ans + '0' + ans1
	print(ans)


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

def insr():
	s = input()
	return s

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

def find_last_zero(l):
	for i in range(len(l) - 1, -1, -1):
		if l[i] == '0':
			return i
	return None

def find_first_one(l):
	for i in range(len(l)):
		if l[i] == '1':
			return i
	return None
r = inp()
for i in range(r):
	insr()
	l2 = insr()
	sp_l2 = list(l2)
	last_zero = find_last_zero(sp_l2)
	first_one = find_first_one(sp_l2)
	if last_zero == None or first_one == None or last_zero < first_one:
		print(l2)
	else:
		print(l2[:first_one] + '0' + l2[last_zero + 1:])


from sys import stdin as cin
from itertools import takewhile

def main():
	t = int(next(cin).strip())
	for i in range(t):
		next(cin)
		s = list(next(cin).strip())
		head = list(takewhile(lambda x: x == '0', s))
		tail = list(takewhile(lambda x: x == '1', reversed(s)))
		body = ['0'] if len(head) + len(tail) < len(s) else []
		print(''.join(head + body + tail))
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	count = []
	if n == 1:
		print(a)
		continue
	if a[0] == '1':
		count = [1]
		ans = '1'
		for i in range(1, n):
			if a[i] == ans:
				count[-1] += 1
			else:
				count.append(1)
				if ans == '1':
					ans = '0'
				else:
					ans = '1'
		if len(count) == 1:
			print(a)
			continue
		if len(count) % 2 == 0:
			print(0)
		else:
			if len(count) > 1:
				print('0', end='')
			print('1' * count[-1])
	else:
		count = [1]
		ans = '0'
		for i in range(1, n):
			if a[i] == ans:
				count[-1] += 1
			else:
				count.append(1)
				if ans == '1':
					ans = '0'
				else:
					ans = '1'
		if len(count) <= 2:
			print(a)
			continue
		if len(count) % 2 == 0:
			print('0' * count[0], end='')
			print('0', end='')
			print('1' * count[-1])
		else:
			print('0' * count[0], end='')
			print('0')


def main():
	t = int(input())
	while t:
		n = int(input())
		s = input()
		i = 0
		(zeros, ones) = (0, 0)
		while i < n:
			if s[i] == '0':
				zeros += 1
			else:
				break
			i += 1
		i = n - 1
		while i >= 0:
			if s[i] == '1':
				ones += 1
			else:
				break
			i -= 1
		if zeros + ones != n:
			zeros += 1
		while zeros:
			print('0', end='')
			zeros -= 1
		while ones:
			print('1', end='')
			ones -= 1
		print()
		t -= 1
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	i = 0
	m = ''
	while i < n:
		if s[i] == '1':
			break
		i += 1
	firstOne = min(i, n - 1)
	i = n - 1
	while i >= 0:
		if s[i] == '0':
			break
		i -= 1
	lastZero = max(0, i)
	if firstOne > lastZero:
		print(s)
		continue
	print(s[:firstOne] + s[lastZero:])


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for ii in range(int(input())):
	n = int(input())
	s = input()
	ind = []
	for i in range(n - 1):
		if s[i] == '1' and s[i + 1] == '0':
			ind.append(i)
	offset = 0
	offset2 = n - 1
	if len(ind) == 0:
		print(s)
		continue
	ans = ''
	for i in range(ind[0], -1, -1):
		if s[i] == '0':
			ans += '0'
	if len(ind):
		ans += '0'
	for i in range(ind[-1] + 1, n):
		if s[i] == '1':
			ans += '1'
	print(ans)


import sys
R = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	s = input()[:n]
	ans = ''
	cur = n - 1
	beg = 0
	while beg < n and s[beg] != '1':
		ans = ans + s[beg]
		beg += 1
	if beg == n:
		print(s)
		continue
	gao = False
	suf = ''
	sl = 0
	while cur > beg:
		if s[cur] == '0':
			gao = True
		if not (gao and s[cur] == '1'):
			suf = s[cur] + suf
			sl += 1
		cur -= 1
	gao = False
	now = 0
	while now < sl and suf[now] == '0':
		now += 1
		if not gao:
			gao = True
	if gao:
		ans += '0'
	else:
		ans += '1'
	ans += suf[now:]
	print(ans)


import math

def nod(a, b):
	while True:
		if a > b:
			if a % b == 0:
				return b
				break
			else:
				a = a % b
		elif b % a == 0:
			return a
			break
		else:
			b = b % a

def dtod(a):
	s = ''
	while a != 0:
		s += str(a % 2)
		a = int(a / 2)
	return s[::-1]

def _8_(a):
	return a[0] * a[1] * a[2] * a[3] * a[4] * a[5] * a[6] * a[7] * a[8] * a[9]
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	arraylen = []
	arrayv = []
	o = 0
	firstnull = 0
	lastone = 0
	ewr = 0
	for j in range(n - 1):
		if s[j] + s[j + 1] == '10':
			ewr = 1
			break
	for j in range(n):
		if s[j] == '1':
			break
		else:
			firstnull += 1
	s = s[::-1]
	for j in range(n):
		if s[j] == '0':
			break
		else:
			lastone += 1
	print('0' * firstnull + '0' * ewr + '1' * lastone)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	(a, b) = (0, 0)
	for i in range(n):
		if s[i] == '1':
			break
		a += 1
	for i in range(1, n + 1):
		if s[-i] == '0':
			break
		b += 1
	if a + b == n:
		print(s)
		continue
	print('0' * (a + 1) + '1' * b)


for i in range(int(input())):
	(n, s) = (int(input()), input())
	last0 = s.rfind('0')
	first1 = s.find('1')
	if last0 <= first1:
		print(s)
		continue
	else:
		print(s[:first1] + s[last0:])


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

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	N = int(input())
	S = input()
	if '10' not in S:
		print(S)
	else:
		Ans = ''
		for i in S:
			if i == '0':
				Ans += i
			else:
				break
		Ans += '0'
		for i in range(N - 1, -1, -1):
			if S[i] == '1':
				Ans += S[i]
			else:
				break
		print(Ans)


from collections import deque
import re
rp = re.compile('[_]+')
for t in range(int(input())):
	(n, s, p) = (input(), deque(input()), deque())
	while s:
		if p and p[-1] == '1' and (s[0] == '0'):
			while p and p[-1] == '1':
				p.pop()
			while s and s[0] == '0':
				s.popleft()
			p.append('_')
		else:
			p.append(s.popleft())
	print(rp.sub('0', ''.join(p)))


def change(s):
	x = s[::-1]
	c0 = c1 = 0
	for u in s:
		if u == '0':
			c0 += 1
		else:
			break
	for u in x:
		if u == '1':
			c1 += 1
		else:
			break
	if c1 + c0 == n:
		return '0' * c0 + '1' * c1
	else:
		return '0' * c0 + '0' + '1' * c1
for _ in range(int(input())):
	n = int(input())
	s = input()
	if len(s) == 1:
		print(s)
	else:
		print(change(s))


for j in range(int(input())):
	a = int(input())
	t = input()
	b = list(t)
	k = 0
	y = 0
	for i in range(len(b)):
		if b[i] == '1':
			k = i
			break
	for i in range(len(b)):
		if b[i] == '1':
			y = y + 1
		else:
			y = 0
	c = b[k:]
	o = 0
	if b.count('1') == 0:
		print(t)
	else:
		for p in range(len(c) - 1):
			if c[p] == '0' and c[p + 1] == '1':
				o = o + 1
		e = c[-1]
		if e == '1':
			if o > 0:
				r = b[:k] + [0] + [1] * y
			else:
				r = b[:k] + [1] * y
		else:
			r = b[:k] + [0]
		u = ''
		for q in r:
			u = u + str(q)
		print(u)


import sys
t = int(input())
while t:
	t -= 1
	n = int(input())
	s = list(map(int, input()))
	if n == 1:
		print(*s)
	else:
		k = s.copy()
		k.sort()
		if k == s:
			print(*s, sep='')
		else:
			c0 = 1
			c1 = 0
			for i in range(n):
				if s[i] == 0:
					c0 += 1
				else:
					break
			for i in range(n - 1, -1, -1):
				if s[i] == 1:
					c1 += 1
				else:
					break
			print('0' * c0 + '1' * c1)


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	l = int(input())
	s = list(input().rstrip())
	ones = 0
	zeros = 0
	found = 0
	for j in range(l):
		if found < 1 and s[j] == '0':
			zeros += 1
		if s[j] == '1':
			ones += 1
			found += 1
		else:
			ones = 0
	if zeros + ones == l:
		print(''.join(s))
	else:
		print((zeros + 1) * '0' + ones * '1')


import os
import sys
from io import BytesIO, IOBase
import threading
from math import floor
from bisect import bisect_right
from collections import Counter
from math import gcd
mod = 998244353

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		ans = []
		ind1 = 0
		ans2 = []
		while ind1 < n and s[ind1] != '1':
			ans.append('0')
			ind1 += 1
		ind = n - 1
		ans2 = []
		while ind >= 0 and s[ind] != '0':
			ans2.append('1')
			ind -= 1
		if ind1 < ind:
			ans = ans + ['0'] + ans2
		else:
			ans = ans + ans2
		print(''.join(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()


z = input
for _ in range(int(z())):
	n = int(z())
	a = z()
	if a.count('1') == 0 or a.count('1') == n:
		print(a)
		continue
	b = a.find('1')
	c = a.rfind('0')
	if b > c:
		print(a)
	else:
		r = '0' * b + a[c:]
		print(r)


def shorten(sample, i):
	sample = sample[:i] + sample[i + 1:]
	return sample

def red_len(sample, size):
	i = size - 1
	if size == 1:
		return sample
	while i > 0:
		if i == size:
			i = i - 1
		if sample[i] == '0' and sample[i - 1] == '1':
			if i == size - 1 and i - 1 == 0:
				sample = shorten(sample, i - 1)
				size = size - 1
				return sample
			elif i == size - 1 and i - 1 != 0:
				sample = shorten(sample, i - 1)
				size = size - 1
			elif i - 1 == 0 and i != size - 1:
				if sample[i + 1] == '1':
					sample = shorten(sample, i - 1)
					size = size - 1
				elif sample[i + 1] == '0':
					sample = shorten(sample, i)
					size = size - 1
			elif i - 1 != 0 and i != size - 1:
				if sample[i - 2] == '1' and sample[i + 1] == '1':
					sample = shorten(sample, i - 1)
					size = size - 1
				elif sample[i - 2] == '0' and sample[i + 1] == '1':
					sample = shorten(sample, i - 1)
					size = size - 1
				elif sample[i - 2] == '1' and sample[i + 1] == '0':
					sample = shorten(sample, i)
					size = size - 1
				elif sample[i - 2] == '0' and sample[i + 1] == '0':
					sample = shorten(sample, i)
					size = size - 1
		else:
			i = i - 1
	return sample

def main():
	t = int(input())
	b = 0
	while b < t:
		size = int(input())
		sample = input()
		print(red_len(sample, size))
		b = b + 1
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	(one, zero) = (0, 0)
	f = g = True
	for i in range(n):
		if s[i] == '0' and f:
			zero += 1
		else:
			f = False
		if s[-(i + 1)] == '1' and g:
			one += 1
		else:
			g = False
	for _ in range(zero):
		print(0, end='')
	if zero + one != n:
		print(0, end='')
	for _ in range(one):
		print(1, end='')
	print()


for i in range(int(input())):
	n = int(input())
	s = input()
	zero = 0
	one = 0
	for i in range(len(s)):
		if s[i] == '0':
			zero += 1
		else:
			break
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			one += 1
		else:
			break
	if one + zero < n:
		print('0' * zero + '0' + '1' * one)
	else:
		print('0' * zero + '1' * one)


for _ in range(int(input())):
	n = int(input())
	s = input()
	strt = ''
	end = ''
	l = 0
	r = n - 1
	for i in range(len(s)):
		if s[i] == '1':
			break
		strt += '0'
		l += 1
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '0':
			break
		end += '1'
		r -= 1
	if l < r:
		strt += '0'
	print(strt + end)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	one = 0
	zero = 0
	if '0' in s and '1' in s:
		r = s.rindex('0')
		e = s.index('1')
		if r > e:
			s = list(s)
			s[e:r + 1] = '0'
			print(''.join(s))
		else:
			print(''.join(s))
	else:
		print(s)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	s = input()
	f1 = s.find('1')
	s = list(s)
	turn = False
	s2 = ''
	i = n - 1
	if f1 == -1:
		f1 = 99999999999
	while i >= 0:
		if turn:
			if s[i] == '0':
				s[i] = ''
				i -= 1
				continue
			else:
				s[i] = '0'
				turn = False
				continue
		if s[i] == '0' and i > f1:
			s[i] = ''
			turn = True
			i -= 1
		else:
			i -= 1
	print(''.join(s))


from sys import stdin, stdout
from collections import Counter
import sys
t_case = int(stdin.readline())
for t in range(t_case):
	l = int(stdin.readline())
	s = stdin.readline()
	stk = []
	last0 = s.rfind('0')
	for (i, c) in enumerate(s):
		if c == '0' and len(stk) > 0 and (stk[-1] == '1'):
			while len(stk) > 0 and stk[-1] == '1':
				stk.pop()
			if i == last0:
				stk.append('0')
			else:
				stk.append('1')
		else:
			stk.append(c)
	print(''.join(stk))


t = int(input())
for i in range(t):
	n = int(input())
	s = list(input())
	one = 0
	zero = 0
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			break
		else:
			one = one + 1
	for i in range(n):
		if s[i] == '1':
			break
		else:
			zero = zero + 1
	if one + zero == n:
		print(''.join(s))
	else:
		r = []
		for i in range(zero):
			r.append('0')
		r.append('0')
		for i in range(one):
			r.append('1')
		print(''.join(r))


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	l = []
	index = 0
	for i in range(n):
		if s[i] == '0':
			index = i
	i = 0
	while i < n:
		if l:
			if l[-1] == '1' and s[i] == '0':
				j = i
				while j < n and s[i] == s[j]:
					j += 1
				while l and l[-1] == '1':
					l.pop()
				if j >= index:
					l.append('0')
				else:
					l.append('1')
				i = j
			else:
				l.append(s[i])
				i += 1
		else:
			l.append(s[i])
			i += 1
	print(''.join(l))


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict as dd

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		en = 0
		st = 0
		(i, j) = (0, n - 1)
		while j >= 0 and s[j] == '1':
			en += 1
			j -= 1
		while i < n and s[i] == '0':
			st += 1
			i += 1
		if st + en == n:
			print('0' * st + '1' * en)
		else:
			print('0' * (st + 1) + '1' * en)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


for _ in range(int(input())):
	n = int(input())
	s = input()
	b = s[::-1]
	if '0' not in list(s):
		print(s)
	elif '1' not in list(s):
		print(s)
	else:
		x1 = b.index('0')
		x2 = s.index('1')
		x1 = len(s) - 1 - x1
		if x2 <= x1:
			ss = ''
			for i in range(x2):
				ss += s[i]
			ss = ss + '0'
			for i in range(x1 + 1, len(s)):
				ss += s[i]
			print(ss)
		else:
			print(s)


def remove_at(i, s):
	return s[:i] + s[i + 1:]
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	front = 0
	back = 0
	yep = 0
	for j in range(len(s) - 1):
		if s[j] > s[j + 1]:
			yep += 1
			break
	if yep == 0:
		print(s)
		continue
	for j in range(len(s)):
		if s[j] == '0':
			front += 1
		else:
			break
	front += 1
	for j in range(len(s) - 1, 0, -1):
		if s[j] == '1':
			back += 1
		else:
			break
	print('0' * front + '1' * back)


for i in range(int(input())):
	n = int(input())
	arr = list(input())
	ans = []
	i = 0
	flag = True
	check = 0
	while i < n:
		if arr[i] == '0':
			cnt = 0
			while i < n and arr[i] == '0':
				i += 1
				cnt += 1
			if flag:
				ans += ['0'] * cnt
			else:
				ans.append('0')
			if check != 0:
				check += 1
		else:
			flag = False
			cnt = 0
			while i < n and arr[i] == '1':
				i += 1
				cnt += 1
			if i == n:
				ans += ['1'] * cnt
			else:
				ans.append('1')
			check += 1
	fin1 = ''
	i = 0
	while i < len(ans):
		if ans[i] == '0':
			fin1 += ans[i]
			i += 1
		else:
			break
	fin2 = ''
	k = i
	i = len(ans) - 1
	while i >= 0:
		if ans[i] == '1':
			fin2 += '1'
			i -= 1
		else:
			break
	aaaa = ''
	if check >= 2:
		print(fin1 + '0' + fin2)
	else:
		print(fin1 + fin2)


from sys import stdin

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	n = int(inp())
	s = inp()
	flag = False
	zero = -1
	one = -1
	for i in range(n):
		if s[i] == '1':
			if not flag:
				one = i
				flag = True
		elif flag:
			zero = i
	flag = False
	if zero == -1:
		print(s)
	else:
		for i in range(n):
			if one <= i < zero:
				pass
			elif i == zero:
				print('0', end='')
			else:
				print(s[i], end='')
		print('')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()[:-1]
	cnt = 0
	flag = False
	for i in range(n):
		if s[i] == '1' and (not flag):
			flag = True
		elif s[i] == '1' and flag and (i > 0) and (s[i - 1] == '0'):
			cnt += 1
		elif s[i] == '0' and (not flag):
			print(0, end='')
	if flag and s[-1] == '0':
		print(0, end='')
	elif flag:
		if cnt:
			print(0, end='')
		i = n - 1
		while i >= 0 and s[i] == '1':
			print(1, end='')
			i -= 1
	print()


for test in range(int(input())):
	n = int(input())
	s = input()
	if -1 == s.find('10'):
		print(s)
		continue
	print(s[:s.find('1')] + s[-1 - s[::-1].find('0'):])


for i in range(int(input())):
	n = int(input())
	st = input()
	arr = []
	arr2 = []
	for j in st:
		arr.append(j)
	j = 1
	zeros = 0
	arr3 = arr[::-1]
	for kk in arr3:
		if kk == '0':
			zeros += 1
		arr2.append(zeros)
	arr2 = arr2[::-1]
	while j < len(arr):
		if j - 1 >= 0 and arr[j - 1] == '1' and (arr[j] == '0'):
			if j - 2 >= 0 and arr[j - 2] == '1' or (j + 1 < len(arr2) and arr2[j + 1] == 0) or j + 1 >= len(arr2):
				arr.pop(j - 1)
				arr2.pop(j - 1)
				j -= 2
			else:
				arr.pop(j)
				arr2.pop(j)
				j -= 2
		j += 1
	ans = ''
	for k in arr:
		ans += k
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = n - len(s.lstrip('0'))
	y = n - len(s.rstrip('1'))
	if x + y == n:
		print(s)
	else:
		print('0' * x + '0' + '1' * y)


import math
t = int(input())
while t:
	t = t - 1
	n = int(input())
	s = input()
	ans = ''
	(one, zero) = (0, 0)
	for w in range(n):
		if s[w] == '0' and one == 0:
			ans += '0'
		elif s[w] == '1':
			one = 1
		elif s[w] == '0' and one != 0:
			zero = 1
	x = 0
	for w in range(n - 1, -1, -1):
		if s[w] == '1':
			x += 1
		else:
			break
	if zero == 0:
		for w in range(n):
			if s[w] == '1':
				ans += s[w]
	elif s[-1] == '0':
		ans += '0'
	else:
		ans += '0'
		for z in range(x):
			ans += '1'
	print(ans)


t = int(input())
for test in range(t):
	n = int(input())
	s = input()
	bval = 0
	for i in s:
		if i == '0':
			bval += 1
		else:
			break
	endval = 0
	for i in s[::-1]:
		if i == '1':
			endval += 1
		else:
			break
	begin = '0' * bval
	end = '1' * endval
	if len(s) > bval + endval:
		mid = '0'
	else:
		mid = ''
	print(begin + mid + end)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	flag = 0
	flag1 = 0
	if '10' not in s:
		print(s)
	else:
		for k in range(n):
			if s[k] == '0':
				print(s[k], end='')
			else:
				flag = k
				break
		for k in range(n - 1, flag, -1):
			if s[k] == '0':
				flag1 = k
				break
		print('0', end='')
		if flag1 != n - 1:
			for k in range(1, n - 1 - flag1 + 1):
				print('1', end='')
		print('')


for i in range(int(input())):
	n = int(input())
	s = input()
	(a, b, c) = (1, 1, 0)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			c = 1
			break
	if c == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			a = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			b = i
			break
	st = s[:a] + '0' + s[b + 1:]
	print(st)


for i in range(int(input())):
	z = input()
	x = input()
	if list(x) == list(sorted(x)):
		print(x)
	else:
		print('0' * (x.index('1') + 1) + '1' * x[::-1].index('0'))


for _ in range(int(input())):
	n = int(input())
	s = input()
	if s.count('0') == 0 or s.count('0') == n:
		print(s)
		continue
	r = s.find('1')
	l = s.rindex('0')
	if r > l:
		print(s)
	else:
		ans = s[:r] + s[l:]
		print(ans)


tot = int(input().strip())
while tot > 0:
	n = int(input().strip())
	s = input().strip()
	rep = True
	pref = 0
	while pref < n and s[pref] == '0':
		pref += 1
	s = s[pref:]
	z = s.count('0')
	mz = 0
	sr = 0
	s = list(s)
	for i in range(0, len(s) - 1):
		if s[i] == '1' and s[i + 1] == '0':
			if mz < z - 1:
				mz += 1
				s[i + 1] = '1'
			else:
				s[i] = '0'
				sr = i + 1
				break
	print('0' * pref + ''.join(s[sr:]))
	tot -= 1


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	n = ii1()
	s = list(is1())
	res = []
	for i in s[::-1]:
		if i == '0':
			res.append(i)
		else:
			flag = False
			while len(res) and res[-1] == '0':
				res.pop()
				flag = True
			if flag == True:
				res.append('0')
			else:
				res.append('1')
	print(''.join(res[::-1]))


t = int(input())
for _ in range(t):
	n = int(input())
	l = input()
	cnt0 = 0
	cnt1 = 0
	for i in range(n):
		if l[i] == '1':
			break
		cnt0 += 1
	for i in range(n - 1, -1, -1):
		if l[i] == '0':
			break
		cnt1 += 1
	f = 0
	for i in range(n - 1):
		if l[i] == '1' and l[i + 1] == '0':
			f = 1
			break
	if f == 1:
		cnt0 += 1
	s = ''
	for i in range(cnt0):
		s += '0'
	for i in range(cnt1):
		s += '1'
	print(s)


t = int(input())
for i in range(t):
	n = int(input())
	s = list(input())
	ans = []
	flag = 0
	lead0 = trail = 0
	for j in range(n):
		if s[j] == '0' and flag == 0:
			lead0 += 1
		else:
			flag = 1
			break
	for k in range(n - 1, -1, -1):
		if s[k] == '1' and flag == 1:
			trail += 1
		else:
			flag = 2
			break
	if lead0 + trail == len(s):
		print(*s, sep='')
	else:
		for i in range(lead0 + 1):
			ans.append(0)
		for i in range(trail):
			ans.append(1)
		print(*ans, sep='')


for _ in range(int(input())):
	n = int(input())
	arr = list(input())
	ans = ''
	pre = -1
	nxt = 2
	i = n - 2
	while i >= 0:
		pre = i - 1
		j = i + 1
		nxt = j + 1
		if i < n and j < n and (arr[i] == '1') and (arr[j] == '0'):
			if pre != -1 and arr[pre] == '1':
				arr.pop(i)
				i += 1
			elif nxt < n and arr[nxt] == '0':
				arr.pop(j)
			else:
				arr.pop(i)
				i += 1
			n -= 1
		else:
			i -= 1
	print(''.join(arr))


from collections import deque

def clean(s):
	q = deque()
	for i in range(len(s) - 1, -1, -1):
		if q and q[0] == '0' and (s[i] == '1'):
			while len(q) > 1 and q[1] == '0':
				q.popleft()
			else:
				continue
		q.appendleft(s[i])
	return ''.join(q)
for i in range(int(input())):
	n = int(input())
	s = input()
	print(clean(s))


for t in range(int(input())):
	n = int(input())
	s = input()
	l = list(s)
	st = '0'
	if n == 1:
		print(s[0])
	elif '10' not in s:
		print(s)
	else:
		i = s.find('1')
		l.reverse()
		j = l.index('0')
		j = n - j - 1
		for k in range(i):
			st = st + '0'
		for k in range(j + 1, n):
			st = st + s[k]
		print(st)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	flg = 0
	flg1 = 0
	st = ''
	for i in range(n):
		if s[i] == '1':
			k = i
			flg1 += 1
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			j = i
			flg += 1
			break
	if flg == 0 or flg1 == 0:
		for i in range(n):
			st += s[i]
		print(st)
	elif j < k:
		for i in range(n):
			st += s[i]
		print(st)
	else:
		for i in range(k):
			st += s[i]
		for i in range(j, n, 1):
			st += s[i]
		print(st)


import sys
lines = sys.stdin.readlines()
T = int(lines[0].strip())
for t in range(T):
	n = int(lines[2 * t + 1].strip())
	s = lines[2 * t + 2].strip()
	left = ''
	right = ''
	for l in range(n):
		if s[l] == '0':
			left += '0'
		else:
			break
	for r in range(n - 1, -1, -1):
		if s[r] == '1':
			right += '1'
		else:
			break
	if l < r:
		left += '0'
	print(left + right)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	last_zero_id = 0
	for i in range(n):
		last_zero_id = i if s[i] == '0' else last_zero_id
	stack = [s[0]]
	i = 1
	while i < n:
		if stack and stack[-1] == '1' and (s[i] == '0'):
			while stack and i < n and (stack[-1] == '1') and (s[i] == '0'):
				if i != last_zero_id:
					i += 1
				else:
					stack.pop()
		if i < n:
			stack.append(s[i])
		i += 1
	print(''.join(stack))


t = int(input())
for i in range(t):
	n = int(input())
	arr = input()
	first_one = arr.find('1')
	last_zero = arr.rfind('0')
	if first_one == -1 or last_zero == -1:
		print(arr)
	elif first_one > last_zero:
		print(arr)
	else:
		final = arr[0:first_one] + arr[last_zero:]
		print(final)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = list()
	ans1 = list()
	j = -1
	for i in s:
		j += 1
		if i == '0':
			ans.append('0')
		else:
			break
	h = -1
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			ans1.append('1')
		else:
			h = i
			break
	if j - 1 == h:
		print(*ans, *ans1, sep='')
		continue
	if len(ans) + len(ans1) == n:
		print(*ans, *ans1, sep='')
	else:
		print(*ans, '0', *ans1, sep='')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	first_one = -1
	last_zero = -1
	for i in range(n):
		if s[i] == '1':
			first_one = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			last_zero = i
			break
	arr = []
	i = 0
	if first_one == -1 or last_zero == -1 or first_one > last_zero:
		print(s)
	else:
		while i < first_one:
			arr.append(s[i])
			i += 1
		arr.append(s[i])
		i += 1
		while i < last_zero:
			if s[i] == '1':
				arr.append(s[i])
			i += 1
		while len(arr) > 0 and arr[-1] == '1':
			arr.pop()
		arr.append(s[i])
		i += 1
		while i < n:
			arr.append(s[i])
			i += 1
		for x in arr:
			print(x, end='')
		print()


I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	s = input()
	if '10' not in s:
		print(s)
		continue
	else:
		te = s.find('10')
		ze = 0
		cn = 0
		for i in range(te):
			if s[i] == '0':
				cn += 1
			else:
				ze = max(ze, cn)
				cn = 0
		ze = max(ze, cn)
		tee = s.rfind('10')
		on = 0
		cn = 0
		for i in range(tee + 2, n):
			if s[i] == '1':
				cn += 1
			else:
				on = max(on, cn)
				cn = 0
		on = max(on, cn)
		print('0' * ze + '0' + '1' * on)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(str, input().strip()))
	l = []
	ze_strt = -1
	one_end = n
	for i in range(n):
		if arr[i] != '0':
			break
		ze_strt = i
	for i in range(n - 1, -1, -1):
		if arr[i] != '1':
			break
		one_end = i
	if one_end - ze_strt == 1:
		print((ze_strt - -1) * '0' + (n - (ze_strt - -1)) * '1')
	else:
		print((ze_strt - -1) * '0' + '0' + (n - one_end) * '1')


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

def si():
	return input()

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

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

def rindex(mylist, myvalue):
	return len(mylist) - mylist[::-1].index(myvalue) - 1
t = ii()
for i in range(t):
	n = ii()
	s = si()
	if '0' not in s or '1' not in s:
		print(s)
	else:
		i = s.index('1')
		j = rindex(s, '0')
		if j < i:
			print(s)
		else:
			print(s[0:i] + s[j:n])


t = int(input())
while t:
	n = int(input())
	a = input()
	ans1 = ''
	i = 0
	while i < n and a[i] == '0':
		ans1 += '0'
		i += 1
	ans2 = ''
	j = n - 1
	while j >= 0 and a[j] == '1':
		ans2 += '1'
		j -= 1
	if j < i:
		print(ans1 + ans2)
	else:
		print(ans1 + '0' + ans2)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	k = 0
	ns = ''
	tba = []
	while k < len(s):
		if s[k] == '1':
			ki = k
			ic = 0
			while k < len(s) and s[k] == '1':
				k = k + 1
			while k < len(s) and s[k] == '0':
				k = k + 1
				ic = 1
			if ic == 1:
				tba.extend(list((int(num) for num in range(ki, k))))
		else:
			k = k + 1
	if tba:
		ns = ns + s[0:tba[0]] + '0' + s[tba[-1] + 1:]
	else:
		ns = s
	print(ns)


test_cases = int(input())

def handle():
	input()
	s = input()
	queue = []
	for char in s[::-1]:
		if char == '1':
			total_zeros = 0
			while queue and queue[-1] == '0':
				total_zeros += 1
				queue.pop()
			if total_zeros > 0:
				queue.append('0')
			else:
				queue.append('1')
		else:
			queue.append('0')
	return ''.join(list(queue[::-1]))
for _ in range(test_cases):
	print(handle())


for _ in range(int(input())):
	n = int(input())
	s = input()
	blocks = [[s[0], 1]]
	for i in range(1, n):
		if s[i] == blocks[-1][0]:
			blocks[-1][1] += 1
		else:
			blocks += [[s[i], 1]]
	res = ''
	if blocks[0][0] == '0':
		res = '0' * blocks[0][1]
	if len(blocks) > 2 and blocks[-2][0] == '0':
		res += '0'
	if len(blocks) > 1 and blocks[-1][0] == '0':
		res += '0'
	if blocks[-1][0] == '1':
		res += blocks[-1][0] * blocks[-1][1]
	print(res)


test = int(input())
for i in range(test):
	n = int(input())
	s = input()
	last = len(s)
	res = s[0]
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '0':
			last = i
			break
	if last == len(s):
		print(s)
	else:
		j = -1
		k = 0
		while k <= last and s[k] != '1':
			j += 1
			k += 1
		if j == last:
			print(s)
		else:
			print(s[:j + 1] + s[last:])


t = int(input())
for test in range(t):
	n = int(input())
	temp = input()
	arr = [int(x) for x in temp]
	zc = 0
	oc = 0
	for i in arr:
		if i == 0:
			zc += 1
	tot = n
	i = 0
	while i + 1 < tot:
		if arr[i] == 1 and arr[i + 1] == 0:
			if zc > 1:
				arr.pop(i + 1)
				tot -= 1
				zc -= 1
			else:
				arr.pop(i)
				tot -= 1
				if i - 1 >= 0:
					i -= 1
		else:
			if arr[i] == 0:
				zc -= 1
			i += 1
	print(''.join((str(x) for x in arr)))


T = int(input())
for i in range(T):
	N = int(input())
	S = input()
	if N == 1:
		print(S)
	else:
		lz = -1
		fo = -1
		for j in range(N):
			if S[j] == '1':
				fo = j
				break
		for j in range(N - 1, -1, -1):
			if S[j] == '0':
				lz = j
				break
		if lz == -1 or fo == -1:
			print(S)
		else:
			if lz < fo:
				ans = S
			elif lz == N - 1:
				ans = S[0:fo] + S[lz]
			else:
				ans = S[0:fo] + '0' + S[lz + 1:]
			print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	lis = []
	a = 0
	for i in range(n):
		if s[i] == '1':
			a = i
			break
	b = 0
	c = 0
	l = 0
	for i in range(a, n):
		if s[i] == '1':
			if c == 1:
				b += 1
			else:
				c = 1
				if l > 0:
					lis.append(b)
					l += 1
				b = 1
		elif c == 0:
			b += 1
		else:
			c = 0
			lis.append(b)
			l += 1
			b = 1
	if l == 0:
		print(s)
	else:
		lis.append(b)
		l += 1
		ans = ''
		for j in range(a):
			ans += '0'
		for j in range(l):
			if j % 2 == 1:
				ans += '0'
				break
		if l % 2 == 1:
			for j in range(lis[-1]):
				ans += '1'
		print(ans)


for i in range(int(input())):
	n = int(input())
	s = input()
	i1 = 0
	j1 = 0
	if s.count('0') == 0 or s.count('1') == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			i1 = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			j1 = i
			break
	if j1 < i1:
		print(s)
		continue
	else:
		s1 = str()
		if i1 > 0:
			s1 += s[0:i1]
		s1 += '0'
		if j1 < n - 1:
			s1 += s[j1 + 1:]
		print(s1)


mod = 1000000007
ssi = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	s = input()
	(zero, one) = (0, 0)
	for i in range(n):
		if s[i] == '0':
			zero += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			one += 1
		else:
			break
	if zero + one == n:
		print('0' * zero + '1' * one)
	else:
		print('0' * zero + '0' + '1' * one)


for _ in range(int(input())):
	n = int(input())
	binary = input()
	if n == 1:
		print(binary)
		continue
	leading_zeroes = 0
	trailing_ones = 0
	sorted_ = True
	for i in range(len(binary) - 1):
		if binary[i] <= binary[i + 1]:
			continue
		else:
			sorted_ = False
			break
	if sorted_:
		print(binary)
		continue
	for i in range(len(binary)):
		if binary[i] == '0':
			leading_zeroes += 1
		else:
			break
	for j in range(len(binary) - 1, -1, -1):
		if binary[j] == '1':
			trailing_ones += 1
		else:
			break
	print('0' * (leading_zeroes + 1) + '1' * trailing_ones)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ans = ''
	ind = n
	flag = 0
	for i in range(n):
		if s[i] == '0':
			ans += '0'
		else:
			ind = i
			break
	for i in range(ind, n):
		if s[i] == '0' and flag == 0:
			ans += '0'
			flag = 1
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			ans += '1'
		else:
			break
	print(ans)


for i in range(int(input())):
	n = int(input())
	s = str(input())
	ss = sorted(s)
	sk = ''
	ss = sk.join(ss)
	if s == ss:
		print(s)
	else:
		l0 = s.index('1')
		y = s.rstrip('1')
		l1 = len(s) - len(y)
		l = []
		for i in range(l0 + 1):
			l.append('0')
		for j in range(l1):
			l.append('1')
		ans = ''
		ans = ans.join(l)
		print(ans)


def solve(n, s):
	one = 0
	zero = 0
	for i in range(n):
		if s[i] == '0':
			zero += 1
		else:
			one += 1
	if s == '0' * zero + '1' * one:
		print(s)
		return
	x = 0
	y = 0
	for i in range(n):
		if s[i] == '0':
			x += 1
			continue
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			y += 1
			continue
		else:
			break
	ans = '0' * (x + 1) + '1' * y
	print(ans)
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	solve(n, s)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	l = list(s)
	i = len(l) - 1
	l1 = []
	while i >= 0:
		if l[i] == '1':
			l1.append(l[i])
		else:
			break
		i = i - 1
	i = 0
	l2 = []
	while i < len(l):
		if l[i] == '0':
			l2.append('0')
		else:
			break
		i = i + 1
	val = 0
	for j in range(len(l) - 1):
		if l[j] == '1' and l[j + 1] == '0':
			val = 1
			break
	if val == 1:
		l2.append('0')
	print(''.join(l2), end='')
	print(''.join(l1))


from math import *
t = int(input())
while t > 0:
	n = int(input())
	s = input()
	r = -1
	l = n
	for i in range(n):
		if s[i] == '0':
			r = i
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			l = i
	if r > l:
		ans = s[:l] + s[r:]
	else:
		ans = s
	print(ans)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	thing = 0
	last = s[0]
	thing = 0
	for i in s[1:]:
		if i != last and last == '1':
			thing += 1
		last = i
	left = 0
	if s[0] == '0':
		for i in range(n):
			if s[i] == '1':
				break
			left += 1
	right = 0
	if s[-1] == '1':
		for i in range(n - 1, -1, -1):
			if s[i] == '0':
				break
			right += 1
	ans = ''
	if thing > 0:
		ans = left * '0' + '0' + right * '1'
	else:
		ans = left * '0' + right * '1'
	print(ans)


from sys import stdin
A = int(stdin.readline())
for t in range(0, A):
	B = int(stdin.readline())
	C = stdin.readline()
	zero = 0
	one = 0
	strzero = ''
	strone = ''
	for k in range(0, B):
		if C[k] == '0':
			zero += 1
			strzero += '0'
		else:
			break
	for k in range(1, B + 1):
		if C[B - k] == '1':
			one += 1
			strone += '1'
		else:
			break
	if zero > 0 and one > 0:
		if zero + one < B:
			print(strzero + '0' + strone)
		else:
			print(strzero + strone)
	elif one == 0:
		if B > zero > 0:
			print(strzero + '0')
		elif zero == 0:
			print('0')
		else:
			print(strzero)
	elif zero == 0:
		if 0 < one < B:
			print('0' + strone)
		elif one == 0:
			print('0')
		else:
			print(strone)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def inar():
	return list(map(int, input().split()))
Testcase = inin()
for _ in range(Testcase):
	n = inin()
	s = input()
	cnt0 = 0
	cnt1 = 0
	ph1 = -1
	ph0 = -1
	i = 0
	while i < n:
		if ph1 == -1:
			if s[i] == '0':
				cnt0 += 1
			else:
				ph1 = i
		if s[i] == '0':
			ph0 = i
			cnt1 = 0
		else:
			cnt1 += 1
		i += 1
	ad = ''
	if ph1 < ph0 and ph1 != -1 and (ph0 != -1):
		ad = '0'
	print('0' * cnt0 + ad + '1' * cnt1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = input()
	(pre, suf) = (0, 0)
	zero = ''
	ones = ''
	for i in range(n):
		if arr[i] == '0':
			zero += '0'
		elif arr[i] == '1':
			pre = i
			break
	for j in reversed(range(n)):
		if arr[j] == '1':
			ones += '1'
		else:
			suf = n - j - 1
			break
	if len(zero) + len(ones) == n:
		print(zero + ones)
	elif n == 1:
		print(arr)
	else:
		print(zero + '0' + ones)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
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))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		i = 0
		while i < n and s[i] == '0':
			i += 1
		ans1 = '0' * i
		j = n - 1
		while j > -1 and s[j] == '1':
			j -= 1
		ans3 = '1' * (n - j - 1)
		s = s.rstrip('1').lstrip('0')
		if s:
			ans = ans1 + '0' + ans3
		else:
			ans = ans1 + ans3
		print(ans)
solve()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().rstrip('\n')
	(l, r) = (-1, -1)
	MODE = True
	for i in range(n):
		if MODE:
			if s[i] == '1':
				l = i
				MODE = False
		elif s[i] == '0':
			r = i
	if l == -1 or r == -1:
		print(s)
	else:
		ans = s[0:l] + '0' + s[r + 1:]
		print(ans)


def solve():
	n = int(input())
	s = input()
	w = list(s)
	(firsto, lastz) = (-1, -1)
	for i in range(n):
		if s[i] == '1' and firsto == -1:
			firsto = i
		if s[i] == '0' and firsto != -1:
			lastz = i
	if firsto != -1 and lastz != -1:
		print(s[:firsto] + s[lastz:])
	else:
		print(s)
for _ in range(int(input())):
	solve()


import re
max_int = 1000000001
min_int = -max_int
t = int(input())
for _t in range(t):
	n = input()
	s = input()
	for l in range(0, len(s)):
		if s[l] == '1':
			break
	for r in range(len(s) - 1, -1, -1):
		if s[r] == '0':
			break
	if l < r:
		print(s[:l] + '0' + s[r + 1:])
	else:
		print(s)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	l = list(s)
	if sorted(l) == l:
		print(s)
	else:
		c0 = 0
		c1 = 0
		j = 0
		k = n - 1
		while l[j] == '0' and j < n:
			c0 += 1
			j += 1
		while l[k] == '1' and k >= 0:
			c1 += 1
			k -= 1
		print('0' * c0 + '0' + '1' * c1)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ans = ''
	c0 = s.find('1')
	c1 = s.rfind('0')
	ans += '0' * c0
	if '10' in s[c0:c1 + 1]:
		ans += '0'
	ans += '1' * (n - c1 - 1)
	if c0 == -1 or c1 == -1:
		ans = s
	print(ans)


def solve(s):
	front = s[0]
	(c1, c2) = (1, 1)
	back = s[-1]
	n = len(s)
	for i in range(1, len(s)):
		if s[i] != front:
			break
		c1 += 1
	for i in range(len(s) - 2, -1, -1):
		if c1 + c2 > n:
			return s
		if s[i] != back:
			break
		c2 += 1
	if c1 + c2 > n:
		return s
	if c1 + c2 == n:
		if front == '0':
			return s
		else:
			return '0'
	if front == '1' and back == '0':
		return back
	if front == '1' and back == '1':
		return '0' + c2 * '1'
	if front == '0' and back == '1':
		return '0' * (c1 + 1) + '1' * c2
	else:
		return '0' * (c1 + 1)
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	print(solve(s))


n = int(input())
for i2 in range(n):
	k = int(input())
	s = input()
	dem = 0
	s3 = ''
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			dem += 1
	if dem == 0:
		s3 = s
	else:
		if s[len(s) - 1] == '1':
			j = len(s) - 1
			while j > -1 and s[j] == '1':
				s3 = s3 + '1'
				j -= 1
			if dem > 1:
				s3 = '0' + s3
		else:
			s3 = '0'
		if s[0] == '0':
			for r in range(len(s)):
				if s[r] == '0':
					s3 = '0' + s3
				else:
					break
	print(s3)


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	a = [str(x) for x in s]
	i = 0
	if n == 1:
		print(s)
	else:
		ans = []
		k = 0
		while k < n and a[k] == '0':
			ans += ['0']
			k += 1
		k -= 1
		for i in range(n - 1, -1, -1):
			if a[i] == '0':
				break
		if i == k:
			i += 1
		for j in range(i, n):
			ans += [a[j]]
		if len(ans) == 0:
			ans = [a[0]]
		for i in range(len(ans)):
			print(ans[i], end='')
		print()


tc = int(input())
for ctr in range(tc):
	n = int(input())
	a = list(input().strip())
	if sorted(a) == a:
		print(''.join(a))
	else:
		zero = a.index('1')
		zero += 1
		a = a[::-1]
		one = a.index('0')
		print('0' * zero + '1' * one)


from sys import stdin, stdout
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()
import math

def p(a):
	print(' '.join(list(map(str, a))))
from collections import Counter

def solve():
	n = IN()
	s = S()
	c0 = 0
	c1 = 0
	for i in range(n):
		if s[i] == '1':
			break
	c0 = i
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			break
		c1 += 1
	if c0 + c1 == n:
		print(s)
	else:
		print('0' * c0 + '0' + '1' * c1)
for i in range(IN()):
	solve()


for _ in range(int(input())):
	a = int(input())
	b = input()
	if len(set(b)) > 1:
		q = b.index('1')
		c = a - b[::-1].index('0')
		if c == q:
			print(b)
		else:
			print(b[:q] + '0' + b[c:])
	else:
		print(b)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	one = 0
	zeo = n - 1
	for i in range(n):
		if s[i] == '1':
			break
		one += 1
	for i in range(n - 1, one, -1):
		if s[i] == '0':
			break
		zeo -= 1
	if one == n:
		zeo += 1
	print(s[:one] + s[zeo:])


def solve():
	N = int(input())
	binary = input()
	if binary.count('0') == 0 or binary.count('1') == 0:
		return binary
	i = 0
	ans = ''
	while i < N and binary[i] == '0':
		ans += '0'
		i += 1
	j = N - 1
	while j > i and binary[j] == '1':
		j -= 1
	if i == j:
		ans += binary[j:]
		return ans
	ans += '0'
	ans += binary[j + 1:]
	return ans

def main():
	for _ in range(int(input())):
		print(solve())
main()


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	s1 = ''
	flag = 0
	s2 = ''
	for j in range(n - 1, -1, -1):
		if s[j] == '1':
			s2 = ''
			if flag == 0:
				s1 += s[j]
		elif flag == 0:
			s1 += s[j]
			flag = 1
		else:
			s2 += s[j]
	s1 += s2
	print(s1[::-1])


tt = int(input())
while tt != 0:
	n = int(input())
	s = list(input())
	p = 0
	t = 0
	(l1, l2) = (0, 0)
	while t < n and s[t] == '0':
		p += 1
		t += 1
	l1 = t - 1
	t = n - 1
	q = 0
	while t >= 0 and s[t] == '1':
		q += 1
		t -= 1
	l2 = t + 1
	if abs(l1 - l2) > 1:
		p += 1
	print('0' * p + '1' * q)
	tt -= 1


for _ in range(int(input())):
	n = int(input())
	s = input()
	while True:
		temp0 = s.replace('100', '10')
		temp1 = temp0.replace('110', '10')
		temp2 = temp1.replace('1010', '10')
		if temp2 == s:
			print(s.replace('10', '0'))
			break
		else:
			s = temp2


for _ in range(0, int(input())):
	n = int(input())
	string = input()
	last_zero = -1
	first_one = -1
	count = 0
	for i in reversed(range(n)):
		if string[i] == '0':
			if last_zero == -1:
				last_zero = i
			count += 1
		if count == 2:
			break
	for i in range(n):
		if string[i] == '1':
			first_one = i
			break
	if count == 1:
		print(string[last_zero:])
	elif count == 0:
		print(string)
	elif first_one == -1:
		print(string)
	elif first_one == 0:
		print(string[last_zero:])
	elif first_one > last_zero:
		print(string)
	else:
		print(string[:first_one] + string[last_zero:])


T = int(input())
for t in range(T):
	n = int(input())
	s = input()
	(left, right, same) = (1, 1, 0)
	for i in range(n - 1):
		if s[i] > s[i + 1]:
			same = 1
			break
	if same == 0:
		print(s)
		continue
	for i in range(n):
		if s[i] == '1':
			left = i
			break
	for i in range(n - 1, 0, -1):
		if s[i] == '0':
			right = i
			break
	ans = s[:left] + '0' + s[right + 1:]
	print(ans)


test = int(input())
for _ in range(test):
	n = int(input())
	bits = list(input())
	ones = -1
	zero = -1
	for i in range(n):
		if bits[i] == '1' and ones == -1:
			ones = i
		elif bits[i] == '0':
			zero = i
	if ones < zero:
		a = ''.join(bits[:ones])
		b = ''.join(bits[zero:])
		print(a + b)
	else:
		print(''.join(bits))


for item in [0] * int(input()):
	n = int(input())
	stri = input()
	zero = 0
	one = 0
	for item in stri:
		if item == '0':
			zero += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if stri[i] == '1':
			one += 1
		else:
			break
	if one + zero == n:
		print(stri)
	else:
		print(''.join((str(ele) for ele in [0] * zero + [0] + [1] * one)))


t = int(input())
for q in range(t):
	n = int(input())
	s = input()
	ans = ''
	r = 0
	ind = 0
	for i in range(n):
		if s[i] == '0' and r == 0:
			ans += s[i]
		if s[i] == '1':
			r = 1
			ind = i
			break
	if r != 0:
		r = ind
		ind += 1
		e = 0
		l = -1
		while ind < n:
			if s[ind] == '0':
				l = ind
			ind += 1
		if l == -1:
			l = r
		ans += s[l:n]
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	ans = ''
	i = 0
	while s[i] == '0':
		ans += '0'
		i += 1
		if i == n:
			break
	j = n - 1
	end = ''
	while s[j] == '1':
		end += '1'
		j -= 1
		if j < 0:
			break
	if i != j + 1:
		ans += '0'
	ans += end
	print(ans)


t = int(input())
for testcase in range(t):
	n = int(input())
	s = input()
	ok = 0
	indx = -1
	c = 0
	s2 = ''
	s1 = ''
	for i in range(len(s)):
		if s[i] == '0':
			s2 += '0'
			c += 1
		else:
			ok = 1
			indx = i
			break
	if ok == 0:
		print(s2 + '\n')
		continue
	ok = 0
	indx1 = -1
	for i in reversed(range(len(s))):
		if s[i] == '1':
			s1 += '1'
			c += 1
		else:
			ok = 1
			indx1 = i
			break
	if c == n:
		print(s2 + s1 + '\n')
		continue
	print(s2 + '0' + s1 + '\n')


t = int(input())
while t > 0:
	n = int(input())
	string = input()
	c = 0
	res = ''
	i = n - 1
	while string[i] == '1' and i >= 0:
		res += string[i]
		i -= 1
	while i >= 0:
		if c == 1:
			if string[i] == '0':
				c += 1
				i -= 1
			else:
				i = i - 1
		elif string[i] == '0':
			c += 1
			i -= 1
		else:
			c = 1
			i -= 1
	s = ''
	for _ in range(c):
		s += '0'
	print(s + res)
	t -= 1


t = int(input())
for j in range(t):
	n = int(input())
	s = list(map(int, input()))
	i = n - 1
	if n == 1:
		print(s[0])
	else:
		while i >= 0:
			if i - 1 >= 0 and (s[i] == 0 and s[i - 1] == 1):
				s.pop(i - 1)
				if i - 1 >= 0 and i < len(s) and (s[i] == 0):
					s[i - 1] = 1
				else:
					i -= 1
			else:
				i -= 1
		print(''.join(map(str, s)))


o = int(input())
for _ in range(o):
	n = int(input())
	s = input()
	ind0 = -1
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			ind0 = i
			break
	if ind0 == -1:
		print(s)
	else:
		ind1 = -1
		for i in range(n):
			if s[i] == '1':
				ind1 = i
				break
		if ind1 == -1:
			print(s)
		elif ind1 >= ind0:
			print(s)
		else:
			ans = ''
			for i in range(ind1):
				ans += s[i]
			for i in range(ind0, n):
				ans += s[i]
			print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = []
	j = []
	for i in s:
		l.append(i)
		j.append(i)
	j.sort()
	if l == j:
		print(s)
		continue
	if s.count('1') == n:
		print(s)
	elif s.count('0') == n:
		print(s)
	else:
		f1 = s.index('1')
		g = s[::-1]
		f2 = g.index('0')
		ans = ''
		ans += (f1 + 1) * '0'
		ans += f2 * '1'
		print(ans)


import sys
import math

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

def iinput():
	return int(input())

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

def listinput():
	return list(map(int, sys.stdin.readline().strip().split()))
for _ in range(iinput()):
	n = iinput()
	s = input()
	(first_one, first_zero_from_last) = (-1, -1)
	if '1' in s:
		first_one = s.index('1')
	k = list(map(str, s))
	k.reverse()
	if '0' in s:
		first_zero_from_last = k.index('0')
	if first_one == -1 or first_zero_from_last == -1:
		print(s)
	elif first_one + first_zero_from_last == len(s):
		print(s)
	else:
		print('0' * (first_one + 1) + '1' * first_zero_from_last)


t = int(input())
for a in range(t):
	n = input()
	s = input()
	l = 1
	r = 1
	q = 0
	for i in range(len(s) - 1):
		if s[i] > s[i + 1]:
			q = 1
			break
	if q == 0:
		print(s)
		continue
	for i in range(len(s)):
		if s[i] == '1':
			l = i
			break
	for i in range(len(s) - 1, 0, -1):
		if s[i] == '0':
			r = i
			break
	s = s[:l] + '0' + s[r + 1:]
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(input())
	i = 0
	ans = []
	while i < n and l[i] == '0':
		ans.append('0')
		i += 1
	if '0' in l[i:]:
		ans.append('0')
	i = n - 1
	while i >= 0 and l[i] == '1':
		ans.append('1')
		i -= 1
	print(''.join(ans))


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	n = int(input())
	s = input().rstrip()
	if '1' not in s:
		print(s + '\n')
		continue
	elif '0' not in s:
		print(s + '\n')
		continue
	lastZ = n - s[::-1].find('0') - 1
	firstO = s.find('1')
	if lastZ < firstO:
		print(s + '\n')
		continue
	zero = ''
	one = ''
	for i in s:
		if i == '1':
			break
		else:
			zero += '0'
	for i in s[::-1]:
		if i == '0':
			break
		else:
			one += '1'
	ans = zero + '0' + one
	print(ans + '\n')


def solve():
	n = int(input())
	st = input()
	pref0 = 0
	for i in st:
		if i == '0':
			pref0 += 1
		else:
			break
	post1 = 0
	for i in st[::-1]:
		if i == '1':
			post1 += 1
		else:
			break
	if n != post1 + pref0:
		print(pref0 * '0' + '0' + post1 * '1')
	else:
		print(pref0 * '0' + post1 * '1')
for i in range(int(input())):
	solve()


for _ in range(int(input())):
	len = int(input())
	st = input()
	new_st = ''
	for i in range(len - 1):
		if st[i] > st[i + 1]:
			break
	else:
		print(st)
		continue
	for i in range(len - 1):
		if st[i] == '1':
			break
		new_st += st[i]
	new_st += '0'
	for i in range(len - 1, 0, -1):
		if st[i] == '0':
			break
		new_st += st[i]
	print(new_st)


for _ in range(int(input())):
	n = int(input())
	s = input('')
	x = -1
	y = -1
	ans = ''
	for i in range(n):
		if s[i] == '1':
			x = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			y = i
			break
	if x == -1 or y < x:
		ans = s
	elif x >= 0 and y >= 0:
		ans = s[:x] + s[y:]
	elif x >= 0:
		ans = s[:x]
	elif x == 0:
		ans = s[0]
	print(ans)


for test in range(int(input())):
	input()
	x = input()
	x1 = x.split('1')[0] + x.split('0')[-1]
	if len(x1) < len(x):
		print('0' + x1)
	else:
		print(x1)


t = int(input())
for i in range(t):
	n = int(input())
	x = input()
	j = n - 1
	count = 0
	count1 = 0
	while j >= 1:
		if x[j] == '0' and x[j - 1] == '1':
			if x[:j - 1].count('1') >= 1:
				for k in range(len(x[:j - 1])):
					if x[k] == '0':
						count1 += 1
					else:
						break
				if len(x[j + 1:]) == x[j + 1:].count('1'):
					print('0' * count1, end='')
					print(x[j:])
				elif len(x[j + 1:]) != x[j + 1:].count('0'):
					print('0' * count1 + '0', end='')
					print('1' * x[j + 1:].count('1'))
				else:
					print('0' * count1 + '0')
			elif len(x[j + 1:]) == x[j + 1:].count('1'):
				print('0' * x[:j + 1].count('0'), end='')
				print(x[j + 1:])
			elif len(x[j + 1:]) != x[j + 1:].count('0'):
				print('0' * x[:j + 1].count('0'), end='')
				print('1' * x[j + 1:].count('1'))
			else:
				print('0' * len(x[:j - 1]) + '0')
			count = 1
			break
		j = j - 1
	if count == 0:
		print(x)


t = int(input())
while t > 0:
	size = int(input())
	inp = str(input())
	t -= 1
	flag = 0
	one_ptr = size - 1
	while one_ptr > 0 and inp[one_ptr] == '1':
		one_ptr -= 1
	zer_ptr = 0
	while zer_ptr < size and inp[zer_ptr] == '0':
		zer_ptr += 1
	if inp == '0' or inp == '1':
		print(inp)
	elif zer_ptr > one_ptr:
		print(inp)
	else:
		for i in range(zer_ptr):
			print(inp[i], end='')
		for i in range(one_ptr, size):
			print(inp[i], end='')
		print()


import math
t = int(input())
for w in range(t):
	n = int(input())
	s = input()
	if s == '1':
		print(s)
	elif s.count('0') == 0:
		print(s)
	elif s.count('1') == 0:
		print(s)
	else:
		ans = ''
		l = list(s)
		l1 = sorted(l)
		if l == l1:
			print(s)
		else:
			k = l[::-1].index('0')
			k1 = l.index('1')
			for i in range(k1):
				ans += s[i]
			for i in range(n - k - 1, n):
				ans += s[i]
			print(ans)


t = int(input())
for testcase in range(t):
	n = int(input())
	A = input()
	previousOne = False
	ll = []
	if A[0] == '1':
		previousOne = True
	ll.append(A[0])
	for i in range(1, len(A)):
		previousOne = len(ll) > 0 and (ll[len(ll) - 1] == '1' or ll[len(ll) - 1] == '2')
		if A[i] == '0' and previousOne:
			while previousOne:
				ll = ll[:-1]
				previousOne = len(ll) > 0 and (ll[len(ll) - 1] == '1' or ll[len(ll) - 1] == '2')
			if i + 1 < len(A) and A[i + 1] == '0':
				ll.append('1')
			else:
				ll.append('2')
		elif A[i] == '0':
			ll.append('0')
		else:
			ll.append('1')
	for i in range(len(ll)):
		if ll[i] != '1':
			ll[i] = '0'
	print(''.join(ll))


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = 0
	r = n - 1
	if s.count('0') == n:
		print(s)
		continue
	if s.count('1') == n:
		print(s)
		continue
	while s[l] == '0':
		l += 1
	while s[r] == '1':
		r -= 1
	if r <= l:
		print(s)
		continue
	print(l * '0' + '0' + (n - r - 1) * '1')


t = int(input())
from collections import deque
for case in range(t):
	n = int(input())
	s = input()
	grouped = deque([])
	last = None
	for x in s:
		if x == last:
			grouped[-1] += x
		else:
			last = x
			grouped.append(x)
	if len(grouped) == 1:
		print(s)
		continue
	begin = ''
	if grouped[0][0] == '0':
		begin += grouped[0]
		grouped.popleft()
	end = ''
	if grouped[-1][0] == '1':
		end += grouped[-1]
		grouped.pop()
	assert len(grouped) % 2 == 0
	if len(grouped):
		print(begin + '0' + end)
	else:
		print(begin + end)


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = -1
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			l = i
			break
	if l == -1:
		print(s)
		continue
	j = 0
	while j < l - 1:
		if s[j] == '1' and s[j + 1] == '0':
			s = s[:j + 1] + s[j + 2:]
			l -= 1
		else:
			j += 1
	j = 0
	while j < l:
		if s[j + 1] == '0' and s[j] == '1':
			s = s[:j] + s[j + 1:]
			l -= 1
			if j > 0:
				j -= 1
		else:
			j += 1
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	z = 0
	o = 0
	stay = [0] * n
	for i in range(n):
		if a[i] == '0' and (z == 0 or o == 0):
			stay[i] = 1
			if o == 1:
				z = 1
		elif a[i] == '1':
			o = 1
		else:
			continue
	z = 0
	for i in range(n - 1, -1, -1):
		if a[i] == '1' and z == 0:
			stay[i] = 1
		elif a[i] == '0':
			z = 1
	st = ''
	for i in range(n):
		if stay[i] == 1:
			st += a[i]
	print(st)


import sys
import math
import operator as op
from functools import reduce
from bisect import *
from collections import OrderedDict
from collections import deque

def read_line():
	return sys.stdin.readline()[:-1]

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

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom

def index(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return -1

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return i - 1
	return -1

def find_le(a, x):
	i = bisect_right(a, x)
	if i:
		return i - 1
	return -1

def find_gt(a, x):
	i = bisect_right(a, x)
	if i != len(a):
		return i
	return -1

def find_ge(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return i
	return -1
mod = int(1000000000.0) + 7
mod2 = 998244353
t = read_int()
for i in range(t):
	n = read_int()
	s = read_line()
	t = s[::-1]
	i1 = 0
	i2 = 0
	while i1 < n and s[i1] == '0':
		i1 += 1
	while i2 < n and t[i2] == '1':
		i2 += 1
	if i1 + i2 != n:
		ans = '0' * i1 + '0' + '1' * i2
	else:
		ans = '0' * i1 + '1' * i2
	print(ans)


t = int(input())
for z in range(t):
	n = int(input())
	s = input()
	if '10' not in s:
		print(s)
		continue
	a = s.index('1')
	for i in range(len(s)):
		if s[i] == '0':
			f = i
	l = s[:a] + '0' + s[f + 1:]
	print(''.join(l))


from itertools import groupby as gb
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if s.count('10') == 0:
		print(s)
		continue
	res = ''
	suf = ''
	l = [(k, len(list(v))) for (k, v) in gb(s)]
	if len(l) > 0 and l[0][0] == '0':
		res += l[0][0] * l[0][1]
		l = l[1:]
	if len(l) > 0 and l[-1][0] == '1':
		suf = l[-1][0] * l[-1][1]
		l = l[:-1]
	print(res + '0' + suf)


for _ in range(int(input())):
	d = int(input())
	f = input()
	c = ''
	op = 0
	for i in range(d):
		if f[d - 1 - i] == '0':
			c = '0' + c
			op = d - 1 - i
			break
		else:
			c = c + '1'
	for i in range(d - 1 - i):
		if f[i] == '0':
			c = '0' + c
		else:
			break
	print(c)


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	s = stdin.readline().strip('\n')
	r = ''.join(reversed(s))
	a = s[0]
	for i in range(n - 1):
		if s[i + 1] != s[i]:
			a += s[i + 1]
	if len(a) == 1:
		print(s)
		continue
	if len(a) == 2:
		if a == '10':
			print(0)
		else:
			print(s)
		continue
	ans = ''
	if a[0] == '0':
		ind = s.find('1')
		ans += s[:ind]
		if len(a) % 2 == 1:
			ans += '0'
		else:
			ans += '0'
			ind = r.find('0')
			ans += r[:ind]
		print(ans)
	else:
		if len(a) % 2 == 0:
			ans = '0'
		else:
			ans = '0'
			ind = r.find('0')
			ans += r[:ind]
		print(ans)


num_cases = int(input())
for _ in range(num_cases):
	l = int(input())
	s = input()
	catch: int = 0
	o: int = 0
	for i in range(l - 1, -1, -1):
		if s[i] == '1':
			o += 1
		else:
			break
	for i in range(l):
		if s[i] == '0':
			catch += 1
		else:
			break
	if catch < l - o:
		catch += 1
	print(''.join(['0' for i in range(catch)] + ['1' for j in range(o)]))


import math
import sys
input = sys.stdin.readline
t = int(input())
result = []
for cs in range(t):
	n = int(input())
	s = input().strip()
	first = n
	last = -1
	for i in range(n):
		if s[i] == '0':
			last = i
		if s[i] == '1' and first == n:
			first = i
	if first < last:
		result.append(s[:first] + s[last:])
	else:
		result.append(s)
print('\n'.join(result))


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

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

def fi():
	return int(input())

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')
t = fi()
while t > 0:
	t -= 1
	n = fi()
	s = input().rstrip()
	if s.count('0') == 0 or s.count('1') == 0:
		print(s)
		continue
	p = s.index('1')
	q = n - s[::-1].index('0')
	if p == q:
		print(s)
	else:
		print(s[:p] + '0' + s[q:])


from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *

@lru_cache(None)
def fact(x):
	if x < 2:
		return 1
	return fact(x - 1) * x

@lru_cache(None)
def per(i, j):
	return fact(i) // fact(i - j)

@lru_cache(None)
def com(i, j):
	return per(i, j) // fact(j)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

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

def power2(n):
	while not n & 1:
		n >>= 1
	return n == 1
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	(i, j) = (0, n - 1)
	ans = ''
	while i < n and s[i] == '0':
		i += 1
	ans += '0' * i
	while j >= 0 and s[j] == '1':
		j -= 1
	c1 = n - 1 - j
	if i < j:
		ans += '0'
	ans += '1' * c1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	x = s.rfind('0')
	if x == -1:
		x = 0
	one = 0
	zero = 0
	if s[0] == '1':
		s = s[x:]
	else:
		for i in range(n):
			if s[i] == '0' and i != x:
				zero += 1
			else:
				break
		s = s[:zero] + s[x:]
	print(s)


n = int(input())
while n > 0:
	x = int(input())
	s = input()
	(l, r) = (x - 2, x - 1)
	res = []
	while l >= 0:
		if s[r] == '0':
			if s[l] == '1' and s[l + 1] == '0':
				r = l + 1
		elif s[r] == '1':
			res.append(s[r])
			r -= 1
		l -= 1
	res.append(s[r])
	r -= 1
	while r >= 0:
		if s[r] == '0':
			res.append(s[r])
		r -= 1
	print(''.join(reversed(res)))
	n -= 1


t = int(input())

def case(s, n):
	f = False
	for i in range(n - 1):
		if s[i + 1] < s[i]:
			f = True
	if f:
		(sb, se) = ('', '')
		for i in range(n):
			if s[i] == '0':
				sb += '0'
			else:
				break
		for i in range(n - 1, 0, -1):
			if s[i] == '1':
				se += '1'
			else:
				break
		print(sb + '0' + se)
	else:
		print(s)
for i in range(t):
	n = int(input())
	s = input()
	case(s, n)


import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
input = lambda : sys.stdin.readline()

def solve():
	for _ in range(int(sys.stdin.readline())):
		n = int(sys.stdin.readline())
		s = sys.stdin.readline().replace('\n', '')
		(o, z) = (0, 0)
		for i in range(n):
			if s[i] == '0':
				z += 1
			else:
				break
		for i in range(n - 1, -1, -1):
			if s[i] == '1':
				o += 1
			else:
				break
		if o + z == n:
			print(s)
		else:
			print('0' * (z + 1) + '1' * o)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


import re
for i in range(int(input())):
	n = int(input())
	s = input()
	if '10' not in s:
		print(s)
	else:
		pos1 = s.index('1')
		for i in range(n):
			if s[i] == '0':
				pos0 = i
		print(s[:pos1] + '0' + s[pos0 + 1:])


for i in range(int(input())):
	n = int(input())
	s = input()
	c0 = 0
	for i in range(len(s)):
		if s[i] == '0':
			c0 += 1
		else:
			break
	s = s[::-1]
	c1 = 0
	for i in range(len(s)):
		if s[i] == '1':
			c1 += 1
		else:
			break
	if c0 + c1 == n:
		print(s[::-1])
	else:
		print(c0 * '0' + '0' + c1 * '1')


for t in range(int(input())):
	n = int(input())
	s = list(input())
	p = sorted(s)
	c = 0
	x = 0
	q = p[::-1]
	if p == s:
		for i in p:
			print(i, end='')
		print('')
	elif s == q:
		print(0)
	else:
		a = s[len(s) - 1]
		for i in range(len(s) - 1):
			if s[i] == '0':
				x = i + 1
		i = 0
		while i < len(s):
			if s[i] == '0':
				c = c + 1
				i = i + 1
			else:
				break
		if a == '0':
			for i in range(c):
				print(0, end='')
			print(0)
		else:
			for i in range(c):
				print(0, end='')
			print(0, end='')
			for i in range(len(s) - x):
				print(1, end='')
		print('')


for _ in range(int(input())):
	(__, s) = (input(), input())
	(i, j) = (None, -1)
	for (n, c) in enumerate(s):
		if c == '0':
			j = max(j, n)
		elif i == None:
			i = n
	if i == None or i > j:
		print(s)
	else:
		print(s[:i] + s[j:])


for t in range(int(input())):
	n = int(input())
	s = input()
	(ans, ans1) = ('', '')
	(l, r) = (-1, n + 1)
	for i in range(n):
		if s[i] == '1':
			l = i
			break
		ans += '0'
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			r = i + 1
			break
		ans1 += '1'
	if l == r or l == -1 or r == n + 1:
		print(ans + ans1)
	else:
		print(ans + '0' + ans1)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = list(range(n - 1))
	c = list()
	for j in range(n - 1):
		b[j] = int(a[j + 1]) - int(a[j])
		if b[j] == -1:
			c.append(j)
	if len(c) == 0:
		ans = a
	else:
		ans = '0'
		for k in range(c[0] - 1, -1, -1):
			if b[k] == 1:
				ans = a[:k + 1] + '0'
				break
		for m in range(c[-1] + 1, n - 1):
			if b[m] == 1:
				ans = ans + a[m + 1:]
				break
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = input()
	s1 = ''
	s2 = ''
	c1 = 0
	c2 = 0
	for i in range(n):
		if l[i] == '0':
			s1 += '0'
		else:
			c1 = i
			break
	for i in range(n - 1, -1, -1):
		if l[i] == '1':
			s2 += '1'
		else:
			c2 = i
			break
	s3 = l[c1:c2 + 1]
	if '01' in s3 or '10' in s3:
		print(s1 + '0' + s2)
	else:
		print(s1 + s2)


T = int(input())
for _ in range(T):
	N = int(input())
	S = input()
	pre = ''
	for c in S:
		if c == '1':
			break
		pre += '0'
	suf = ''
	for c in S[::-1]:
		if c == '0':
			break
		suf += '1'
	if len(pre) + len(suf) < N:
		ans = pre + '0' + suf
	else:
		ans = pre + suf
	print(ans)


test = int(input())

def solve():
	n = int(input())
	s = input()
	x = 0
	y = 0
	ok = 0
	for i in range(n - 1):
		if s[i] <= s[i + 1]:
			ok = 1
		else:
			ok = 0
			break
	if ok == 1 or n == 1:
		print(s)
		return
	for i in range(n):
		if s[i] == '0':
			x += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '1':
			y += 1
		else:
			break
	s = ''
	for i in range(x + 1):
		s = s + '0'
	for i in range(y):
		s = s + '1'
	print(s)
while test:
	solve()
	test -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = str(input())
	b = ''
	c = ''
	i = 0
	while a[i] == '0':
		b += '0'
		i += 1
		if i == n:
			break
	if i < n:
		if a[n - 1] == '0':
			b += '0'
		else:
			j = n - 1
			c = ''
			while a[j] == '1':
				j -= 1
				c += '1'
				if j == -1:
					break
			if i - 1 == j:
				b = a
			else:
				b += '0'
				b += c
	print(b)


cases = int(input())
for i in range(cases):
	n = input()
	s = input()
	l = 0
	r = len(s) - 1
	countz = 0
	right = 0
	left = 0
	for j in range(len(s)):
		char = s[j]
		if char == '1':
			left = j
			break
		else:
			countz += 1
	counto = 0
	for k in range(len(s) - 1, -1, -1):
		char = s[k]
		if char == '0':
			right = k
			break
		else:
			counto += 1
	if right <= left or counto == len(s) or countz == len(s):
		print(s)
	else:
		ans = ''
		ans += countz * '0'
		ans += '0'
		ans += counto * '1'
		print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	while 1:
		bef = s
		s = s.replace('10', '*')
		s = s.replace('*0', '*')
		s = s.replace('1*', '*')
		s = s.replace('**', '*')
		if s == bef:
			break
		bef = s
	print(s.replace('*', '0'))


for i in range(int(input())):
	a = int(input())
	c = input()
	b = list(c)
	e = []
	j = 0
	if c.count('10') == 0:
		print(c)
	else:
		while b[j] == '0':
			e.append(b[j])
			j += 1
		f = []
		b.reverse()
		k = 0
		while f.count('0') != 1:
			f.append(b[k])
			k += 1
		f.reverse()
		e.extend(f)
		print(''.join(e))


from collections import *
for t in range(int(input())):
	r = int(input())
	s = input()
	(l, n, flag) = (1, 1, True)
	for i in range(0, r - 1):
		if s[i] > s[i + 1]:
			flag = False
			break
	if flag:
		print(s)
		continue
	for i in range(r):
		if s[i] == '1':
			l = i
			break
	for i in range(r - 1, 0, -1):
		if s[i] == '0':
			n = i
			break
	res = s[:l] + '0' + s[n + 1:]
	print(res)


tt = int(input())
for z in range(tt):
	n = int(input())
	s = input()
	c_z = 0
	u = 0
	while u < n:
		if s[u] == '0':
			c_z += 1
			u += 1
		else:
			break
	c_e = 0
	u = n - 1
	while u > -1:
		if s[u] == '1':
			c_e += 1
			u -= 1
		else:
			break
	if c_z + c_e != n:
		c_z += 1
	for i in range(c_z):
		print('0', end='')
	for i in range(c_e):
		print('1', end='')
	print()


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	n = int(sys.stdin.readline())
	s = sys.stdin.readline().strip()
	list_se = [-1, -1]
	for i in range(n):
		if s[i] == '1':
			list_se[0] = i
			break
	for i in range(n - 1, -1, -1):
		if s[i] == '0':
			list_se[1] = i
			break
	if list_se[1] < list_se[0] or list_se[0] == -1 or list_se[1] == -1:
		print(s)
		continue
	res = []
	for i in range(n):
		if i == list_se[0]:
			res.append('0')
		elif i < list_se[0] or i > list_se[1]:
			res.append(s[i])
	print(''.join(res))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	z = -1
	o = -1
	s = list(s)
	res = ''
	for i in range(len(s)):
		if o == -1 and s[i] == '1':
			o = i
		if s[i] == '0':
			z = max(z, i)
	if o > z:
		s = ''.join(s)
		print(s)
	else:
		res = s[:o] + s[z:]
		res = ''.join(res)
		print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	i = 0
	while i < n and s[i] == '0':
		print('0', end='')
		i += 1
	p = i
	i = n - 1
	count = 0
	while i >= 0 and s[i] == '1':
		count += 1
		i -= 1
	if i >= p:
		print('0', end='')
	print(count * '1')