You are given an integer $n$ and an array $a_1, a_2, \ldots, a_n$. You should reorder the elements of the array $a$ in such way that the sum of $\textbf{MEX}$ on prefixes ($i$-th prefix is $a_1, a_2, \ldots, a_i$) is maximized.

Formally, you should find an array $b_1, b_2, \ldots, b_n$, such that the sets of elements of arrays $a$ and $b$ are equal (it is equivalent to array $b$ can be found as an array $a$ with some reordering of its elements) and $\sum\limits_{i=1}^{n} \textbf{MEX}(b_1, b_2, \ldots, b_i)$ is maximized.

$\textbf{MEX}$ of a set of nonnegative integers is the minimal nonnegative integer such that it is not in the set.

For example, $\textbf{MEX}(\{1, 2, 3\}) = 0$, $\textbf{MEX}(\{0, 1, 2, 4, 5\}) = 3$.


-----Input-----

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

The first line of each test case contains a single integer $n$ $(1 \le n \le 100)$.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ $(0 \le a_i \le 100)$.


-----Output-----

For each test case print an array $b_1, b_2, \ldots, b_n$  — the optimal reordering of $a_1, a_2, \ldots, a_n$, so the sum of $\textbf{MEX}$ on its prefixes is maximized.

If there exist multiple optimal answers you can find any.


-----Examples-----

Input
3
7
4 2 0 1 3 3 7
5
2 2 8 6 9
1
0
Output
0 1 2 3 4 7 3 
2 6 8 9 2 
0


-----Note-----

In the first test case in the answer $\textbf{MEX}$ for prefixes will be:

$\textbf{MEX}(\{0\}) = 1$

$\textbf{MEX}(\{0, 1\}) = 2$

$\textbf{MEX}(\{0, 1, 2\}) = 3$

$\textbf{MEX}(\{0, 1, 2, 3\}) = 4$

$\textbf{MEX}(\{0, 1, 2, 3, 4\}) = 5$

$\textbf{MEX}(\{0, 1, 2, 3, 4, 7\}) = 5$

$\textbf{MEX}(\{0, 1, 2, 3, 4, 7, 3\}) = 5$

The sum of $\textbf{MEX} = 1 + 2 + 3 + 4 + 5 + 5 + 5 = 25$. It can be proven, that it is a maximum possible sum of $\textbf{MEX}$ on prefixes.

Difficulty: EASY
Tags: Complete search

Sorting

Data structures

Greedy algorithms
Skill types: Complete search

Sorting

Data structures

Greedy algorithms

Starter code:

Solutions:
def func(arr, n):
	sa = set(arr)
	c = 0
	while c <= max(sa):
		if c not in sa:
			break
		c += 1
	o = [i for i in range(c)]
	cou = {i: 0 for i in sa}
	for i in arr:
		cou[i] += 1
	for i in range(c):
		cou[i] -= 1
	for i in cou:
		o.extend([i for j in range(cou[i])])
	print(' '.join(map(str, o)))
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	func(arr, n)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = sorted(list(set(a)))
	l1 = [m for m in l if a.count(m) > 1]
	k = []
	for p in l1:
		for b in range(a.count(p) - 1):
			k.append(p)
	print(*l + k)


for i in range(int(input())):
	conjunto = set()
	inpt = input()
	lt = []
	for n in list(map(int, input().split())):
		if not n in conjunto:
			conjunto.add(n)
		else:
			lt.append(n)
	rsl = list(conjunto)
	rsl.sort()
	rsl += lt
	print(*rsl)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	a.sort()
	b = [a[0]]
	c = []
	last = -1
	for i in range(1, len(a)):
		if a[i] == b[-1]:
			c.append(a[i])
		else:
			b.append(a[i])
	b.extend(c)
	print(*b, sep=' ')


import sys
T = int(sys.stdin.readline())
for i in range(T):
	N = int(sys.stdin.readline())
	nums = list(map(int, sys.stdin.readline().split()))
	big = max(nums)
	temp = []
	for j in range(big + 1):
		if j in nums:
			temp.append(j)
	for k in range(big + 1):
		if nums.count(k) > 1:
			for l in range(nums.count(k) - 1):
				temp.append(k)
	print(' '.join([str(x) for x in temp]))


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	s = set(arr)
	k = len(s)
	i = 0
	while i < k - 1:
		if arr[i] == arr[i + 1]:
			arr.remove(arr[i])
			arr.append(arr[i])
		else:
			i += 1
	for i in range(n):
		if i == n - 1:
			print(arr[i])
		else:
			print(arr[i], end=' ')


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	s.sort()
	a = [s.pop(0)]
	b = []
	for i in s:
		if i == a[-1]:
			b.append(i)
		else:
			a.append(i)
	print(*a, *b)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(list(set(a)))
	for num in b:
		a.remove(num)
	print(*b + a)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = []
	leftover = []
	for i in range(n):
		if len(b) == 0 or b[-1] != a[i]:
			b.append(a[i])
		else:
			leftover.append(a[i])
	print(*b + leftover)


cases = int(input())
for i in range(cases):
	size = int(input())
	my_list = list(map(int, input().split()))
	my_set = set(my_list)
	result = sorted(list(my_set))
	for yo in result:
		print(yo, end=' ')
	will_remove = []
	for x in my_list:
		if x in my_set:
			my_set.remove(x)
			will_remove.append(x)
	for yes in will_remove:
		my_list.remove(yes)
	for y in my_list:
		print(y, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	arr = sorted([int(x) for x in input().split()])
	res = []
	left = []
	for i in arr:
		if i not in res:
			res.append(i)
		else:
			left.append(i)
	print(' '.join([str(x) for x in res + left]))


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	p = []
	l = []
	c = 0
	d = len(set(a))
	for i in range(n):
		m = min(a)
		if m in l:
			p.append(m)
		else:
			l.append(m)
		a.remove(m)
	l = l + p
	print(*l)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [0] * 101
	for i in l:
		ans[i] += 1
	for i in range(101):
		if ans[i] != 0:
			print(i, end=' ')
			ans[i] -= 1
	for i in range(101):
		if ans[i] == 0:
			continue
		for j in range(ans[i]):
			print(i, end=' ')
	print()


for _ in range(int(input())):
	input()
	arr = sorted(list(map(int, input().split())))
	temp = ''
	temp1 = ''
	for a in arr:
		if str(a) not in temp:
			temp += str(a) + ' '
		else:
			temp1 += str(a) + ' '
	print(temp + temp1)


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	setArray = sorted(set(array))
	countArray = list(map(array.count, setArray))
	while max(countArray) != 0:
		for i in range(len(setArray)):
			if countArray[i] > 0:
				print(setArray[i], end=' ')
				countArray[i] -= 1
	print('')


from collections import *
for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	l.sort()
	for i in l:
		d[i] += 1
	ka = []
	f = 0
	while f == 0:
		f = 1
		for i in d:
			if d[i] > 0:
				ka.append(i)
				d[i] -= 1
				f = 0
	print(*ka)


import sys

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 s1 in range(t):
	n = II()
	l = LI()
	q = []
	ans = []
	l.sort()
	for i in l:
		if i in ans:
			q.append(i)
		else:
			ans.append(i)
	ans += q
	print(*ans)


import math
from collections import deque
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)
	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 < abs(max_ending_here):
			max_so_far = max_ending_here
	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 gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

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

def is_val(h, m, h1, m1):
	s1 = str(h1)
	s2 = str(m1)
	s3 = ''
	s4 = ''
	for i in s1:
		if i not in ['0', '1', '2', '5', '8']:
			return False
	for i in s2:
		if i not in ['0', '1', '2', '5', '8']:
			return False
	for i in s1:
		if i in ['0', '1', '8']:
			s3 += i
		elif i == '2':
			s3 += '5'
		else:
			s3 += '2'
	for i in s2:
		if i in ['0', '1', '8']:
			s4 += i
		elif i == '2':
			s4 += '5'
		else:
			s4 += '2'
	if int(s3[::-1]) < m and int(s4[::-1]) < h:
		return True
	else:
		return False

def main():
	n = int(input())
	l = list(map(int, input().split()))
	f = [-1 for i in range(0, n)]
	d = {}
	l.sort()
	for i in l:
		d[i] = 0
	for i in l:
		d[i] += 1
	f = 0
	while f == 0:
		for j in d:
			if d[j] > 0:
				print(j, end=' ')
				d[j] -= 1
		f = 1
		for j in d:
			if d[j] > 0:
				f = 0
				break
	print()
t = int(input())
for i in range(0, t):
	main()


def meximize(array):
	array.sort()
	counter = 0
	for i in range(len(array) - 1):
		while array[i] == array[i + 1] and i < len(array) - counter:
			last_element = array[i + 1]
			array = array[:i + 1] + array[i + 2:]
			array.append(last_element)
			counter += 1
	return array
t = int(input())
for i in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	print(*meximize(array))


import sys
import math
from collections import Counter, defaultdict
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()

def case():
	n = IN()
	a = LI()
	d = Counter(a)
	i = 0
	while n:
		if d[i]:
			print(i, end=' ')
			d[i] -= 1
			n -= 1
		i += 1
		i %= 101
	print()
for _ in range(IN()):
	case()


for _ in range(int(input())):
	n = int(input())
	c = [0] * 101
	for x in map(int, input().split()):
		c[x] += 1
	a = []
	for i in range(101):
		if c[i]:
			c[i] -= 1
			a += (i,)
	for i in range(101):
		a += [i] * c[i]
	print(*a)


for i in range(int(input())):
	n = int(input())
	b = [0 for i in range(101)]
	a = [int(i) for i in input().split()]
	for i in a:
		b[i] += 1
	for i in range(101):
		if b[i] > 0:
			print(i, end=' ')
			b[i] -= 1
	for i in range(101):
		for j in range(b[i]):
			print(i, end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	v = []
	r = []
	new = list(map(int, input().strip().split()))[:n]
	for j in range(n):
		if new[j] in v:
			r.append(new[j])
		else:
			v.append(new[j])
	v = sorted(v)
	r = sorted(r)
	print(*v + r)


T = int(input())
for _ in range(T):
	n = int(input())
	a = [int(x) for x in input().split()]
	nums = [0 for _ in range(101)]
	for el in a:
		nums[el] += 1
	result = []
	for i in range(101):
		if nums[i] >= 1:
			result += [str(i)]
			nums[i] -= 1
		else:
			break
	for i in range(101):
		while nums[i] >= 1:
			result += [str(i)]
			nums[i] -= 1
	print(' '.join(result))


def sol(la):
	la.sort()
	sa = set()
	lb = list()
	rep = list()
	for an in la:
		if an in sa:
			rep.append(str(an))
		else:
			lb.append(str(an))
			sa.add(an)
	lb.extend(rep)
	return ' '.join(lb)

def lec():
	input()
	la = input().split()
	return [int(an) for an in la]

def main():
	nt = int(input())
	for _ in range(nt):
		print(sol(lec()))
main()


t = int(input())
for z in range(t):
	n = int(input())
	inp = [int(i) for i in input().split()]
	freq = {}
	answer = []
	for i in inp:
		if i in freq:
			freq[i] += 1
		else:
			freq[i] = 1
	for i in range(101):
		if i in freq:
			answer.append(i)
			freq[i] -= 1
	for i in range(101):
		if i in freq:
			while freq[i] >= 1:
				answer.append(i)
				freq[i] -= 1
	for i in answer:
		print(i, end=' ')
	print()


t = eval(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	sett = set(arr)
	[arr.remove(i) for i in sett]
	arr1 = list(sett) + arr
	print(*arr1)


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	dic = defaultdict(int)
	for i in l:
		dic[i] += 1
	sort = sorted(dic)
	while dic:
		for i in sort:
			if i in dic:
				print(i, end=' ')
				dic[i] -= 1
				if dic[i] == 0:
					del dic[i]
	else:
		print()


for _ in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	l = list(set(a))
	for i in l:
		a.remove(i)
	print(*l, end=' ')
	print(*a)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	dic = {}
	for i in ar:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	ans = []
	for i in range(n):
		if i in dic and dic[i] != 0:
			ans.append(i)
			dic[i] -= 1
		else:
			break
	for i in dic:
		while dic[i] != 0:
			ans.append(i)
			dic[i] -= 1
	print(*ans)


from math import gcd

def int_input():
	return [int(x) for x in input().split()]
for enumeration in range(int(input())):
	n = int(input())
	used = []
	array = int_input()
	array.sort()
	temp = []
	length = len(array)
	for i in range(length):
		if array[i] in used:
			temp.append(array[i])
		else:
			used.append(array[i])
	array = list(set(array))
	array.sort()
	print(' '.join([str(x) for x in array + temp]))


for _ in range(int(input())):
	input()
	(s, t) = ([], [])
	for i in sorted(list(map(int, input().split(' ')))):
		if i in s:
			t.append(i)
		else:
			s.append(i)
	print(*s + t)


for i in range(int(input())):
	n = int(input())
	spic = sorted(list(map(int, input().split())))
	print(spic[0], end=' ')
	nm = []
	for j in range(1, n):
		if spic[j] != spic[j - 1]:
			print(spic[j], end=' ')
		else:
			nm.append(spic[j])
	print(*nm)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dic = {}
	for i in a:
		if i not in dic:
			dic[i] = 0
		else:
			dic[i] += 1
	b = list(set(a))
	b.sort()
	for i in dic:
		while dic[i] != 0:
			b.append(i)
			dic[i] -= 1
	print(*b)


def answer(n, a):
	a.sort()
	b = [a[0]]
	x = []
	for i in range(1, n):
		if a[i] != b[-1]:
			b.append(a[i])
		else:
			x.append(a[i])
	b.extend(x)
	return ' '.join(map(str, b))

def main():
	t = int(input())
	n = [0] * t
	a = [0] * t
	for j in range(t):
		n[j] = int(input())
		a[j] = [int(i) for i in input().split()]
	for j in range(t):
		print(answer(n[j], a[j]))
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * 101
	for i in a:
		c[i] += 1
	for i in range(101):
		if c[i] > 0:
			print(i, end=' ')
			c[i] -= 1
	for i in range(101):
		while c[i] > 0:
			print(i, end=' ')
			c[i] -= 1
	print()


try:
	for _ in range(int(input())):
		x = int(input())
		a = list(map(int, input().split()))
		b = list(set(a))
		b.sort()
		for i in b:
			for j in a:
				if i == j:
					a.remove(i)
					break
		st = ''
		for i in b:
			st = st + str(i) + str(' ')
		for j in a:
			st = st + str(j) + str(' ')
		print(st)
except:
	pass


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(s) for s in input().split(' ')]
	count = Counter(arr)
	ans = list(sorted(count.keys()))
	for (key, value) in count.items():
		if value == 1:
			continue
		else:
			ans += [key] * (value - 1)
	print(' '.join(map(str, ans)))


import logging
import sys
from inspect import currentframe
input = sys.stdin.readline
logging.basicConfig(level=logging.DEBUG)

def dbg(*args):
	id2names = {id(v): k for (k, v) in currentframe().f_back.f_locals.items()}
	logging.debug(', '.join((id2names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args)))

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	sa = set()
	arr = []
	after = []
	for i in range(n):
		if a[i] in sa:
			after.append(a[i])
		else:
			arr.append(a[i])
			sa.add(a[i])
	ans = arr + after
	print(*ans)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if 0 not in l:
		print(*l)
		continue
	l = sorted(l)
	p = []
	q = []
	j = 0
	while j < n:
		i = l[j]
		t = l.count(i)
		if t > 1:
			for _ in range(t - 1):
				q.append(str(i))
		p.append(str(i))
		j += t
	print(' '.join(p + q))


for _ in range(int(input())):
	n = int(input())
	vals = dict()
	for i in map(int, input().split()):
		if i not in vals:
			vals[i] = 0
		vals[i] += 1
	res = []
	for i in sorted(vals.keys()):
		res.append(i)
		vals[i] -= 1
	for i in vals.keys():
		res += [i] * vals[i]
	print(*list(res))


T = int(input())

def myMethod(ml):
	L = set(ml)
	L = sorted(L)
	ml.sort()
	for j in L:
		ml.remove(j)
	for j in L:
		print(j, end=' ')
	for j in ml:
		print(j, end='  ')
	print('')
while T != 0:
	num = int(input())
	mylist = [int(i) for i in input().split()]
	myMethod(mylist)
	T = T - 1


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	for i in range(len(arr) - 1, 0, -1):
		if arr[i] == arr[i - 1]:
			arr.append(arr.pop(i))
	print(' '.join(list(map(str, arr))))


n = int(input())
for i in range(n):
	y = []
	repetidos = []
	l = int(input())
	x = [int(x) for x in input().split(' ')]
	x.sort()
	for j in range(1, l):
		if x[j] != x[j - 1]:
			y.append(x[j - 1])
		else:
			repetidos.append(x[j - 1])
	if x[l - 1] != x[l - 2]:
		y.append(x[l - 1])
	else:
		repetidos.append(x[l - 1])
	for k in repetidos:
		y.append(k)
	for k in range(len(y) - 1):
		print(y[k], end=' ')
	print(y[len(y) - 1])


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split(' ')))
	a = []
	l.sort()
	s = set(l)
	s = sorted(s)
	for i in s:
		l.pop(l.index(i))
		a.append(i)
	for i in range(len(l)):
		for j in l:
			if l.count(j) != 1:
				a.append(j)
				l.pop(l.index(j))
				break
			else:
				a.append(j)
				l.pop(l.index(j))
	print(*a)


def meximization():
	n = int(input())
	for _ in range(n):
		input()
		items = list(map(int, input().split(' ')))
		items.sort()
		previous = items[0]
		unique = [previous]
		repeated = []
		for i in range(len(items)):
			if i == 0:
				continue
			element = items[i]
			if element == previous:
				repeated.append(element)
			else:
				unique.append(element)
			previous = element
		output = unique + repeated
		print(' '.join(map(str, output)))
meximization()


def solve(arr):
	s = set()
	duplicated = []
	for n in arr:
		if n not in s:
			s.add(n)
		else:
			duplicated.append(n)
	return ' '.join(map(str, sorted(s) + duplicated))
t = int(input())
for _ in range(t):
	n = int(input())
	arr = map(int, input().split())
	print(solve(arr))


for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	x = []
	y = []
	for i in l:
		if i not in x:
			x.append(i)
		else:
			y.append(i)
	for i in sorted(x):
		print(i, end=' ')
	for j in sorted(y):
		print(j, end=' ')
	print('\n', end='')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	count = Counter(arr)
	x = []
	for i in range(n):
		if i == 0:
			x.append(arr[i])
		elif arr[i] != arr[i - 1]:
			x.append(arr[i])
	for i in count:
		if count[i] > 1:
			while count[i] > 1:
				x.append(i)
				count[i] -= 1
	print(' '.join(map(str, x)))


import sys
input = sys.stdin.readline
t = int(input())
for i1 in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	d = {}
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	l2 = []
	l3 = []
	for i in d:
		l2.append(i)
		d[i] -= 1
		while d[i] > 0:
			l3.append(i)
			d[i] -= 1
	l2.sort()
	l4 = l2 + l3
	print(*l4, end='')
	print()


from math import *
from collections import deque
from copy import deepcopy
import sys

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

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

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

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

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

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

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

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

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

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
t = int(inp())
for _ in range(t):
	n = int(inp())
	a = lis()
	hashy = {}
	for i in a:
		if i not in hashy:
			hashy[i] = 1
		else:
			hashy[i] += 1
	b = set(a)
	c = list(b)
	c.sort()
	for i in c:
		print(i, end=' ')
	rema = []
	for i in b:
		if hashy[i] > 1:
			for j in range(hashy[i] - 1):
				rema.append(i)
	for i in rema:
		print(i, end=' ')
	print()


num = int(input())
for i in range(num):
	y = []
	repetidos = []
	l = int(input())
	Arr = [int(x) for x in input().split(' ')]
	Arr.sort()
	for j in range(1, l):
		if Arr[j] != Arr[j - 1]:
			y.append(Arr[j - 1])
		else:
			repetidos.append(Arr[j - 1])
	if Arr[l - 2 + 1] != Arr[l - 3 + 1]:
		y.append(Arr[l - 2 + 1])
	else:
		repetidos.append(Arr[l - 1])
	for k in repetidos:
		y.append(k)
	for k in range(len(y) - 1):
		print(y[k], end=' ')
	print(y[len(y) - 1])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	x = list(set(a))
	x.sort()
	for y in x:
		a[a.index(y)] = -1
	for w in x:
		print(w, end=' ')
	for q in a:
		if q != -1:
			print(q, end=' ')
	print()


for _ in range(int(input())):
	input()
	s = [int(i) for i in input().split()]
	s = sorted(s)
	vis = []
	ans = []
	for i in s:
		if i not in ans:
			ans.append(i)
		else:
			vis.append(i)
	ans += vis
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	b = []
	c = []
	a = list(map(int, input().split()))
	b = sorted(a)
	for i in range(n - 1):
		if b[i] == b[i + 1]:
			c.append(b[i])
	a = set(a)
	a = list(a)
	a = sorted(a)
	print(*a + c, sep=' ')


for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l = sorted(l)
	s = []
	for i in range(n - 1):
		if l[i] == l[i + 1]:
			s.append(l[i])
	st = set(l)
	st = sorted(st)
	print(*st, *s)


from sys import stdin
t = int(input())

def mex(a):
	a.sort()
	if not a:
		return 0
	b = 0
	for i in a:
		if i > b:
			return b
		b = i + 1
	return b
for _ in range(t):
	n = int(next(stdin))
	nums = list(map(int, input().split()))
	s = 0
	nums.sort()
	(x, y) = ([], [])
	for i in nums:
		if i in x:
			y.append(i)
		else:
			x.append(i)
	for i in y:
		x.append(i)
	print(*x)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	d = {}
	(ans, l) = ([], [])
	for i in a:
		if i not in d:
			ans.append(i)
			d[i] = 1
		else:
			l.append(i)
	print(*ans + l)


n = int(input())
for i in range(n):
	j = int(input())
	lista = [int(x) for x in input().split()]
	dictionary = dict()
	for a in lista:
		if dictionary.get(a, 0) == 0:
			dictionary[a] = 1
		else:
			dictionary[a] += 1
	res = sorted(list(set(lista)))
	ans = []
	b = 0
	while b < len(lista):
		for x in res:
			if dictionary[x] > 0:
				ans.append(x)
				dictionary[x] -= 1
				b += 1
	for h in ans:
		print(h, end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	arr.sort()
	nums = []
	rep = []
	f = ''
	for num in arr:
		if num not in nums:
			f += str(num) + ' '
			nums.append(num)
		else:
			rep.append(num)
	for num in rep:
		f += str(num) + ' '
	print(f)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	ans = []
	rem = []
	for i in l:
		if i not in d:
			ans.append(i)
			d[i] = True
		else:
			rem.append(i)
	ans.sort()
	ans += rem
	for i in ans:
		print(i, end=' ')
	print()


import sys
l = sys.stdin.readlines()
i = 0
t = int(l[i].replace('\n', ''))
i = 1
while True:
	t = int(l[i].replace('\n', ''))
	i += 1
	a = [int(x) for x in l[i].replace('\n', '').split()]
	i += 1
	aux = set()
	aux = [x for x in a if x in aux or aux.add(x)]
	a = list(dict.fromkeys(a))
	a.sort()
	ret = ''
	for k in a:
		ret += str(k) + ' '
	for k in aux:
		ret += str(k) + ' '
	print(ret.strip())
	if i == len(l):
		break


rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
from collections import Counter
for _ in range(rn()):
	n = rn()
	a = rl()
	c = Counter(a)
	b = sorted(list(set(a)))
	ans = []
	for i in b:
		ans.append(i)
		c[i] -= 1
	for i in c:
		ans += c[i] * [i]
	print(*ans)


for t in range(int(input())):
	n = int(input())
	k = []
	l = []
	N = list(sorted(map(int, input().split())))
	for i in range(n):
		if N[i] not in k:
			k.append(N[i])
		else:
			l.append(N[i])
	k = k + l
	print(*k)


t = int(input())
for _ in range(t):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	s = []
	print(a[0], end=' ')
	for i in range(1, n):
		if a[i] == a[i - 1]:
			s.append(a[i])
		else:
			print(a[i], end=' ')
	for i in s:
		print(i, end=' ')
	print()


t = int(input())
for j in range(t):
	n = int(input())
	a = input().split(' ')
	for i in range(n):
		a[i] = int(a[i])
	a.sort(key=int)
	i = 0
	aux = []
	while i < len(a) - 1:
		if a[i] == a[i + 1]:
			aux.append(a[i])
			a.pop(i + 1)
		else:
			i += 1
	for i in range(len(a)):
		print(a[i], end=' ')
	for i in range(len(aux)):
		print(aux[i], end=' ')
	print()


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = [int(i) for i in input().split()]
	arr.sort()
	mem = []
	print(arr[0], end=' ')
	for i in range(1, len(arr)):
		if arr[i - 1] == arr[i]:
			mem.append(arr[i])
		else:
			print(arr[i], end=' ')
	print(*mem)


for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	sx = list(sorted(set(x)))
	for i in range(len(sx)):
		x.remove(sx[i])
	print(*sx + x)


for i in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	t.sort()
	p = []
	q = []
	u = {}
	for j in t:
		if j not in u:
			p.append(j)
			u[j] = 1
		else:
			q.append(j)
	print(*p + q)


T = int(input())
for x in range(T):
	n = int(input())
	a = [int(y) for y in input().split()]
	a1 = list(set(a))
	a1.sort()
	for z in a1:
		a.remove(z)
	for p in a1:
		print(p, end=' ')
	for q in a:
		print(q, end=' ')
	print()


for i in range(int(input())):
	n = int(input())
	arr = [int(_) for _ in input().split()]
	l = []
	sarr = sorted(arr)
	j = 0
	while j <= n - 2:
		if sarr[j] == sarr[j + 1]:
			l.append(sarr[j])
			sarr[j] = -1
		j += 1
	sarr = [i for i in sarr if i != -1]
	for val in l:
		sarr.append(val)
	print(*sarr)


import sys
from collections import defaultdict, Counter as CC
from math import sqrt, ceil, floor, log2
INF = float('inf')
MOD = 10 ** 9 + 7
read = lambda : [int(s) for s in sys.stdin.readline().split()]

def solve():
	(n,) = read()
	a = read()
	d = [0] * 101
	for i in a:
		d[i] += 1
	for i in range(101):
		if d[i] > 0:
			d[i] -= 1
			print(i, end=' ')
	for i in range(101):
		if d[i] > 0:
			for j in range(d[i]):
				print(i, end=' ')
	print()
_ = 1
_ = int(input())
while _:
	solve()
	_ -= 1


for i in range(int(input())):
	l = int(input())
	(*a,) = sorted(map(int, input().split()))
	for i in range(l):
		if a.count(a[i]) > 1:
			a += [a.pop(i)]
	print(*a)


def solve(n):
	for i in range(n):
		x = input()
		res = []
		inp = list(map(int, input().split()))
		while len(inp) != 0:
			lst = sorted(set(inp))
			for j in lst:
				inp.remove(j)
			res += lst
		print(*res)
solve(int(input()))


import math
for _ in range(int(input())):
	n = int(input())
	l1 = []
	l2 = []
	l = list(map(int, input().split()))
	l.sort()
	if n == 1:
		print(l[0])
		continue
	for i in range(n - 1):
		if l[i] != l[i + 1]:
			l1.append(l[i])
		else:
			l2.append(l[i])
	print(*l1 + [l[n - 1]] + l2)


for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split(' ')]
	l = sorted(l)
	ml = []
	for i in range(0, n):
		if i == 0:
			print(l[i], end=' ')
		elif l[i] == l[i - 1]:
			ml.append(l[i])
		else:
			print(l[i], end=' ')
	for i in ml:
		print(i, end=' ')
	print()


for _ in range(int(input())):
	input()
	conjunto = set()
	lista = []
	for num in list(map(int, input().split())):
		if not num in conjunto:
			conjunto.add(num)
		else:
			lista.append(num)
	resultado = list(conjunto)
	resultado.sort()
	resultado += lista
	print(*resultado)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = input().split(' ')
	a = [int(x) for x in a]
	u = sorted(list(set(a)))
	count = Counter(a)
	for x in u:
		count[x] -= 1
	for (k, v) in count.items():
		while v > 0:
			u.append(k)
			v -= 1
	print(' '.join([str(x) for x in u]))


def solve(arr, n):
	arr = sorted(arr)
	final = []
	ele = []
	for i in arr:
		if i not in final:
			final.append(i)
		else:
			ele.append(i)
	res = final + ele
	print(*res)
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	solve(a, n)
	t -= 1


import math

def max_cuts(n, a, b, c):
	if n == 0:
		return 0
	elif n < 0:
		return -1
	result = max(max_cuts(n - a, a, b, c), max_cuts(n - b, a, b, c), max_cuts(n - c, a, b, c))
	if result == -1:
		return -1
	return result + 1

def freq(list1):
	freq_count = {}
	for i in list1:
		if i in freq_count:
			freq_count[i] += 1
		else:
			freq_count[i] = 1
	return freq_count
t = int(input())
for t1 in range(t):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	uniq = sorted(list(set(a)))
	for i in uniq:
		a.remove(i)
	ans = uniq + a
	print(*ans)


no_of_test_cases = int(input())

def fun():
	n = int(input())
	lis = input().split(' ')
	a_lis = []
	b_lis = []
	same_num_lis = []
	for i in lis:
		a_lis.append(int(i))
	for l in range(n):
		x = min(a_lis)
		if x in b_lis:
			same_num_lis.append(x)
		else:
			b_lis.append(x)
		a_lis.remove(x)
	b_lis += same_num_lis
	new_lis = []
	for h in b_lis:
		new_lis.append(str(h))
	return new_lis
x = []
y = []
for m in range(no_of_test_cases):
	x = fun()
	y.append(' '.join(x))
for j in y:
	print(j)


def main():
	tests = int(input())
	for i in range(tests):
		N = int(input())
		input_list = [int(i) for i in input().split()]
		reordered_1 = []
		reordered_2 = []
		input_list.sort()
		for i in range(N):
			if i == 0 or input_list[i] != input_list[i - 1]:
				reordered_1.append(input_list[i])
			else:
				reordered_2.append(input_list[i])
		final = reordered_1 + reordered_2
		for i in range(N):
			if i != N - 1:
				print(final[i], end=' ')
			else:
				print(final[i])
main()


tests = int(input())
for _ in range(tests):
	n = int(input())
	numbers = sorted(map(int, input().split()))
	read = dict.fromkeys(numbers)
	for i in read.keys():
		print(i, end=' ')
	for i in range(n):
		number = numbers[i]
		if read[number] is None:
			read[number] = 0
		read[number] = read[number] + 1
	for (key, value) in read.items():
		if value > 1:
			answer = [key] * (value - 1)
			print(*answer, end=' ')
	print()


x = int(input())
for z in range(x):
	n = int(input())
	li1 = list(map(int, input().split()))
	li2 = list(set(li1))
	li2.sort()
	print(*li2, end=' ')
	for i in range(len(li2)):
		li1.remove(li2[i])
	print(*li1)


for i in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	b = [0] * 101
	for x in l:
		b[x] += 1
	for i in range(101):
		if b[i] > 0:
			print(i, end=' ')
			b[i] -= 1
	for i in range(101):
		if b[i] > 0:
			t = b[i]
			for j in range(t):
				print(i, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	arr.sort()
	seen = set()
	diff = []
	res = []
	for i in arr:
		if i not in seen:
			res.append(i)
			seen.add(i)
		else:
			diff.append(i)
	res = res + diff
	print(*res)


def main():
	t = int(input())
	output = []
	for i in range(t):
		(n, b) = (int(input()), [])
		a = sorted(list(map(int, input().split())))
		for i in range(n):
			if i == 0 or a[i] != a[i - 1]:
				b.append(a[i])
		for i in range(n):
			if i > 0 and a[i] == a[i - 1]:
				b.append(a[i])
		output.append(b)
	for i in range(len(output)):
		print(*output[i])
main()


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		d = Counter(a)
		sd = []
		for i in d:
			if d[i] > 1:
				sd.append(i)
		sd.sort()
		s = sorted(list(set(a)))
		for i in sd:
			for j in range(d[i] - 1):
				s.append(i)
		for i in s:
			print(i, 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()


def meximization():
	n = int(input())
	for _ in range(n):
		a = int(input())
		numbers = [int(i) for i in input().split()]
		numbers.sort()
		result = []
		result_final = []
		if numbers[0] > 0:
			print(' '.join((str(e) for e in numbers)))
		else:
			ant = numbers[0]
			at = -1
			len_num = len(numbers) - 1
			i = 0
			result.append(ant)
			while i < len_num:
				i += 1
				at = numbers[i]
				if at - ant == 0:
					result_final.append(numbers[i])
				else:
					result.append(numbers[i])
				ant = at
			result = result + result_final
			print(' '.join((str(e) for e in result)))
meximization()


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	cnt = defaultdict(lambda : 0)
	res = []
	for j in b:
		cnt[j] += 1
	req = sorted(list(set(b)))
	l = 0
	j = 0
	l1 = len(req)
	while l < n:
		curr = req[j % l1]
		if cnt[curr] == 0:
			pass
		else:
			res.append(curr)
			cnt[curr] += -1
			l += 1
		j += 1
	print(*res)


t = int(input())
while t > 0:
	t -= 1
	d = {}
	n = int(input())
	ip = input()
	arr = ip.split()
	for num in arr:
		num = int(num)
		if num not in d:
			d[num] = 1
		else:
			d[num] += 1
	ans = []
	size = 0
	while size < n:
		temp = []
		for (no, freq) in d.items():
			if d[no] > 0:
				temp.append(no)
				d[no] -= 1
		ans += sorted(temp)
		size += len(temp)
	print(*ans)


def printList(lst):
	if len(lst) > 0:
		print(f'{lst[0]}', end='')
	for i in lst[1:]:
		print(f' {i}', end='')
	print()
number_tests = int(input().strip())
for _ in range(number_tests):
	n = int(input().strip())
	a = [int(i) for i in input().strip().split()]
	final = []
	repeated = []
	a.sort()
	last = -1
	for i in a:
		if i == last:
			repeated.append(i)
		else:
			final.append(i)
		last = i
	printList(final + repeated)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = []
	d = []
	for j in a:
		if j not in b:
			b.append(j)
		else:
			d.append(j)
	b.extend(d)
	print(*b)


def get_input():
	t = int(input())
	data = []
	for _ in range(t):
		n = int(input())
		arr = [int(x) for x in input().split()]
		data.append((n, arr))
	return data

def mex(arr):
	arr = set(arr)
	mex = 0
	while mex in arr:
		mex += 1
	return mex

def find_max_mex(arr_a, arr_b):
	max_mex = -1
	max_mex_index = -1
	for i in range(len(arr_a)):
		cur_mex = mex(arr_b + [arr_a[i]])
		if cur_mex > max_mex:
			max_mex = cur_mex
			max_mex_elem_index = i
	return max_mex_elem_index

def find_max_mex_sum_array(arr_a):
	arr_b = []
	while len(arr_a):
		max_mex_index = find_max_mex(arr_a, arr_b)
		arr_b.append(arr_a.pop(max_mex_index))
	return arr_b

def solve():
	data = get_input()
	for unit in data:
		(n, arr) = unit
		max_sum = find_max_mex_sum_array(arr)
		print(''.join([str(x) + ' ' for x in max_sum]).rstrip())
solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(set(a))
	for i in range(len(b)):
		if a.count(b[i]) > 1:
			for k in range(a.count(b[i]) - 1):
				b.append(b[i])
	print(*b)


from re import X

def sumOfMex(c):
	d = dict()
	x = 0
	s = 0
	for i in range(len(c)):
		d[c[i]] = 1
		while x in d.keys():
			x += 1
		s += x
		print(' MEX{} = {}'.format(c[:i + 1], x))
	return s

def mex(c):
	x = 0
	d = dict()
	for i in range(len(c)):
		d[c[i]] = 1
		while x in d.keys():
			x += 1
	return x

def main():
	test_cases = int(input())
	for _ in range(test_cases):
		n = int(input())
		v = [int(x) for x in input().split(' ')]
		m = mex(v)
		ans = []
		for i in range(m):
			ans.append(i)
			v.remove(i)
		ans.extend(v)
		print(' '.join([str(character) for character in ans]))
main()


import math
import bisect
import copy
from collections import defaultdict
from collections import OrderedDict
from sys import stdout
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ar.sort()
	chk = [0] * n
	freq = {}
	ans = []
	for i in range(n):
		if ar[i] not in freq:
			freq[ar[i]] = 1
		else:
			freq[ar[i]] += 1
	while len(ans) < n:
		for i in freq.keys():
			if freq[i] > 0:
				ans.append(i)
				freq[i] -= 1
	print(*ans)


def solve():
	t = int(input().strip())
	for _ in range(t):
		_ = input()
		original = list(map(int, input().strip().split(' ')))
		original = sorted(original)
		added = set()
		answer = []
		to_end = []
		for x in original:
			if x not in added:
				answer.append(x)
				added.add(x)
			else:
				to_end.append(x)
		answer += to_end
		print(*answer)
solve()


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	c = [a[0]]
	k = 0
	d = []
	for i in range(1, n):
		if c[k] != a[i]:
			c.append(a[i])
			k += 1
		else:
			d.append(a[i])
	print(*c, *d)


t = int(input())
for i in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	conjunto = sorted(set(array))
	for num in conjunto:
		array.remove(num)
	array = list(conjunto) + array
	print(*array)


t = int(input())
for i in range(t):
	n = int(input())
	m = [int(j) for j in input().split()]
	m.sort()
	res = 0
	c = 0
	new = sorted(list(set(m)))
	for j in new:
		m.remove(j)
	print(' '.join([str(k) for k in new + m]))


from collections import Counter

def mex(n, arr):
	data = Counter(arr)
	ele = list(data.keys())
	ele.sort()
	ans = []
	for i in range(len(ele)):
		ans.append(ele[i])
		data[ele[i]] -= 1
	for i in range(len(ele)):
		if data[ele[i]] != 0:
			for j in range(data[ele[i]]):
				ans.append(ele[i])
	print(*ans, end=' ')
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	mex(n, arr)
	print('')


def dedup(lst):
	mx = max(lst) + 1
	dupcnt = 0
	delcnt = 0
	start = 0
	for i in range(1, len(lst) + 1):
		if i == len(lst) or lst[i] != lst[start]:
			lst[start - delcnt] = lst[start] + dupcnt * mx
			delcnt += dupcnt
			start = i
			dupcnt = 0
		else:
			dupcnt += 1
	dupidx = len(lst) - delcnt
	for i in range(0, len(lst) - delcnt):
		dupcnt = lst[i] // mx
		if dupcnt:
			lst[i] %= mx
			for j in range(dupidx, dupidx + dupcnt):
				lst[j] = lst[i]
			dupidx += dupcnt
	return lst
t = int(input())
while t > 0:
	n = int(input())
	lst = [int(x) for x in input().split()]
	lst.sort()
	lst2 = dedup(lst)
	for i in range(n):
		print(lst2[i], end=' ')
	print(end='\n')
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = [a[0]]
	for i in range(1, n):
		if a[i - 1] != a[i]:
			b.append(a[i])
	for i in range(1, n):
		if a[i - 1] == a[i]:
			b.append(a[i])
	print(*b)


def solve():
	lis = []
	li = []
	k = int(input())
	lis = [int(x) for x in input().split()]
	lis.sort()
	b = []
	if k == 1:
		print(lis[0])
		return
	for i in lis:
		if i not in b:
			b.append(i)
	for i in range(1, k):
		if lis[i - 1] == lis[i]:
			b.append(lis[i])
	for i in b:
		print(i, end=' ')
n = int(input())
for i in range(n):
	solve()


t = int(input())
for i in range(t):
	n = input()
	l = map(int, input().split())
	s = sorted(l)
	ans1 = []
	ans2 = []
	d = {}
	for j in s:
		if j in d:
			ans2.append(str(j))
		else:
			d[j] = True
			ans1.append(str(j))
	print(' '.join(ans1 + ans2))


def Solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = {}
	c = []
	for i in range(len(a)):
		if b.get(a[i]) != None:
			c.append(a[i])
		else:
			b[a[i]] = 1
			print(a[i], end=' ')
	for i in c:
		print(i, end=' ')
	print()
q = int(input())
while q:
	Solve()
	q -= 1


import sys

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

def mex(a, i):
	for j in range(1, 10000):
		if all((j != a[k] for k in range(i))):
			return j

def slv():
	n = int(input())
	a = list(map(int, input().split()))
	seen = [False] * 200
	a.sort()
	b = []
	ans = []
	for v in a:
		if seen[v] == False:
			ans.append(v)
			seen[v] = True
		else:
			b.append(v)
	ans += b
	print(*ans)

def main():
	t = int(input())
	for i in range(t):
		slv()
	return
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	res = []
	print(a[0], end=' ')
	for i in range(1, n):
		if a[i] == a[i - 1]:
			res.append(a[i])
		else:
			print(a[i], end=' ')
	for i in res:
		print(i, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	for i in range(n - 1):
		if l[i] == l[i + 1]:
			l.append(l[i + 1])
	lst = l[n:]
	lst = list(sorted(set(l[0:n]))) + lst
	print(*lst)


t = int(input())
for asasd in range(t):
	n = int(input())
	con = [int(i) for i in input().split()]
	res = []
	sobr = []
	con.sort()
	for i in con:
		if i in res:
			sobr.append(i)
		else:
			res.append(i)
	res.extend(sobr)
	for i in res:
		print(i, end=' ')
	print('')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [0] * 101
	a.sort()
	for x in a:
		b[x] += 1
	ans1 = []
	ans2 = []
	for i in range(101):
		if b[i] > 0:
			ans1.append(i)
			ans2 += [i] * (b[i] - 1)
	print(*ans1 + ans2)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()[:n]))
	arr = sorted(arr)
	new = []
	new2 = []
	for i in range(len(arr)):
		if arr[i] not in new:
			new.append(arr[i])
		else:
			new2.append(arr[i])
	print(*new + new2)


def fun():
	from collections import defaultdict
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		arr.sort()
		ans = []
		from collections import defaultdict
		while arr:
			lis = []
			dic = defaultdict(int)
			n = len(arr)
			arr.sort()
			for i in range(n):
				if dic[arr[i]] == 0:
					ans.append(arr[i])
				else:
					lis.append(arr[i])
				dic[arr[i]] += 1
			arr = lis.copy()
		print(*ans)
fun()


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = set(arr)
	b = list(s)
	b.sort()
	for i in range(len(b)):
		val = arr.count(b[i]) - 1
		for j in range(val):
			b.append(b[i])
	print(*b)


t = int(input())
for i in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	freq = {}
	for j in range(n):
		if array[j] in freq:
			freq[array[j]] += 1
		else:
			freq[array[j]] = 0
	array = set(array)
	array = list(array)
	array.sort()
	for j in range(n):
		if freq[array[j]] >= 1:
			array.append(array[j])
			freq[array[j]] -= 1
	print(*array)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = sorted(map(int, input().split()))
		b = []
		ans = []
		p = -1
		for x in a:
			if x == p:
				b.append(x)
			else:
				ans.append(x)
				p = x
		ans.extend(b)
		print(*ans)
main()


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	i = 0
	f = False
	ans = []
	temp = []
	while i < len(a):
		if i == 0:
			ans.append(a[i])
		elif a[i] == a[i - 1]:
			temp.append(a[i])
		else:
			ans.append(a[i])
		i += 1
	for i in range(len(temp)):
		ans.append(temp[i])
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	zoz = [int(x) for x in input().split()]
	zoz.sort()
	res = []
	pes = []
	res.append(zoz[0])
	for i in range(1, n):
		if zoz[i] != zoz[i - 1]:
			res.append(zoz[i])
		else:
			pes.append(zoz[i])
	res = res + pes
	print(*res)


t = int(input())
for _ in range(t):
	n = int(input())
	numbers = [int(x) for x in input().split()]
	numbers = sorted(numbers)
	new_set = []
	left_out = []
	for num in numbers:
		if num not in new_set:
			new_set.append(num)
		else:
			left_out.append(num)
	for num in new_set:
		print(num, end=' ')
	for num in left_out:
		print(num, end=' ')
	print()


R = lambda : int(input())
S = lambda : [int(a) for a in input().split()]
for _ in range(R()):
	n = R()
	a = S()
	a.sort()
	b = []
	c = []
	for i in range(n):
		if a[i] not in b:
			b.append(a[i])
		else:
			c.append(a[i])
	b.extend(c)
	print(*b)


case = int(input())
for T in range(case):
	n = int(input())
	num = input()
	num = [int(it) for it in num.strip().split()]
	num = sorted(num)
	left = []
	res = []
	for (i, it) in enumerate(num):
		if i == 0:
			res.append(it)
		elif it == num[i - 1]:
			left.append(it)
		else:
			res.append(it)
	last = res + left
	print(' '.join([str(it) for it in last]))


x = int(input(''))
for i in range(x):
	l = []
	a = int(input(''))
	p = input('').split(' ')
	for j in range(a):
		l.append(int(p[j]))
	l.sort()
	print(l[0], end=' ')
	q = []
	for k in range(1, a):
		if l[k] != l[k - 1]:
			print(l[k], end=' ')
		else:
			q.append(l[k])
	for r in q:
		print(r, end=' ')
	print()


from collections import Counter, defaultdict, OrderedDict, deque
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from typing import List
import itertools
import math
import heapq
import string
import random
(MIN, MAX, MOD) = (-1061109567, 1061109567, 1000000007)
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 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())
for _ in range(N()):
	n = N()
	a = RLL()
	res = sorted(set(a))
	c = Counter(a)
	for i in res:
		c[i] -= 1
		if c[i] == 0:
			del c[i]
	for i in c:
		for _ in range(c[i]):
			res.append(i)
	print(*res)


for i in range(int(input())):
	lenn = int(input())
	list1 = list(map(int, input().split()))
	count = [0] * 101
	ans = ''
	for i in list1:
		count[i] += 1
	for i in range(101):
		if count[i] > 0:
			ans += str(i) + ' '
			count[i] -= 1
	for i in range(101):
		for j in range(count[i]):
			ans += str(i) + ' '
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	b = list(set(l))
	b.sort()
	counts = dict()
	for i in l:
		counts[i] = counts.get(i, 0) + 1
	for (x, y) in counts.items():
		if y > 1:
			b.extend([x] * (y - 1))
	print(*b)


try:
	t = int(input())
	while t != 0:
		n = int(input())
		arr = list(map(int, input().split()))
		first = []
		second = []
		d = {}
		for i in arr:
			if i in d:
				d[i] += 1
				second.append(i)
			else:
				first.append(i)
				d[i] = 1
		first.sort()
		final = first + second
		print(*final)
		t -= 1
except EOFError:
	print(' ')


import sys
import bisect
import math
import itertools

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

def in1():
	return int(input())
for _ in range(in1()):
	n = in1()
	a = get_line()
	d = {}
	for i in range(n):
		if a[i] not in d.keys():
			d[a[i]] = 1
		else:
			d[a[i]] += 1
	a1 = sorted(d.keys())
	t1 = sum(d.values()) - len(a1)
	while t1 != 0:
		for i in d.keys():
			if d[i] - 1 > 0:
				a1.append(i)
				d[i] -= 1
				t1 -= 1
	print(*a1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	ans = 0
	arr = list(map(int, input().split()))
	hash_map = {}
	for i in arr:
		if i in hash_map:
			hash_map[i] += 1
		else:
			hash_map[i] = 0
	arr_set = list(set(arr))
	arr_set.sort()
	for i in hash_map:
		if hash_map[i]:
			arr_set += [i] * hash_map[i]
	for i in arr_set:
		print(str(i), end=' ')
	print()


import sys
from math import factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest, nsmallest
from itertools import groupby
from copy import deepcopy
MOD = 10 ** 9 + 7
INF = float('inf')
rl = lambda : list(map(int, sys.stdin.readline().split()))
rs = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	A = rl()
	C = Counter(A)
	ans = [0] * n
	(i, j) = (0, n - 1)
	for c in sorted(C):
		ans[i] = c
		while C[c] > 1:
			ans[j] = c
			j -= 1
			C[c] -= 1
		i += 1
	print(*ans)


for i in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	d = {}
	for i in arr:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	arr = sorted(d.keys())
	temp = []
	for i in arr:
		if d[i] > 1:
			for j in range(1, d[i]):
				temp.append(i)
	arr.extend(temp)
	print(' '.join([str(i) for i in arr]))


while True:
	try:
		t = eval(input())
		for i in range(t):
			n = eval(input())
			a = list(map(int, input().split()))
			a.sort()
			a.insert(0, -1)
			for j in range(1, n + 1):
				if a[j - 1] != a[j]:
					print(a[j], end=' ')
			for j in range(1, n + 1):
				if a[j - 1] == a[j]:
					print(a[j], end=' ')
			print(end='\n')
	except:
		break


from collections import defaultdict

def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	d = defaultdict(lambda : 0)
	for x in a:
		d[x] += 1
	l = list(set(a))
	l.sort()
	x = len(l)
	i = 0
	check = True
	while True:
		if d[l[i]] != 0:
			d[l[i]] -= 1
			print(l[i], end=' ')
			check = False
		if i == x - 1:
			if check:
				break
			else:
				check = True
		i = (i + 1) % x
	print()
t = int(input())
while t:
	t -= 1
	solve()


from sys import stdin, stdout
from collections import defaultdict as dd
import math
input = stdin.readline
flush = stdout.flush
tc = 1
tc = int(input())
for _ in range(tc):
	d = dd(lambda : 0)
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	x = []
	print(l[0], end=' ')
	for i in range(1, n):
		if l[i] == l[i - 1]:
			x.append(l[i])
			continue
		print(l[i], end=' ')
	print(*x)


from io import BytesIO, IOBase
import sys
import math
import os
from collections import defaultdict
from math import ceil
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 mint():
	return map(int, input().split())

def mfloat():
	return map(float, input().split())

def solve():
	m = int(input())
	(*a,) = map(int, input().split())
	d = {}
	for i in a:
		d[i] = d.get(i, 0) + 1
	print(*sorted(d.keys()), end=' ')
	e = []
	for i in d:
		if d[i] > 1:
			e += [i] * (d[i] - 1)
	print(*e)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


cases = int(input())
for i in range(cases):
	length = int(input())
	array = input().split(' ')
	array = list(map(int, array))
	array.sort()
	lastnum = -1
	repetednums = []
	finalarray = []
	for k in range(length):
		if lastnum != array[k]:
			finalarray.append(array[k])
			lastnum = array[k]
		else:
			repetednums.append(array[k])
	finalarray = finalarray + repetednums
	finalarraystring = ''
	for m in range(length):
		finalarraystring += str(finalarray[m]) + ' '
	print(finalarraystring)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = list(set(l))
	d = dict()
	ans = []
	for i in range(n):
		d.setdefault(l[i], 0)
		d[l[i]] += 1
	s.sort()
	ans.extend(s)
	for (q, v) in d.items():
		if v - 1 > 0:
			ans += [q] * (v - 1)
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	s = list(set(arr))
	s.sort()
	ans.extend(s)
	freq = {i: arr.count(i) for i in arr}
	for i in s:
		ans.extend([i] * (freq[i] - 1))
	print(*ans)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = list(set(l))
	x.sort()
	d = dict(Counter(l))
	f = []
	for i in range(len(x)):
		if d[x[i]] > 1:
			for j in range(d[x[i]] - 1):
				f.append(x[i])
	f1 = x + f
	print(*f1)


def meximization(n, a):
	b = []
	i = 0
	while True:
		if i in a:
			b.append(i)
			a.remove(i)
		else:
			break
		i += 1
	b.extend(a)
	return b
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(*meximization(n, a))


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	l.sort()
	nw = []
	print(l[0], end=' ')
	for i in range(1, len(l), 1):
		if l[i] != l[i - 1]:
			print(l[i], end=' ')
		else:
			nw.append(l[i])
	for i in range(len(nw)):
		print(nw[i], end=' ')
	print('\n', end='')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	lst = [-1] * 200
	k = 110
	for i in l:
		if lst[i] == -1:
			lst[i] = i
		else:
			lst[k] = i
			k += 1
	m = []
	for j in lst:
		if j != -1:
			m.append(j)
	print(*m)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [0] * 101
	for i in a:
		b[i] += 1
	for i in range(101):
		if b[i]:
			print(i, end=' ')
			b[i] -= 1
	for i in range(101):
		while b[i]:
			print(i, end=' ')
			b[i] -= 1
	print()


from sys import stdin
input = stdin.readline

def solution():
	N = int(input())
	A = list(map(int, input().split()))
	vst = [False] * 105
	L = []
	R = []
	for a in A:
		if not vst[a]:
			L.append(a)
			vst[a] = True
		else:
			R.append(a)
	print(*sorted(L) + R)
T = int(input())
for _ in range(T):
	solution()


for _ in range(int(input())):
	x = int(input())
	y = list(map(int, input().split()))
	sort = list(sorted(y))
	dupli = []
	nondupli = [sort[0]]
	for i in range(1, x):
		if sort[i] == sort[i - 1]:
			dupli.append(sort[i])
		else:
			nondupli.append(sort[i])
	print(*nondupli + dupli)


user_input = int(input())
for i in range(user_input):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = [0] * n
	b[0] = a[0]
	c = 0
	for i in range(1, n):
		if a[i] == a[i - 1]:
			c += 1
	j = n - c
	k = 1
	for i in range(1, n):
		if a[i] == a[i - 1]:
			b[j] = a[i]
			j += 1
		else:
			b[k] = a[i]
			k += 1
	s = ''
	for i in b:
		s += str(i) + ' '
	print(s)


t = int(input())
for i in range(t):
	n = int(input())
	numbers = input().split(' ')
	numbers = list(map(int, numbers))
	noEqual = []
	equal = []
	for j in numbers:
		if j not in noEqual:
			noEqual.append(j)
		else:
			equal.append(j)
	noEqual.sort()
	equal.sort()
	final = noEqual + equal
	string = ''
	for z in range(n):
		string += str(final[z])
		if z != n - 1:
			string += ' '
	print(string)


import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	arr = [0 for i in range(105)]
	for i in range(n):
		arr[li[i]] += 1
	for i in range(105):
		if arr[i]:
			print(i, end=' ')
			arr[i] -= 1
	for i in range(105):
		for j in range(arr[i]):
			print(i, end=' ')
	print()


import sys

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

def getInt():
	return int(getInput())

def getInts():
	return map(int, getInput().split())

def getArray():
	return list(getInts())
for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	li.sort()
	rep_li = []
	dic = {}
	ans = []
	for i in range(101):
		dic[i] = 0
	for i in li:
		if dic[i] == 1:
			rep_li.append(i)
		else:
			ans.append(i)
			dic[i] = 1
	ans = ans + rep_li
	print(*ans)


t = int(input())
for j in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	lst.sort()
	if len(lst) == 1:
		print(*lst)
	else:
		i = 1
		maxvalue = lst[-1]
		while lst[i] != maxvalue:
			if lst[i] == lst[i - 1]:
				lst.append(lst.pop(i))
			else:
				i += 1
		print(*lst)


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	n = read_int()
	a = list(read_ints())
	s = list(set(a))
	s.sort()
	vis = set()
	for i in a:
		if i in vis:
			s.append(i)
		else:
			vis.add(i)
	print(' '.join(map(str, s)))


def Sort(sub_li):
	return sorted(sub_li, key=lambda x: x[1])
import math
n = int(input())
for i in range(0, n):
	o = int(input())
	p = input().rstrip().split(' ')
	L = [0] * 101
	L = list(L)
	for j in range(0, len(p)):
		L[int(p[j])] += 1
	for j in range(0, len(L)):
		A = j
		B = L[j]
		if B > 0:
			print(A, end=' ')
		L[j] -= 1
	for j in range(0, len(L)):
		A = j
		for k in range(0, L[j]):
			print(A, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	dict1 = dict()
	ans = []
	normal = []
	for i in li:
		if i in dict1:
			ans.append(i)
		else:
			dict1[i] = 1
			normal.append(i)
	normal.sort()
	ans.sort()
	print(*normal + ans)


def solve():
	n = int(input())
	arr = [int(n) for n in input().split(' ')]
	set_arr = sorted(set(arr))
	for n in set_arr:
		arr.remove(n)
	arr = list(set_arr) + arr
	print(*arr)
for t in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * 101
	s = list()
	for i in a:
		b[i] += 1
		if b[i] > 1:
			s.append(i)
	if b[0] == 0:
		print(' '.join(map(str, a)))
	else:
		print(' '.join(map(str, sorted(set(a)))), end=' ')
		print(' '.join(map(str, sorted(s))))


from sys import stdin
from math import sqrt

def readGenerator():
	while True:
		tokens = stdin.readline().strip().split(' ')
		for t in tokens:
			yield t
reader = readGenerator()

def readWord():
	return next(reader)

def readInt():
	return int(next(reader))

def readFloat():
	return float(next(reader))

def readLine():
	return input()

def fact(n):
	return n * fact(n - 1) if n > 1 else n

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

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

def mergeSort(n, a):
	return a

def bubbleSort(n, a):
	f = True
	while f:
		f = False
		for i in range(1, n):
			if a[i] < a[i - 1]:
				f = True
				(a[i], a[i - 1]) = (a[i - 1], a[i])
	return a

def binarySearch(n, x, a):
	l = 0
	r = n - 1
	a.sort()
	while r - l > 1:
		mid = (r + l) // 2
		if a[mid] < x:
			l = mid
		else:
			r = mid
	if a[l] == x:
		return l
	if a[r] == x:
		return r
	return -1

def mergeArrays(n, m, a, b):
	k = 0
	i = 0
	prev = 0
	for j in range(m):
		if j > 0 and b[j] == b[j - 1]:
			k += prev
			continue
		i2 = i
		while i < n and a[i] <= b[j]:
			if a[i] < b[j]:
				i2 += 1
			i += 1
		prev = i - i2
		i = i2
		k += prev
	return k

def solve(n, a):
	a.sort()
	b = []
	d = []
	for i in range(n):
		if i > 0 and a[i] == a[i - 1]:
			d.append(i)
			continue
		b.append(str(a[i]))
	if len(d):
		for i in range(len(d)):
			b.append(str(a[d[i]]))
	return ' '.join(b)
t = readInt()
for _ in range(t):
	n = readInt()
	a = [readInt() for _ in range(n)]
	print(solve(n, a))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	c = []
	b = []
	s = len(set(a))
	while a != []:
		i = a.pop()
		if len(b) >= s:
			b.append(i)
		elif len(b) == 0 or b[-1] != i:
			b.append(i)
		else:
			c.append(i)
	b += c
	print(*b)


import os
import sys
from collections import Counter
from io import BytesIO, IOBase
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))

def main():
	for _ in range(nmbr()):
		n = nmbr()
		a = lst()
		d = Counter(a)
		ans = sorted(set(a))
		for (k, v) in d.items():
			for i in range(v - 1):
				ans += [k]
		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')
for t in range(1):
	main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(b, c) = ([], [])
	used = set()
	for x in a:
		if x not in used:
			b.append(x)
			used.add(x)
		else:
			c.append(x)
	b = sorted(b) + c
	print(*b)


t = int(input())
for i in range(t):
	n = int(input())
	a_s = list(map(int, input().split()))
	set_a = sorted(list(set(a_s)))
	for num in set_a:
		a_s.remove(num)
	print(*set_a + a_s)


def process(A):
	S = set([])
	answer = []
	answer2 = []
	for x in A:
		if x not in S:
			answer.append(x)
			S.add(x)
		else:
			answer2.append(x)
	return sorted(answer) + answer2
t = int(input())
for i in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	answer = process(A)
	print(' '.join(map(str, answer)))


t = int(input())
for i in range(t):
	n = int(input())
	line = [int(i) for i in input().split()]
	line.sort()
	rep = []
	print(line[0], end='')
	ant = line[0]
	for i in range(1, n):
		if line[i] == ant:
			rep.append(line[i])
		else:
			print(f' {line[i]}', end='')
		ant = line[i]
	if len(rep) > 0:
		for i in rep:
			print(f' {i}', end='')
	print()


x = int(input())
for i in range(x):
	n = int(input())
	ar = list(map(int, input().split()))[:n]
	ar.sort()
	b = [0] * 101
	for j in range(0, n):
		b[ar[j]] = b[ar[j]] + 1
	s = set(ar)
	print(*s, end=' ')
	for g in range(101):
		b[g] = b[g] - 1
		while b[g] > 0:
			print(g, end=' ')
			b[g] = b[g] - 1
	print()


t = int(input())
for a0 in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	r = []
	l.sort()
	te = []
	for i in range(n):
		if l[i] in r:
			te.append(l[i])
		else:
			r.append(l[i])
	for i in te:
		r.append(i)
	print(*r)


cases = int(input())
for i in range(cases):
	n = int(input())
	entrada = input().split()
	vetor = []
	for j in entrada:
		vetor.append(int(j))
	vetor.sort()
	remover = []
	for j in range(n - 1):
		if vetor[j] == vetor[j + 1]:
			remover.append(vetor[j])
	for j in remover:
		vetor.remove(j)
	saida = vetor + remover
	for j in range(len(saida) - 1):
		print(saida[j], end=' ')
	print(saida[-1])


for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ar.sort()
	kek = []
	ans = [ar[0]]
	for i in range(1, n):
		if ar[i] != ans[-1]:
			ans.append(ar[i])
		else:
			kek.append(ar[i])
	ans += kek
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	x = input().split()
	lst = [int(_) for _ in x]
	lst.sort()
	left = []
	front = []
	front.append(lst[0])
	for i in range(1, n):
		if lst[i] != lst[i - 1]:
			front.append(lst[i])
		else:
			left.append(lst[i])
	for x in front:
		print(x, end=' ')
	for x in left:
		print(x, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	c = list(set(a))
	for i in c:
		a.remove(i)
	print(*c + a)


from collections import Counter
T = int(input())
for t in range(T):
	n = int(input())
	xs = [int(x) for x in input().split()]
	c = Counter(xs)
	ans = []
	for x in range(105):
		if x not in c:
			break
		else:
			ans.append(x)
			c[x] -= 1
	for (x, occurence) in c.items():
		for i in range(occurence):
			ans.append(x)
	print(*ans)


t = int(input())
for _ in range(t):
	n = input()
	a = list(map(int, input().split()))
	s = set(a)
	[a.remove(i) for i in s]
	a = list(s) + a
	print(*a)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	prev = -1
	(res, ex) = ([], [])
	for i in sorted(a):
		if i != prev:
			res.append(i)
		else:
			ex.append(i)
		prev = i
	print(*res, *ex)


for _ in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	a = list(a)
	a.sort()
	b = []
	c = []
	for i in a:
		if i not in b:
			b.append(i)
		else:
			c.append(i)
	b += c
	print(*b)


import math
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	A.sort()
	C = []
	D = []
	for el in A:
		if el not in C:
			C.append(el)
		else:
			D.append(el)
	E = C + D
	print(' '.join(map(str, E)))


from collections import deque
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	l3 = deque()
	for i in l:
		l3.append(i)
	l1 = []
	l2 = []
	while len(l3) > 0:
		a = l3[0]
		if a not in l1:
			l1.append(a)
			l3.popleft()
		elif a in l1:
			l2.append(a)
			l3.popleft()
	l1.extend(l2)
	print(*l1)


t = int(input())
for i in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	s = set(array)
	[array.remove(i) for i in s]
	array = list(s) + array
	print(*array)


for i in range(int(input())):
	n = input()
	arr = [int(i) for i in input().split()]
	unique = set(arr)
	ans = sorted(list(unique))
	for i in arr:
		if i in unique:
			unique.remove(i)
		else:
			ans.append(i)
	print(' '.join([str(i) for i in ans]))


from collections import Counter, OrderedDict
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dict_1 = Counter(arr)
	dict_1 = dict(OrderedDict(sorted(dict_1.items())))
	arr_1 = []
	while max(dict_1.values()) != 0:
		for i in dict_1.keys():
			if dict_1[i] != 0:
				arr_1.append(i)
				dict_1[i] -= 1
	print(' '.join(map(str, arr_1)))


for s in [*open(0)][2::2]:
	r = (a, b) = [[], []]
	for x in sorted(s.split(), key=int):
		r[x in a] += (x,)
	print(*a + b)


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	a = []
	b = []
	for i in l:
		if i not in a:
			a.append(i)
		else:
			b.append(i)
	a = a + b
	print(*a)
for testis in range(int(input())):
	solve()


for Pythonic__Python in range(int(input())):
	n = input()
	l = list(map(int, input().split()))
	ans = []
	d = {}
	dup = []
	l.sort()
	for i in l:
		if i not in d.keys():
			d[i] = 1
			ans.append(i)
		else:
			dup.append(i)
	ans = ans + dup
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split(' ')
	a = [int(i) for i in a]
	a.sort()
	mex = [a[0]]
	aux = []
	for i in range(1, n):
		if a[i] != a[i - 1]:
			mex.append(a[i])
		else:
			aux.append(a[i])
	mex += aux
	for n in mex:
		print(n, end=' ')
	print()


t = int(input())

def solve():
	pass
result = []
for i in range(t):
	n = int(input())
	integers = [int(x) for x in input().strip().split(' ')]
	tmp = set()
	extra = []
	for num in integers:
		if num in tmp:
			extra.append(num)
		else:
			tmp.add(num)
	integers = sorted(list(tmp)) + sorted(extra)
	result.append(' '.join([str(x) for x in integers]))
for line in result:
	print(line)