Kuroni has $n$ daughters. As gifts for them, he bought $n$ necklaces and $n$ bracelets:  the $i$-th necklace has a brightness $a_i$, where all the $a_i$ are pairwise distinct (i.e. all $a_i$ are different),  the $i$-th bracelet has a brightness $b_i$, where all the $b_i$ are pairwise distinct (i.e. all $b_i$ are different). 

Kuroni wants to give exactly one necklace and exactly one bracelet to each of his daughters. To make sure that all of them look unique, the total brightnesses of the gifts given to each daughter should be pairwise distinct. Formally, if the $i$-th daughter receives a necklace with brightness $x_i$ and a bracelet with brightness $y_i$, then the sums $x_i + y_i$ should be pairwise distinct. Help Kuroni to distribute the gifts.

For example, if the brightnesses are $a = [1, 7, 5]$ and $b = [6, 1, 2]$, then we may distribute the gifts as follows:  Give the third necklace and the first bracelet to the first daughter, for a total brightness of $a_3 + b_1 = 11$. Give the first necklace and the third bracelet to the second daughter, for a total brightness of $a_1 + b_3 = 3$. Give the second necklace and the second bracelet to the third daughter, for a total brightness of $a_2 + b_2 = 8$. 

Here is an example of an invalid distribution:   Give the first necklace and the first bracelet to the first daughter, for a total brightness of $a_1 + b_1 = 7$. Give the second necklace and the second bracelet to the second daughter, for a total brightness of $a_2 + b_2 = 8$. Give the third necklace and the third bracelet to the third daughter, for a total brightness of $a_3 + b_3 = 7$. 

This distribution is invalid, as the total brightnesses of the gifts received by the first and the third daughter are the same. Don't make them this upset!


-----Input-----

The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 100$)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $n$ ($1 \le n \le 100$)  — the number of daughters, necklaces and bracelets.

The second line of each test case contains $n$ distinct integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$)  — the brightnesses of the necklaces.

The third line of each test case contains $n$ distinct integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 1000$)  — the brightnesses of the bracelets.


-----Output-----

For each test case, print a line containing $n$ integers $x_1, x_2, \dots, x_n$, representing that the $i$-th daughter receives a necklace with brightness $x_i$. In the next line print $n$ integers $y_1, y_2, \dots, y_n$, representing that the $i$-th daughter receives a bracelet with brightness $y_i$.

The sums $x_1 + y_1, x_2 + y_2, \dots, x_n + y_n$ should all be distinct. The numbers $x_1, \dots, x_n$ should be equal to the numbers $a_1, \dots, a_n$ in some order, and the numbers $y_1, \dots, y_n$ should be equal to the numbers $b_1, \dots, b_n$ in some order. 

It can be shown that an answer always exists. If there are multiple possible answers, you may print any of them.


-----Example-----
Input
2
3
1 8 5
8 4 5
3
1 7 5
6 1 2

Output
1 8 5
8 4 5
5 1 7
6 2 1



-----Note-----

In the first test case, it is enough to give the $i$-th necklace and the $i$-th bracelet to the $i$-th daughter. The corresponding sums are $1 + 8 = 9$, $8 + 4 = 12$, and $5 + 5 = 10$.

The second test case is described in the statement.

Difficulty: EASY
Tags: Greedy algorithms

Complete search

Sorting

Constructive algorithms
Skill types: Complete search

Sorting

Greedy algorithms

Starter code:

Solutions:
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l.sort()
	l2.sort()
	print(*l)
	print(*l2)


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	neck = list(map(int, stdin.readline().strip().split(' ')))
	brac = list(map(int, stdin.readline().strip().split(' ')))
	neck.sort()
	brac.sort()
	stdout.write(' '.join(list(map(str, neck))) + '\n')
	stdout.write(' '.join(list(map(str, brac))) + '\n')


for i in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1 = sorted(l1)
	l2 = sorted(l2)
	for j in range(n):
		l1[j] = str(l1[j])
		l2[j] = str(l2[j])
	print(' '.join(l1))
	print(' '.join(l2))


from sys import stdin
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	A = list(map(int, stdin.readline().split(' ')))
	B = list(map(int, stdin.readline().split(' ')))
	A.sort()
	B.sort()
	for item in A:
		print(item, end=' ')
	print('')
	for item in B:
		print(item, end=' ')
	print('')


x = int(input())
for i in range(0, x):
	n = int(input())
	m = list(map(int, input().split()))[:n]
	p = list(map(int, input().split()))[:n]
	m.sort()
	p.sort()
	print(*m)
	print(*p)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()
while t:
	t -= 1
	(n,) = I()
	a = sorted(I())
	b = sorted(I())
	print(*a)
	print(*b)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		a.sort()
		b.sort()
		print(*a)
		print(*b)
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()


def solve():
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	print(*l1)
	print(*l2)
for _ in range(int(input())):
	solve()


n = int(input())
for i in range(n):
	m = int(input())
	l_o = list(map(int, input().split()))
	l_b = list(map(int, input().split()))
	l_o.sort()
	l_b.sort()
	print(*l_o)
	print(*l_b)


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		a.sort()
		b.sort()
		a = list(map(str, a))
		b = list(map(str, b))
		print(' '.join(a))
		print(' '.join(b))
main()


for _ in [0] * int(input()):
	input()
	print(*sorted(map(int, input().split())))
	print(*sorted(map(int, input().split())))


t = int(input())
for i in range(t):
	n = int(input())
	A = [int(j) for j in input().split()]
	B = [int(j) for j in input().split()]
	A.sort()
	B.sort()
	A0 = [str(k) for k in A]
	B0 = [str(k) for k in B]
	print(' '.join(A0))
	print(' '.join(B0))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	neck = sorted(list(map(int, input().split())))
	brac = sorted(list(map(int, input().split())))
	print(' '.join(map(str, neck)))
	print(' '.join(map(str, brac)))


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	print(*l1)
	print(*l2)


num_test_cases = int(input())
for _ in range(num_test_cases):
	total_nums = int(input())
	num_a = sorted(input().split(' '), key=lambda x: int(x))
	num_b = sorted(input().split(' '), key=lambda x: int(x))
	print(' '.join(num_a))
	print(' '.join(num_b))


from math import *
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	x.sort()
	y.sort()
	for i in x:
		print(i, '', end='')
	print()
	for i in y:
		print(i, '', end='')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	for i in a:
		print(i, end=' ')
	print()
	for i in b:
		print(i, end=' ')
	print()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = sorted(map(int, input().split()))
	b = sorted(map(int, input().split()))
	print(*a)
	print(*b)


import sys
answers = []
test_num = int(input().rstrip())
for i in range(test_num):
	count = int(input().rstrip())
	line = input().rstrip()
	array_1 = list(map(int, line.split()))
	line = input().rstrip()
	array_2 = list(map(int, line.split()))
	array_1.sort()
	array_2.sort()
	answers.append((array_1, array_2))
for (array_1, array_2) in answers:
	print(*array_1)
	print(*array_2)
sys.stdout.flush()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	b = list(map(int, input().strip().split(' ')))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	for j in a:
		print(j, end=' ')
	print()
	for j in b:
		print(j, end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	for x in range(n):
		print(a[x], end=' ')
	print(' ')
	for y in range(n):
		print(b[y], end=' ')
	print(' ')


t = int(input())
while t != 0:
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	print(*a)
	print(*b)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = sorted(map(int, input().split()))
	b = sorted(map(int, input().split()))
	print('%s\n%s' % (' '.join(map(str, a)), ' '.join(map(str, b))))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = list(map(int, input().split()))
	b.sort()
	print(' '.join((str(x) for x in a)))
	print(' '.join((str(x) for x in b)))


t = int(input().strip())
for testcase in range(t):
	n = int(input().strip())
	a = map(int, input().strip().split())
	b = map(int, input().strip().split())
	print(' '.join(map(str, sorted(a))))
	print(' '.join(map(str, sorted(b))))


t = int(input())
for i in range(t):
	x = int(input())
	x1 = list(map(int, input().split()))
	x2 = list(map(int, input().split()))
	x1.sort()
	x2.sort()
	res_x = []
	for j in range(x):
		res_x.append([x1[j], x2[j]])
	for j in range(x):
		print(res_x[j][0], end=' ')
	print()
	for j in range(x):
		print(res_x[j][1], end=' ')
	print()


def merge(array, start, pointer, end):
	n1 = pointer - start + 1
	n2 = end - pointer
	left = array[start:pointer + 1]
	right = array[pointer + 1:end + 1]
	i = j = 0
	k = start
	while i < n1 and j < n2:
		if left[i] <= right[j]:
			array[k] = left[i]
			i += 1
		else:
			array[k] = right[j]
			j += 1
		k += 1
	while i < n1:
		array[k] = left[i]
		i += 1
		k += 1
	while j < n2:
		array[k] = right[j]
		j += 1
		k += 1

def merge_sort(array):
	merge_sort2(array, 0, len(array) - 1)

def merge_sort2(array, start, end):
	if start < end:
		m = (start + end) // 2
		merge_sort2(array, start, m)
		merge_sort2(array, m + 1, end)
		merge(array, start, m, end)

def findnums(arr1, arr2):
	suma = []
	j = newsum = 0
	while j < len(arr1):
		newsum = arr1[j] + arr2[j]
		if newsum not in suma:
			suma.append(newsum)
			j += 1
		else:
			for i in range(j + 1, len(arr1)):
				newsum = arr1[j] + arr2[i]
				if newsum not in suma:
					suma.append(newsum)
					(arr2[i], arr2[j]) = (arr2[j], arr2[i])
					break
				newsum = arr1[i] + arr2[j]
				if newsum not in suma:
					suma.append(newsum)
					(arr1[i], arr1[j]) = (arr1[j], arr1[i])
					j += 1
					break
	return (arr1, arr2)
n = int(input())
outputs = []
for _ in range(n):
	r = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	merge_sort(a)
	merge_sort(b)
	(r1, r2) = findnums(a, b)
	outputs.append(r1)
	outputs.append(r2)
for z in outputs:
	print(*z)


def summ(a, b):
	s = []
	for j in range(len(a)):
		s.append(a[j] + b[j])
	s = set(s)
	if len(list(s)) == len(a):
		print(*a)
		print(*b)
		return 0
	else:
		b = [b[-1]] + b[0:-1]
		summ(a, b)
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	summ(a, b)


t = int(input())
while t:
	n = int(input())
	a = input().split()
	a = [int(x) for x in a]
	a.sort()
	b = input().split()
	b = [int(x) for x in b]
	b.sort()
	for x in a:
		print(x, end=' ')
	print()
	for x in b:
		print(x, end=' ')
	print()
	t -= 1


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 list(map(int, 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=2):
	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)
for _ in range(ii()):
	n = ii()
	a = li()
	b = li()
	print(*sorted(a))
	print(*sorted(b))


nn = int(input())
for tt in range(nn):
	n = int(input())
	a = []
	b = []
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	for i in a:
		print(i)
	for i in b:
		print(i)


import collections

def recur(neck, brac):
	while 1:
		summ = [x + y for (x, y) in zip(neck, brac)]
		dictt = {x: y for (x, y) in collections.Counter(summ).items() if y > 1}
		if len(dictt.keys()) > 0:
			for ele in dictt:
				indices = [i for (i, x) in enumerate(summ) if x == ele]
				for i in range(len(indices) // 2):
					temp = brac[indices[i]]
					brac[indices[i]] = brac[indices[i + 1]]
					brac[indices[i + 1]] = temp
		else:
			return (neck, brac)
test = int(input())
for i in range(test):
	n = int(input())
	neck = list(map(int, input().split()))
	brac = list(map(int, input().split()))
	(neck, brac) = recur(neck, brac)
	print(*neck)
	print(*brac)


for _ in range(int(input())):
	q = input()
	a = [int(h) for h in input().split(' ')]
	b = [int(h) for h in input().split(' ')]
	print(' '.join([str(e) for e in sorted(a)]))
	print(' '.join([str(e) for e in sorted(b)]))


import sys
input = sys.stdin.readline
for ti in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	print(*a)
	print(*b)


ab = int(input())
for k in range(ab):
	a = int(input())
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	b.sort()
	c.sort()
	for j in b:
		print(j, end=' ')
	print()
	for t in c:
		print(t, end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a = [str(x) for x in sorted(a)]
	b = [str(x) for x in sorted(b)]
	print(' '.join(a))
	print(' '.join(b))


for _ in range(int(input())):
	lens = int(input())
	print(*sorted([int(x) for x in input().split()]))
	print(*sorted([int(x) for x in input().split()]))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a, sep=' ')
	print(*b, sep=' ')


for _ in range(int(input())):
	n = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	print(*sorted(ai))
	print(*sorted(bi))


for i in range(int(input())):
	size = int(input())
	arr1 = [int(i) for i in input().split()]
	arr2 = [int(i) for i in input().split()]
	arr1.sort()
	arr2.sort()
	print(*arr1)
	print(*arr2)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = []
	b1 = []
	while len(a) > 0:
		a1.append(max(a))
		b1.append(max(b))
		a.remove(max(a))
		b.remove(max(b))
	for item in a1:
		print(item, end=' ')
	print()
	for item in b1:
		print(item, end=' ')
	print()


t = int(input())
q = []
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	z = []
	a.sort()
	b.sort()
	for j in range(0, n):
		k = a[j] + b[j]
		if k in z:
			for f in range(0, len(z)):
				if k == z[f]:
					e = f
			t = a[f]
			a[f] = a[j]
			a[j] = t
			z[f] = a[f] + b[f]
			k = a[j] + b[j]
		z.append(k)
	q.append(a)
	q.append(b)
for i in q:
	for j in i:
		print(j, end=' ')
	print()


def main():
	n = int(input())
	for i in range(n):
		input()
		x = sorted(list(map(int, input().split())))
		y = sorted(list(map(int, input().split())))
		print(' '.join([str(xx) for xx in x]))
		print(' '.join([str(xx) for xx in y]))
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())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	a.sort()
	b.sort()
	b = deque(b)
	cal = set()
	ansa = []
	ansb = []
	for i in range(n):
		while len(cal) < i + 1:
			c = b.popleft()
			tmp = a[i] + c
			if tmp in cal:
				b.append(c)
			else:
				ansa.append(a[i])
				ansb.append(c)
				cal.add(tmp)
				break
	print(*ansa)
	print(*ansb)


n = int(input())
for i in range(n):
	t = int(input())
	x = [int(x) for x in input().split()]
	y = [int(y) for y in input().split()]
	x.sort()
	y.sort()
	for i in range(t):
		print(x[i], end=' ')
	print()
	for i in range(t):
		print(y[i], end=' ')
	print()


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()
	a = inputlist()
	b = inputlist()
	a.sort()
	b.sort()
	print(*a)
	print(*b)


for _ in range(int(input())):
	n = int(input())
	neck = list(map(int, input().split()))
	brace = list(map(int, input().split()))
	neck.sort()
	brace.sort()
	for i in neck:
		print(i, end=' ')
	print()
	for i in brace:
		print(i, end=' ')
	print()


from math import ceil, sqrt, floor
n = int(input())
for i in range(n):
	_ = int(input())
	for j in range(2):
		print(*sorted(list(map(int, input().split()))))


t = int(input())
for j in range(t):
	n = int(input())
	nk = list(map(int, input().split()))
	br = list(map(int, input().split()))
	nk.sort()
	br.sort()
	for i in nk:
		print(i, end=' ')
	print()
	for i in br:
		print(i, end=' ')
	print()


for i in range(int(input())):
	n = int(input())
	neck = list(map(int, input().split()))
	brac = list(map(int, input().split()))
	neck.sort()
	brac.sort()
	print(*neck)
	print(*brac)


I = input
l = []
for _ in range(int(I())):
	I()
	a = list(map(int, I().split()))
	b = list(map(int, I().split()))
	a.sort()
	b.sort()
	l.append(a)
	l.append(b)
for i in l:
	for j in i:
		print(j, end=' ')
	print()


for i in ' ' * int(input()):
	input()
	print(*sorted([*map(int, input().split())]))
	print(*sorted([*map(int, input().split())]))


a = int(input())
y = []
for i in range(a):
	x = []
	b = int(input())
	c = sorted(list(map(int, input().split())))
	d = sorted(list(map(int, input().split())))
	print(*c)
	print(*d)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a = sorted(a)
	b = sorted(b)
	print(' '.join(map(str, a)))
	print(' '.join(map(str, b)))


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()
	a = list(intsput())
	a.sort()
	b = list(intsput())
	b.sort()
	print(*a)
	print(*b)


t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	x.sort()
	y.sort()
	print(*x)
	print(*y)


def solve():
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	x.sort()
	y.sort()
	print(*x)
	print(*y)
for _ in range(int(input())):
	solve()


T = int(input())
for i in range(0, T):
	n = int(input())
	ar1 = list(map(int, input().split()[:n]))
	ar2 = list(map(int, input().split()[:n]))
	ar1.sort()
	ar2.sort()
	for j in range(0, n):
		if j == n - 1:
			print(ar1[j])
		else:
			print(ar1[j], end=' ')
	for j in range(0, n):
		if j == n - 1:
			print(ar2[j])
		else:
			print(ar2[j], end=' ')


ans = []
for t in range(int(input())):
	n = int(input())
	(a, b) = ([int(i) for i in input().split()], [int(i) for i in input().split()])
	a.sort()
	b.sort()
	s = ' '.join([str(i) for i in a]) + '\n' + ' '.join([str(i) for i in b])
	ans.append(s)
print('\n'.join(ans))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	arr.sort()
	brr.sort()
	for i in range(n):
		print(arr[i], end=' ')
	print('')
	for i in range(n):
		print(brr[i], end=' ')
	print('')


n = int(input())
from math import *
for x in range(n):
	t = int(input())
	l = sorted(list(map(int, input().split())))
	m = sorted(list(map(int, input().split())))
	l = [str(xa) for xa in l]
	m = [str(ya) for ya in m]
	print(' '.join(l))
	print(' '.join(m))


t = int(input())
for items in range(t):
	n = int(input())
	x = sorted(list(map(int, input().split())))[:n]
	y = sorted(list(map(int, input().split())))[:n]
	print(*x)
	print(*y)


for j in range(int(input())):
	n = int(input())
	a = list(map(int, input().rstrip().split(' ')))
	b = list(map(int, input().rstrip().split(' ')))
	used = set()
	a.sort()
	b.sort()
	inc = 0
	ans = []
	j = 0
	while len(ans) < len(b):
		if a[j] + b[j - inc] not in used and b[j - inc] != -1:
			used.add(a[j] + b[j - inc])
			ans.append(b[j - inc])
			b[j - inc] = -1
			j = j + 1
		else:
			c = 1
			while a[j] + b[j - inc + c] in used or b[j - inc + c] == -1:
				c = c + 1
			used.add(a[j] + b[j - inc + c])
			ans.append(b[j - inc + c])
			b.remove(b[j - inc + c])
			j = j + 1
	a = list(map(str, a))
	ans = list(map(str, ans))
	print(' '.join(a))
	print(' '.join(ans))


T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A.sort()
	B.sort()
	for i in range(n - 1):
		print(A[i], end=' ')
	print(A[n - 1])
	for i in range(n - 1):
		print(B[i], end=' ')
	print(B[n - 1])


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(j) for j in input().split()]
	l1 = [int(j) for j in input().split()]
	l.sort()
	l1.sort()
	for j in l:
		print(j, end=' ')
	print()
	for j in l1:
		print(j, end=' ')


for i in range(int(input())):
	input()
	lis1 = list(map(int, input().split()))
	lis2 = list(map(int, input().split()))
	lis1.sort(reverse=True)
	lis2.sort(reverse=True)
	print(*lis1, sep=' ')
	print(*lis2, sep=' ')


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	Query.append((N, A, B))
for (N, A, B) in Query:
	A.sort()
	B.sort()
	print(*A)
	print(*B)


for _ in range(int(input())):
	n = int(input())
	a = sorted([int(i) for i in input().split()])
	b = sorted([int(i) for i in input().split()])
	print(*a)
	print(*b)


m = int(input())
for i in range(m):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	c = sorted(a)
	d = sorted(b)
	for i in c:
		print(i, end=' ')
	print()
	for j in d:
		print(j, end=' ')
	print()


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


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(y) for y in input().split()]
	a = sorted(a)
	b = sorted(b)
	print(*a)
	print(*b)


n = int(input())
r = 0
c = list()
while r < n:
	input()
	a = [int(a) for a in input().split()]
	b = [int(b) for b in input().split()]
	a.sort()
	b.sort()
	c.append(a)
	c.append(b)
	r = r + 1
r = 0
while r < len(c):
	print(' '.join((char for char in map(str, c[r]))))
	r = r + 1


for _ in range(int(input())):
	input()
	print(*sorted(list(map(int, input().split()))))
	print(*sorted(list(map(int, input().split()))))


for i in range(int(input())):
	am = int(input())
	arr = list(sorted(list(map(int, input().split()))))
	arr2 = list(sorted(list(map(int, input().split()))))
	print(*arr)
	print(*arr2)


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


exec(int(input()) * ('input();' + 'print(*sorted(map(int,input().split())));' * 2))


for _ in range(int(input())):
	_ = input()
	arr1 = list(map(int, input().split(' ')))
	arr2 = list(map(int, input().split(' ')))
	(arr1, arr2) = (sorted(arr1), sorted(arr2))
	print(*arr1)
	print(*arr2)


import math

class Read:

	@staticmethod
	def string():
		return input()

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

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

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

def solve():
	n = Read.int()
	a = Read.list_int()
	b = Read.list_int()
	a.sort()
	b.sort()
	print(' '.join((str(x) for x in a)))
	print(' '.join((str(x) for x in b)))
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	for i in a:
		print(i, end=' ')
	print(' ')
	for i in b:
		print(i, end=' ')
	print(' ')


t = int(input())
for _ in range(t):
	n = int(input())
	necklaces = list(map(int, input().split(' ')))
	bracelets = list(map(int, input().split(' ')))
	bracelets.sort()
	necklaces.sort()
	print(' '.join([str(val) for val in necklaces]))
	print(' '.join([str(val) for val in bracelets]))


import sys
input = lambda : sys.stdin.readline()
n = int(input())
for i in range(n):
	a = int(input())
	c = list(map(lambda x: (int(x[1]), x[0]), enumerate(input().split())))
	d = list(map(lambda x: (int(x[1]), x[0]), enumerate(input().split())))
	c.sort()
	d.sort()
	print(' '.join(map(lambda x: str(x[0]), c)))
	print(' '.join(map(lambda x: str(x[0]), d)))


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		n = int(input())
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		A.sort()
		B.sort()
		print(' '.join(list((str(a) for a in A))))
		print(' '.join(list((str(b) for b in B))))
main()


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l.sort()
	l1.sort()
	for i in l:
		print(i, end=' ')
	print()
	for i in l1:
		print(i, end=' ')
	print()


num = int(input())
for i in range(num):
	n = int(input())
	neck = [int(i) for i in input().split(' ')]
	bracelet = [int(i) for i in input().split(' ')]
	neck.sort()
	bracelet.sort()
	print(*neck, sep=' ')
	print(*bracelet, sep=' ')


t = int(input())
while t != 0:
	t -= 1
	l = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	d = []
	for i in range(l):
		ele = a[i]
		j = i
		while j > 0 and a[j - 1] > ele:
			a[j] = a[j - 1]
			j -= 1
		a[j] = ele
	for i in range(l):
		ele = b[i]
		j = i
		while j > 0 and b[j - 1] > ele:
			b[j] = b[j - 1]
			j -= 1
		b[j] = ele
	(a1, b1) = ('', '')
	for i in range(len(a)):
		a1 = a1 + str(a[i]) + ' '
	for i in range(len(b)):
		b1 = b1 + str(b[i]) + ' '
	print(a1[0:-1])
	print(b1[0:-1])


t = int(input())
for i in range(0, t):
	n = input()
	neck = list(map(int, input().split()))
	brac = list(map(int, input().split()))
	print(*sorted(neck))
	print(*sorted(brac))


I = lambda : map(int, input().split())
P = lambda : print(*sorted(I()))
for _ in range(*I()):
	I()
	P()
	P()


t = int(input())
for i2 in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	x.sort()
	y.sort()
	for i in range(n):
		print(x[i], end=' ')
	print('')
	for i in range(n):
		print(y[i], end=' ')
	print('')


import sys
pin = sys.stdin.readline
pout = sys.stdout.write
ran = range
mape = map
maxi = max
t = int(pin())
for i in ran(t):
	sub = []
	sub1 = []
	m = int(pin())
	total = list(mape(int, pin().split()))
	total1 = list(mape(int, pin().split()))
	for j in ran(m):
		sub.append(maxi(total))
		total.remove(maxi(total))
		sub1.append(maxi(total1))
		total1.remove(maxi(total1))
	print(' '.join(map(str, sub)))
	print(' '.join(map(str, sub1)))


for i in range(int(input())):
	x = int(input())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	print(*a)
	print(*b)


import sys
import copy
input = sys.stdin.readline
from math import *
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	print(*sorted(a))
	print(*sorted(b))


n = int(input())
for i in range(n):
	m = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(' '.join(map(str, a)))
	print(' '.join(map(str, b)))


from sys import stdin

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

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()
	a = linput()
	b = linput()
	a.sort()
	b.sort()
	print(*a)
	print(*b)


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 YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		b = LI()
		rr.append(JA(sorted(a), ' '))
		rr.append(JA(sorted(b), ' '))
	return JA(rr, '\n')
print(main())


import sys
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		a.sort()
		b.sort()
		for i in range(n):
			print(a[i], end=' ')
		print('')
		for i in range(n):
			print(b[i], end=' ')
		print('')
main()


for _ in range(int(input())):
	a = int(input())
	a1 = [int(x) for x in input().split()]
	a2 = [int(y) for y in input().split()]
	a1.sort()
	a2.sort()
	print(*a1)
	print(*a2)


t = int(input())
for _ in range(t):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	print(*a)
	print(*b)


def solve(braces, necks):
	braces.sort()
	necks.sort()
	for i in necks:
		print(i, end=' ')
	print()
	for i in braces:
		print(i, end=' ')
	print()

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		neck = list(map(int, input().split()))
		braces = list(map(int, input().split()))
		solve(braces, neck)
main()


for _ in range(int(input())):
	input()
	a = map(int, input().split())
	a = sorted(a)
	print(' '.join([str(x) for x in a]))
	a = map(int, input().split())
	a = sorted(a)
	print(' '.join([str(x) for x in a]))


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		necklaceBrightness = list(map(int, input().split()))
		braceletsBrightness = list(map(int, input().split()))
		necklaceBrightness.sort()
		braceletsBrightness.sort()
		for n in necklaceBrightness:
			print(n, end=' ')
		print()
		for b in braceletsBrightness:
			print(b, end=' ')
		print()
main()


for i in range(int(input())):
	n = int(input())
	necklaces = list(map(int, input().split()))
	bracelets = list(map(int, input().split()))
	output1 = ''
	output2 = ''
	necklaces.sort()
	bracelets.sort()
	for i in necklaces:
		output1 += str(i) + ' '
	for i in bracelets:
		output2 += str(i) + ' '
	print(output1)
	print(output2)


for kk in range(int(input())):
	j = 1 + 1
	aa = int(input())
	ak = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	print(*ak)
	print(*b)


for _ in range(int(input())):
	n = int(input())
	aa = list(map(int, input().split()))
	bb = list(map(int, input().split()))
	aa.sort()
	bb.sort()
	ll = []
	mm = []
	for i in range(n):
		ll.append(aa[i])
		mm.append(bb[i])
	print(*ll)
	print(*mm)


t = int(input())
while t != 0:
	n = int(input())
	arr = []
	arr = [int(x) for x in input().split()]
	brr = []
	brr = [int(x) for x in input().split()]
	arr.sort()
	brr.sort()
	print(*arr)
	print(*brr)
	t = t - 1


t = int(input())
for i in range(t):
	p = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a, sep=' ')
	print(*b, sep=' ')


def check(n, neck, brac):
	neck.sort()
	brac.sort()
	neck = list(map(str, neck))
	brac = list(map(str, brac))
	print(' '.join(neck))
	print(' '.join(brac))
tcase = int(input())
for i in range(tcase):
	n = int(input())
	necklace = list(map(int, input().split(' ')))
	brac = list(map(int, input().split(' ')))
	check(n, necklace, brac)


for i in range(int(input())):
	n = int(input())
	print(*sorted(list(map(int, input().split()))))
	print(*sorted(list(map(int, input().split()))))


t = int(input())
for i in range(t):
	n = int(input())
	necklace = list(map(int, input().split()))
	braclet = list(map(int, input().split()))
	sum1 = []
	for j in range(0, n):
		sum1.append(necklace[j] + braclet[j])
	if len(list(dict.fromkeys(sum1))) == len(sum1):
		print(*necklace, sep=' ')
		print(*braclet, sep=' ')
	else:
		sum1.clear()
		temp = necklace.copy()
		temp.sort()
		for j in range(0, n):
			sum1.append(temp[j] + braclet[j])
		if len(list(dict.fromkeys(sum1))) == len(sum1):
			print(*temp, sep=' ')
			print(*braclet, sep=' ')
		else:
			sum1.clear()
			temp.clear()
			temp = braclet.copy()
			temp.sort()
			for j in range(0, n):
				sum1.append(temp[j] + necklace[j])
			if len(list(dict.fromkeys(sum1))) == len(sum1):
				print(*necklace, sep=' ')
				print(*temp, sep=' ')
			else:
				sum1.clear()
				temp.clear()
				temp = necklace.copy()
				temp.sort()
				temp1 = braclet.copy()
				temp1.sort()
				for j in range(0, n):
					sum1.append(temp[j] + temp1[j])
				if len(list(dict.fromkeys(sum1))) == len(sum1):
					print(*temp, sep=' ')
					print(*temp1, sep=' ')
				else:
					sum1.clear()


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


t = int(input())
o = []
b = []
for i in range(t):
	_ = input()
	o.append(list(map(int, input().split())))
	b.append(list(map(int, input().split())))
answer = []
for i in range(t):
	o[i].sort()
	b[i].sort()
	answer.append(' '.join(map(str, o[i])))
	answer.append(' '.join(map(str, b[i])))
for a in answer:
	print(a)


t = int(input())
for i in range(t):
	n = int(input())
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	li1.sort()
	li2.sort()
	for i in li1:
		print(i, end=' ')
	print('')
	for i in li2:
		print(i, end=' ')
	print('')


for _ in range(int(input())):
	N = int(input())
	List1 = [int(x) for x in input().split()]
	List2 = [int(x) for x in input().split()]
	List1.sort()
	List2.sort()
	print(*List1)
	print(*List2)


test = int(input())
for i in range(test):
	length = int(input())
	necklace = list(map(int, input().split()))
	bracelets = list(map(int, input().split()))
	necklace.sort()
	bracelets.sort()
	necklace = list(map(str, necklace))
	bracelets = list(map(str, bracelets))
	print(' '.join(necklace))
	print(' '.join(bracelets))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	a.sort()
	b.sort()
	for num in a:
		print(num, end=' ')
	print()
	for num in b:
		print(num, end=' ')
	print()


testcases = int(input())
masterlist = []
for i in range(testcases):
	input()
	necklaces = list(map(int, input().split(' ')))
	bracelets = list(map(int, input().split(' ')))
	necklaces.sort()
	bracelets.sort()
	masterlist.append((necklaces, bracelets))
for i in masterlist:
	ns = i[0]
	bs = i[1]
	str = ''
	str2 = ''
	for i in ns:
		str += '{} '.format(i)
	for i in bs:
		str2 += '{} '.format(i)
	print(str)
	print(str2)


for i in range(int(input())):
	input()
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	x.sort()
	y.sort()
	print(*x, sep=' ')
	print(*y, sep=' ')


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	n = int(sys.stdin.readline().rstrip())
	a = list(map(int, sys.stdin.readline().rstrip().split()))
	b = list(map(int, sys.stdin.readline().rstrip().split()))
	a.sort()
	b.sort()
	for i in a:
		print(i, end=' ')
	print('')
	for i in b:
		print(i, end=' ')
	print('')


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin, tan

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 lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()
for _ in range(ii()):
	n = ii()
	a = li()
	b = li()
	print(*sorted(a))
	print(*sorted(b))


t = int(input())
while t:
	n = int(input())
	A = list(map(int, input().split()))
	A.sort()
	B = list(map(int, input().split()))
	B.sort()
	print(*A, sep=' ')
	print(*B, sep=' ')
	t = t - 1


for tc in range(int(input())):
	k = map(int, input().split())
	l = list(map(int, input().split()))
	f = list(map(int, input().split()))
	l.sort()
	f.sort()
	print(*l)
	print(*f)


def main():
	for _ in range(int(input())):
		n = int(input())
		x = list(map(int, input().split()))
		y = list(map(int, input().split()))
		x.sort()
		y.sort()
		set1 = set()
		resx = []
		resy = []
		for i in range(n):
			for j in range(n):
				if x[i] != -1 and y[i] != -1 and (x[i] + y[i] not in set1):
					resx.append(x[i])
					resy.append(y[i])
					set1.add(x[i] + y[i])
					x[i] = -1
					y[i] = -1
		print(*resx)
		print(*resy)
main()


def main():
	t = int(input())
	for __ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		a.sort()
		b.sort()
		print(*a)
		print(*b)
main()


T = int(input())
answer = ''
for t in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	arr.sort()
	brr.sort()
	f = s = ''
	for i in range(n):
		f += str(arr[i]) + ' '
		s += str(brr[i]) + ' '
	f += '\n'
	s += '\n'
	answer += f + s
print(answer)


n = int(input())
neck = []
brac = []
arr = []
for i in range(0, n):
	j = int(input())
	arr = input().split()
	arr = [int(i) for i in arr]
	arr.sort()
	neck.append(arr)
	arr = []
	arr = input().split()
	arr = [int(i) for i in arr]
	arr.sort()
	brac.append(arr)
for i in range(n):
	print(*neck[i])
	print(*brac[i])


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A.sort()
	B.sort()
	print(*A)
	print(*B)


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')
MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
let = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(ii()):
	n = ii()
	neck = sorted(il())
	brac = sorted(il())
	print(*neck)
	print(*brac)


import sys, math
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())
t = 1
t = inp()
for tt in range(t):
	n = inp()
	a = inlt()
	b = inlt()
	print(*sorted(a))
	print(*sorted(b))


for _ in range(int(input())):
	n = int(input())
	x = sorted(list(map(int, input().split())))
	y = sorted(list(map(int, input().split())))
	print(*x)
	print(*y)


tests = int(input())
res_a = []
res_b = []
for i in range(tests):
	n = int(input())
	a = list(map(int, input().split()[:n]))
	b = list(map(int, input().split()[:n]))
	at = a
	bt = b
	at.sort()
	bt.sort()
	res_a.append(at)
	res_b.append(bt)
for i in range(tests):
	print(*res_a[i], sep=' ')
	print(*res_b[i], sep=' ')


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)
t = int(input())
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	for x in a:
		print(x, end=' ')
	print('')
	for x in b:
		print(x, end=' ')
	print('')


for _ in range(int(input())):
	n = int(input())
	nec = list(map(int, input().split()))
	brac = list(map(int, input().split()))
	nec.sort()
	brac.sort()
	[print(i, end=' ') for i in nec]
	print()
	[print(i, end=' ') for i in brac]
	print()


printn = lambda x: print(x, end='')
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
t = inn()
for tt in range(t):
	n = inn()
	a = inl()
	b = inl()
	a.sort()
	b.sort()
	pad = ''
	for i in range(n):
		printn(pad + str(a[i]))
		pad = ' '
	print('')
	pad = ''
	for i in range(n):
		printn(pad + str(b[i]))
		pad = ' '
	print('')


t = int(input())
for i in range(t):
	n = int(input())
	z = []
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a = sorted(a)
	b = sorted(b)
	aa = []
	bb = []
	for i in range(n):
		for j in range(n):
			if a[i] + b[j] not in z and b[j] != 0:
				z.append(a[i] + b[j])
				aa.append(a[i])
				bb.append(b[j])
				b[j] = 0
				break
	print(*aa)
	print(*bb)


from sys import stdin, gettrace
if not gettrace():

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

def main():

	def solve():
		n = int(input())
		aa = [int(a) for a in input().split()]
		bb = [int(a) for a in input().split()]
		aa.sort()
		bb.sort()
		print(' '.join(map(str, aa)))
		print(' '.join(map(str, bb)))
	q = int(input())
	for _ in range(q):
		solve()
main()


T = int(input())
for _ in range(T):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arr1.sort()
	arr2.sort()
	print(*arr1)
	print(*arr2)


t = int(input())
for q in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	for x in a:
		print(x, end=' ')
	print()
	for x in b:
		print(x, end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	xs = list(map(int, input().split()))
	ys = list(map(int, input().split()))
	xs.sort()
	ys.sort()
	print(*xs)
	print(*ys)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l.sort()
	l1.sort()
	for i in range(n):
		print(l[i], end=' ')
	print()
	for i in range(n):
		print(l1[i], end=' ')
	print()


T = int(input())
for _ in range(T):
	n = int(input())
	A = sorted(list(map(int, input().split())))
	B = sorted(list(map(int, input().split())))
	print(' '.join([str(x) for x in A]))
	print(' '.join([str(x) for x in B]))


for _ in [0] * int(input()):
	input()
	exec('print(*sorted(map(int,input().split())));' * 2)


T = int(input())
for _ in range(T):
	N = int(input())
	print(*sorted([int(a) for a in input().split()]))
	print(*sorted([int(a) for a in input().split()]))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(' '.join(list(map(str, a))))
	print(' '.join(list(map(str, b))))


n = int(input())
while n:
	nr = int(input())
	a = input().split()
	b = input().split()
	for i in range(len(a)):
		a[i] = int(a[i])
		b[i] = int(b[i])
	a.sort()
	b.sort()
	for i in range(len(a)):
		print(a[i], end=' ')
	print()
	for i in range(nr):
		print(b[i], end=' ')
	n -= 1


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time

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

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

def S():
	return input()

def MS():
	return map(str, input().split())

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

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

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

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

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

def print_matrix(d):
	for i in range(len(d)):
		print(d[i])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = {False: 'No', True: 'Yes'}
MOD = 10 ** 9 + 7
inf = float('inf')
IINF = 10 ** 10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False

def f(x, y, _x, _y):
	for i in range(len(x)):
		for j in range(len(y)):
			nx = _x.copy()
			nx.add(i)
			ny = _y.copy()
			ny.add(j)
			f(x[i], y[j], nx, ny)

def solve(T):
	n = I()
	x = LI()
	y = LI()
	x = sorted(x)
	y = sorted(y)
	print(*x)
	print(*y)

def main():
	T = I()
	for i in range(T):
		solve(T)
main()


m = int(input())
l = []
for _ in range(m):
	t = int(input())
	s = ''
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	for i in a:
		s += str(i) + ' '
	s += '\n'
	for i in b:
		s += str(i) + ' '
	l.append(s)
for i in l:
	print(i)


x = int(input())
for i in range(x):
	n = int(input())
	A = sorted((int(new) for new in input().split()))
	B = sorted((int(new) for new in input().split()))
	print(*A)
	print(*B)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input().split()
	b = input().split()
	for i in range(n):
		a[i] = int(a[i])
		b[i] = int(b[i])
	a.sort()
	b.sort()
	for i in range(n):
		a[i] = str(a[i])
		b[i] = str(b[i])
	print(' '.join(a))
	print(' '.join(b))


for _ in range(int(input())):
	t = int(input())
	a = sorted([int(x) for x in input().split()])
	b = sorted([int(x) for x in input().split()])
	aa = [str(x) for x in a]
	bb = [str(x) for x in b]
	print(' '.join(aa))
	print(' '.join(bb))


t = int(input())
for _ in range(t):
	n = int(input())
	a = map(int, input().split())
	b = map(int, input().split())
	a_sort = sorted(a)
	b_sort = sorted(b)
	for i in range(n):
		print(a_sort[i], end=' ')
	print()
	for i in range(n):
		print(b_sort[i], end=' ')


for a0 in range(int(input())):
	n = int(input())
	new = []
	for i in range(2):
		new.append(sorted(list(map(int, input().split()))))
	for i in new:
		print(*i)


for i in range(int(input())):
	n = input()
	a = [int(a) for a in input().split()]
	a.sort()
	b = [int(b) for b in input().split()]
	b.sort()
	for j in a:
		print(str(j), end=' ')
	print()
	for j in b:
		print(str(j), end=' ')


t = int(input())
for _ in range(t):
	m = input()
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a.sort()
	b.sort()
	print(*a)
	print(*b)


from math import ceil, sqrt, gcd, log, floor
from collections import deque

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

def si():
	return input()

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

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

def msi():
	return map(str, input().strip().split(' '))

def lsi():
	return list(msi())
t = ii()
while t:
	t -= 1
	n = ii()
	a = li()
	b = li()
	a.sort()
	b.sort()
	print(*a)
	print(*b)


def solve(A, B, n):
	A.sort()
	B.sort()
	print(' '.join(map(str, A)))
	print(' '.join(map(str, B)))
for case in range(int(input())):
	n = int(input())
	Ne = list(map(int, input().split()))
	Br = list(map(int, input().split()))
	solve(Ne, Br, n)


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


def main():
	t = int(input())
	while t:
		t -= 1
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		for x in sorted(a):
			print(x, end=' ')
		print()
		for x in sorted(b):
			print(x, end=' ')
		print()
main()


T = int(input())
for i in range(T):
	n = int(input())
	lst1 = list(map(int, input().split()))[:n]
	lst2 = list(map(int, input().split()))[:n]
	lst1.sort()
	lst2.sort()
	print(' '.join((str(e) for e in lst1)))
	print(' '.join((str(e) for e in lst2)))


t = int(input())
for k in range(t):
	n = int(input())
	mas1 = list(map(int, input().split()))
	mas2 = list(map(int, input().split()))
	mas1.sort()
	mas2.sort()
	print(*mas1)
	print(*mas2)


import math
k = int(input())
while k > 0:
	n = int(input())
	lista1 = list(map(int, input().split()))
	lista2 = list(map(int, input().split()))
	lista1.sort()
	lista2.sort()
	for i in range(0, n):
		print(lista1[i], end=' ')
	print('')
	for i in range(0, n):
		print(lista2[i], end=' ')
	print('')
	k = k - 1


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l.sort()
	l1.sort()
	print(*l)
	print(*l1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	summs = set()
	visitedb = set()
	ar = []
	br = []
	for j in range(n):
		for h in range(n):
			if b[h] in visitedb or a[j] + b[h] in summs:
				continue
			summs.add(a[j] + b[h])
			visitedb.add(b[h])
			ar.append(str(a[j]))
			br.append(str(b[h]))
			break
	print(' '.join(ar))
	print(' '.join(br))


L = lambda : sorted(map(int, input().split()))
for _ in range(int(input())):
	L()
	print(*L())
	print(*L())


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		n = int(input())
		neck = [int(x) for x in input().split()]
		brace = [int(x) for x in input().split()]
		neck.sort()
		brace.sort()
		yield ' '.join((str(x) for x in neck))
		yield ' '.join((str(x) for x in brace))
t = int(input())
ans = gift()
print(*ans, sep='\n')


for _ in range(int(input())):
	(a, b) = [sorted(map(int, input().split())) for i in range(3)][1:]
	print(*a)
	print(*b)


n = int(input())
for _ in range(n):
	input()
	arr1 = ' '.join(map(str, sorted(map(int, input().split()))))
	arr2 = ' '.join(map(str, sorted(map(int, input().split()))))
	print(arr1)
	print(arr2)


for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(*sorted(a))
	print(*sorted(b))


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	print(*l1, sep=' ')
	print(*l2, sep=' ')


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	A.sort()
	B = list(map(int, input().split()))
	B.sort()
	print(' '.join(map(str, A)))
	print(' '.join(map(str, B)))


t = int(input())
s = []
for ijkf in range(0, t):
	n = int(input())
	aa = input()
	a = aa.split()
	bb = input()
	b = bb.split()
	for i in range(0, n):
		b[i] = int(b[i])
		a[i] = int(a[i])
	a.sort()
	b.sort()
	s.append(a)
	s.append(b)
for i in s:
	for j in i:
		print(j, end=' ')
	print()


for x in range(int(input())):
	input()
	print(*sorted(list(map(int, input().split()))))
	print(*sorted(list(map(int, input().split()))))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	b = list(map(int, input().strip().split(' ')))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


for _ in [0] * int(input()):
	n = int(input())
	x = sorted(list(map(int, input().split())))
	y = sorted(list(map(int, input().split())))
	print(' '.join(map(str, x)))
	print(' '.join(map(str, y)))


def main():
	n = int(input())
	nec = sorted(list(map(int, input().split())))
	br = sorted(list(map(int, input().split())))
	print(*nec)
	print(*br)
t = int(input())
for _ in range(t):
	main()


n = int(input())
for i in range(n):
	a = int(input())
	s = [int(i) for i in input().split()]
	d = [int(i) for i in input().split()]
	s.sort()
	d.sort()
	print(*s)
	print(*d)


t = int(input())
for i in range(t):
	st = input()
	l = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l.sort()
	l2.sort()
	print(*l)
	print(*l2)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	for i in a:
		print(i, end=' ')
	print()
	for i in b:
		print(i, end=' ')
	print()


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


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		x = [int(i) for i in input().split()]
		y = [int(i) for i in input().split()]
		x.sort()
		y.sort()
		print(*x, sep=' ', end='\n')
		print(*y, sep=' ', end='\n')
main()


for i in range(int(input())):
	n = int(input())
	N = [int(i) for i in input().split(' ')]
	B = [int(i) for i in input().split(' ')]
	N.sort()
	B.sort()
	[print(i, end=' ') for i in N]
	print()
	[print(i, end=' ') for i in B]


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(o) for o in input().split()]
	b = [int(p) for p in input().split()]
	a = sorted(a)
	b = sorted(b)
	for k in a:
		print(k, end=' ')
	print()
	for s in b:
		print(s, end=' ')
	print()


def solve(N, A, B):
	A.sort()
	B.sort()
	A.reverse()
	B.reverse()
	return (A, B)
	pass

def main():
	T = int(input())
	while T > 0:
		N = int(input())
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		(X, Y) = solve(N, A, B)
		for i in X:
			print(i, end=' ')
		print()
		for i in Y:
			print(i, end=' ')
		print()
		T = T - 1
	return
main()


def main():
	for _ in range(int(input())):
		n = int(input())
		nk = list(map(int, input().split(' ')))
		br = list(map(int, input().split(' ')))
		nk.sort()
		br.sort()
		print(*nk)
		print(*br)
main()


def main():
	op = ''
	t = int(input())
	for i in range(t):
		n = int(input())
		ip_1 = [int(item) for item in input().split(' ')]
		ip_2 = [int(item) for item in input().split(' ')]
		ip_1.sort()
		ip_2.sort()
		for item in ip_1:
			op += str(item) + ' '
		op += '\n'
		for item in ip_2:
			op += str(item) + ' '
		op += '\n'
	print(op)
main()


import os, sys

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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())
i = 0
t = ii()
while i < t:
	n = ii()
	a = li()
	b = li()
	a.sort()
	b.sort()
	for k in range(0, n):
		print(a[k], end=' ')
	print()
	for k in range(0, n):
		print(b[k], end=' ')
	print()
	i = i + 1


for _ in range(int(input())):
	n = int(input())
	aarr = list(map(int, input().split()))
	barr = list(map(int, input().split()))
	aarr.sort()
	barr.sort()
	print(*aarr)
	print(*barr)


for _ in range(int(input())):
	n = int(input())
	lst1 = [int(i) for i in input().split()]
	lst2 = [int(i) for i in input().split()]
	lst1.sort()
	lst2.sort()
	for i in range(0, n):
		print(lst1[i], end=' ')
	print()
	for i in range(0, n):
		print(lst2[i], end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	sumi = 0
	print(*a)
	print(*b)


def solution(n, a, b):
	sa = ''
	a.sort()
	for e in a:
		sa += str(e) + ' '
	sb = ''
	b.sort()
	for e in b:
		sb += str(e) + ' '
	return [sa.strip(), sb.strip()]
t = int(input())
while t:
	n = int(input())
	a = [int(x) for x in input().strip().split(' ')]
	b = [int(x) for x in input().strip().split(' ')]
	ans = solution(n, a, b)
	print(ans[0])
	print(ans[1])
	t -= 1


n = int(input())
for i in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	p = list(map(int, input().split()))
	l.sort()
	print(*l)
	p.sort()
	print(*p)


for j in range(int(input())):
	t = int(input())
	f = sorted(list(map(int, input().split())))
	s = sorted(list(map(int, input().split())))
	ff = [str(x) for x in f]
	ss = [str(x) for x in s]
	print(' '.join(ff))
	print(' '.join(ss))


t = int(input())
while t > 0:
	n = int(input())
	arr1 = sorted(list(map(int, input().split()))[:n])
	arr2 = sorted(list(map(int, input().split()))[:n])
	print(' '.join(map(str, arr1)))
	print(' '.join(map(str, arr2)))
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	print(' '.join(map(str, sorted(list(map(int, input().split()))))))
	print(' '.join(map(str, sorted(list(map(int, input().split()))))))


r = int(input())
s = []
for i in range(0, r):
	f = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	s.append(a)
	s.append(b)
for i in range(0, len(s)):
	for j in range(0, len(s[i])):
		print(s[i][j], end=' ')
	print('')


ntestcase = int(input())
while ntestcase > 0:
	input()
	necklaces = sorted([int(i) for i in input().split(' ')])
	bracelets = sorted([int(i) for i in input().split(' ')])
	[print(i, end=' ') for i in necklaces]
	print()
	[print(i, end=' ') for i in bracelets]
	print()
	ntestcase -= 1


R = lambda : sorted(map(int, input().split()))
exec(R()[0] * 'R();print(*R()+R());')


from math import factorial
from collections import Counter
from heapq import heapify, heappop, heappush
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 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 = 1000000007
INF = float('inf')

def main():
	for _ in range(N()):
		n = N()
		nk = list(RL())
		br = list(RL())
		nk.sort()
		br.sort()
		print(*nk)
		print(*br)
main()


ts = int(input())
while ts > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	temp1 = ' '.join(map(str, a))
	temp2 = ' '.join(map(str, b))
	print(temp1)
	print(temp2)
	ts -= 1


for ttt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = list(map(int, input().split()))
	l.sort()
	s.sort()
	for j in range(n):
		print(l[j], end=' ')
	print('')
	for j in range(n):
		print(s[j], end=' ')
	print('')


T = int(input())

def getAllindex(list, num):
	return filter(lambda a: list[a] == num, range(0, len(list)))
for _ in range(T):
	n = input()
	n = int(n)
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a.sort()
	b.sort()
	for i in a:
		print(i, end=' ')
	for j in b:
		print(j, end=' ')


import itertools
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	a.sort()
	b.sort()
	for i in a:
		print(i, end=' ')
	print()
	for i in b:
		print(i, end=' ')


test = int(input())
for i in range(test):
	arrSize = int(input())
	arrF = list(map(int, input().split(' ')))
	arrS = list(map(int, input().split(' ')))
	arrF.sort()
	arrS.sort()
	for k in arrF:
		print(k, end=' ')
	print()
	for k in arrS:
		print(k, end=' ')
	print()


for _ in range(int(input())):
	input()
	for _ in range(2):
		print(*sorted(map(int, input().split())))


t = int(input())
for _ in range(t):
	n = int(input())
	l = sorted(list(map(int, input().split())))
	m = sorted(list(map(int, input().split())))
	print(*l)
	print(*m)


t = int(input(''))
for i in range(0, t):
	n = int(input(''))
	l = input('').split(' ')
	q = input('').split(' ')
	for k in range(0, len(l)):
		g = l[k]
		m = int(g)
		l[k] = m
		y = q[k]
		r = int(y)
		q[k] = r
	l.sort()
	q.sort()
	output = ''
	count = ''
	for s in range(0, len(l)):
		output = output + str(l[s]) + ' '
		count = count + str(q[s]) + ' '
	print(output)
	print(count)


def run():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		a.sort()
		b.sort()
		print(*a)
		print(*b)
run()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	na = sorted(a)
	nb = sorted(b)
	for i in na:
		print(i, end=' ')
	print()
	for i in nb:
		print(i, end=' ')
	print()
for _ in range(int(input())):
	main()


t = int(input())
while t:
	t -= 1
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	x.sort()
	y.sort()
	for i in range(n):
		print(x[i], end=' ')
	print()
	for i in range(n):
		print(y[i], end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	ls1 = list(map(int, input().split()))
	ls2 = list(map(int, input().split()))
	ls1.sort()
	ls2.sort()
	print(*ls1)
	print(*ls2)


read = lambda : list(map(int, input().split(' ')))
t = int(input())
for _ in range(t):
	n = int(input())
	a = read()
	b = read()
	a.sort()
	b.sort()
	print(*a)
	print(*b)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append(a[i] + b[i])
	d = len(list(dict.fromkeys(c)))
	if d < n:
		a.sort()
		b.sort()
	for i in range(n - 1):
		print(a[i], end=' ')
	print(a[n - 1])
	for i in range(n):
		print(b[i], end=' ')


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	arr.sort()
	brr.sort()
	for i in range(len(arr)):
		print(arr[i], end=' ')
	print()
	for i in range(len(brr)):
		print(brr[i], end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	a.sort()
	b.sort()
	ans1 = [0] * n
	ans2 = [0] * n
	for i in range(n):
		ans1[i] = a[i]
		ans2[i] = b[i]
	print(*ans1)
	print(*ans2)


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2 ** 62 - 1

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

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

def read_float():
	return float(input())

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

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

def read_str_n():
	return list(map(str, input().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

@mt
def slv(N, A, B):
	ans = 0
	A.sort()
	B.sort()
	for i in permutations(range(N)):
		cand = set()
		for (x, y) in zip(range(N), i):
			s = A[x] + B[y]
			if s in cand:
				break
			else:
				cand.add(s)
		else:
			print(*A)
			print(*[B[j] for j in i])
			return

def main():
	T = read_int()
	for _ in range(T):
		N = read_int()
		A = read_int_n()
		B = read_int_n()
		slv(N, A, B)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	new = []
	i = 0
	while i < n:
		temp = a[i] + b[i]
		if temp not in new:
			new.append(temp)
			i += 1
		else:
			(a[i], a[n // 2]) = (a[n // 2], a[i])
	print(*a, sep=' ')
	print(*b, sep=' ')


from sys import *
input = stdin.readline
listInput = lambda : list(map(int, input().strip().split()))
lineInput = lambda : map(int, input().strip().split())
sJoin = lambda a, sep: f'{sep}'.join(a)
arrJoin = lambda a, sep: f'{sep}'.join(map(str, a))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, int(math.sqrt(n) + 1), 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def main():
	for _ in range(int(input())):
		n = int(input())
		nec = sorted(listInput())
		bec = sorted(listInput())
		print(*nec)
		print(*bec)
main()


t = int(input())
for i in range(t):
	n = int(input())
	arr1 = sorted(map(int, input().split()))
	arr2 = sorted(map(int, input().split()))
	print(' '.join(map(str, arr1)))
	print(' '.join(map(str, arr2)))


def sol():
	t = int(input())
	for tt in range(t):
		n = int(input())
		A = [int(item) for item in input().split()]
		B = [int(item) for item in input().split()]
		A.sort()
		B.sort()
		print(*A)
		print(*B)
sol()


import sys

def main():
	f = sys.stdin
	t = int(f.readline())
	for k in range(t):
		n = int(f.readline())
		a = map(int, f.readline().strip().split())
		b = map(int, f.readline().strip().split())
		a = sorted(a)
		b = sorted(b)
		for i in range(n - 1):
			print(a[i], end=' ')
		print(a[n - 1])
		for i in range(n - 1):
			print(b[i], end=' ')
		print(b[n - 1])
main()


import math
import collections
import bisect

def arrPrint(a):
	return ' '.join([str(i) for i in a])

def gridPrint(a):
	return '\n'.join([' '.join([str(j) for j in a[i]]) for i in range(len(a))])

def isPalindrome(s):
	for i in range(len(s) // 2):
		if not s[i] == s[-i - 1]:
			return False
	return True

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

def solve(n, a, b):
	return arrPrint(sorted(a)) + '\n' + arrPrint(sorted(b))
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	result = solve(n, a, b)
	print(result)


t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	l.sort()
	b.sort()
	for i in range(n):
		print(l[i], end=' ')
	print('\n')
	for i in range(n):
		print(b[i], end=' ')
	print('\n')


t = int(input())
while t != 0:
	n = int(input())
	L1 = list(map(int, input().split()))
	L2 = list(map(int, input().split()))
	L1.sort()
	L2.sort()
	for i in range(n):
		print(L1[i], end=' ')
	print('')
	for i in range(n):
		print(L2[i], end=' ')
	print('')
	t = t - 1


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
test = int_input()
for _ in range(test):
	n = int_input()
	neck = list_input()
	brace = list_input()
	neck.sort()
	brace.sort()
	print(*neck)
	print(*brace)


from sys import stdin

def main():
	readline = stdin.readline
	t = int(readline())
	result = []
	for t_i in range(t):
		n = int(readline())
		a = list(map(int, readline().split()))
		b = list(map(int, readline().split()))
		a.sort()
		b.sort()
		result.append(a)
		result.append(b)
	for li in result:
		print(*li)
main()


(t,) = map(int, input().split())
for _ in range(t):
	(N,) = map(int, input().split())
	X = list(map(int, input().split()))
	Y = list(map(int, input().split()))
	X.sort()
	Y.sort()
	print(*X)
	print(*Y)


for _ in range(0, int(input())):
	input()
	x = sorted(map(int, input().split()))
	y = sorted(map(int, input().split()))
	print(*x)
	print(*y)


t = int(input())
for _ in range(t):
	input()
	for _ in range(2):
		inp = input().split()
		inp.sort(key=int)
		print(' '.join(inp))


import sys
input = sys.stdin.readline

def inp():
	return int(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())
t = inp()
cases = []
for i in range(t):
	n = inp()
	a = inlt()
	b = inlt()
	a.sort()
	b.sort()
	cases.append((a, b))
for (a, b) in cases:
	print(' '.join(map(str, a)))
	print(' '.join(map(str, b)))


from math import ceil

def solve():
	n = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	lst1.sort()
	lst2.sort()
	print(*lst1)
	print(*lst2)
t = int(input())
for i in range(t):
	solve()


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())
		ar = inpt()
		br = inpt()
		ar.sort()
		br.sort()
		for i in range(n):
			print(ar[i], end=' ')
		print()
		for i in range(n):
			print(br[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')
(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())
	print(*sorted([int(x) for x in input().split()]))
	print(*sorted([int(x) for x in input().split()]))


g = int(input())
for ee in range(g):
	n = int(input())
	a = [int(i) for i in input().split(' ', n - 1)]
	b = [int(i) for i in input().split(' ', n - 1)]
	a.sort()
	b.sort()
	for i in range(len(a)):
		print(a[i], end=' ')
	print()
	for i in range(len(a)):
		print(b[i], end=' ')
	print()


from math import floor, ceil
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(' '.join(map(str, a)))
	print(' '.join(map(str, b)))


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

def _():
	return sys.stdin.readline()

def __():
	return sys.stdin.readline().split()
maxn = 200005
q = int(_())
for id in range(q):
	n = int(_())
	print(*sorted(list(map(int, __()))))
	print(*sorted(list(map(int, __()))))


def ab():
	f = int(input())
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	b.sort()
	c.sort()
	print(*b)
	print(*c)
for i in range(0, int(input())):
	ab()


import math
n = int(input())
for t in range(n):
	a = int(input())
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d = [c[i] + b[i] for i in range(a)]
	flag = 0
	for i in range(a):
		aux = d[0]
		d.remove(d[0])
		if aux in d:
			flag = 1
			break
	if flag == 1:
		b.sort()
		d = [c[i] + b[i] for i in range(a)]
		flag = 0
		for i in range(a):
			aux = d[0]
			d.remove(d[0])
			if aux in d:
				flag = 1
				break
	if flag == 1:
		c.sort()
		d = [c[i] + b[i] for i in range(a)]
		flag = 0
		for i in range(a):
			aux = d[0]
			d.remove(d[0])
			if aux in d:
				flag = 1
				break
	for i in range(a - 1):
		print(str(b[i]) + ' ', end='')
	print(b[a - 1])
	for i in range(a - 1):
		print(str(c[i]) + ' ', end='')
	print(c[a - 1])


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 get_num_2_5(n):
	twos = 0
	fives = 0
	while n > 0 and n % 2 == 0:
		n //= 2
		twos += 1
	while n > 0 and n % 5 == 0:
		n //= 5
		fives += 1
	return (twos, fives)

def shift(a, i, num):
	for _ in range(num):
		(a[i], a[i + 1], a[i + 2]) = (a[i + 2], a[i], a[i + 1])

def solution(a, b, n):
	return ' '.join(map(str, sorted(a))) + '\n' + ' '.join(map(str, sorted(b)))

def main():
	T = 1
	T = ri()
	for i in range(T):
		n = ri()
		a = ria()
		b = ria()
		x = solution(a, b, 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()


num_cases = int(input())
for case in range(num_cases):
	n = int(input())
	lst_one = [int(i) for i in input().split(' ')]
	lst_two = [int(i) for i in input().split(' ')]
	lst_one.sort()
	lst_two.sort()
	for one in lst_one:
		print(one, end=' ')
	print()
	for two in lst_two:
		print(two, end=' ')


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
GAP = 3
for t in [wtf[i:i + GAP] for i in range(1, len(wtf), GAP)]:
	n = int(t[0])
	A = sorted(map(int, t[1].split()))
	B = sorted(map(int, t[2].split()))
	print(' '.join(map(str, A)) + '\n' + ' '.join(map(str, B)))


def println(arr):
	for j in range(len(arr)):
		print(arr[j], end=' ')

def func(arr_1, arr_2):
	result_1 = []
	result_2 = []
	(arr_1, arr_2) = (sorted(arr_1), sorted(arr_2))
	for q in range(len(arr_1)):
		result_1.append(arr_1[q])
		result_2.append(arr_2[q])
	println(result_1)
	print()
	println(result_2)
	print()
	return
n = int(input())
for i in range(n):
	k = int(input())
	oj = list(map(int, input().split()))
	br = list(map(int, input().split()))
	func(oj, br)


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce
from collections import deque
import io
import os

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)))
for _ in range(iinput()):
	n = iinput()
	print(' '.join(map(str, sorted(rlinput()))))
	print(' '.join(map(str, sorted(rlinput()))))


def it():
	return sorted([int(x) for x in input().split()])
for t in range(int(input())):
	n = int(input())
	data1 = it()
	data2 = it()
	for i in range(n):
		print(data1[i], end=' ')
	print()
	for i in range(n):
		print(data2[i], end=' ')


t = int(input())
for j in range(t):
	n = int(input())
	lst1 = [int(i) for i in input().split()]
	lst2 = [int(i) for i in input().split()]
	lst1.sort()
	lst2.sort()
	for i in range(len(lst1)):
		print(lst1[i], end=' ')
	for i in range(len(lst2)):
		print(lst2[i], end=' ')


t = int(input())
for _ in range(t):
	n = int(input())
	aa = list(map(int, input().split()))
	bb = list(map(int, input().split()))
	aa.sort()
	bb.sort()
	print(*aa)
	print(*bb)


t = int(input())
(ans1, ans2, ns) = ([], [], [])
for i in range(t):
	n = int(input())
	ns.append(n)
	(x, y, aas, bbs) = ([], [], [], [])
	aas = [int(a) for a in input().split()]
	bbs = [int(a) for a in input().split()]
	aas.sort
	bbs.sort
	(x, y) = (sorted(aas), sorted(bbs))
	ans1.append(x)
	ans2.append(y)
	(s1, s2) = (str(), str())
for i in range(t):
	for j in range(ns[i]):
		print(ans1[i][j], end=' ')
	print('', end='\n')
	for j in range(ns[i]):
		print(ans2[i][j], end=' ')
	print('\n')


t = int(input())
while t != 0:
	n = int(input())
	arrA = sorted(list(map(int, input().split())))
	arrB = sorted(list(map(int, input().split())))
	for i in range(n):
		print(arrA[i], end=' ')
	for i in range(n):
		print(arrB[i], end=' ')
	t -= 1


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


t = int(input())
while t:
	t -= 1
	n = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	l1.sort()
	l2.sort()
	for i in range(n):
		print(l1[i], end=' ')
	print()
	for i in range(n):
		print(l2[i], end=' ')
	print()


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a, sep=' ')
	print(*b, sep=' ')


t = int(input())
for case in range(t):
	n = int(input())
	a = [int(s) for s in input().split(' ')]
	b = [int(s) for s in input().split(' ')]
	a.sort()
	b.sort()
	print(' '.join([str(i) for i in a]))
	print(' '.join([str(j) for j in b]))


t = int(input())
for _ in range(t):
	n = int(input())
	neck = list(map(int, input().split()))
	brac = list(map(int, input().split()))
	neck.sort()
	brac.sort()
	print(*neck)
	for i in range(n):
		tab = list(brac[i:] + brac[:i])
		s = set()
		for (a, b) in zip(neck, tab):
			s.add(a + b)
		if len(s) == n:
			print(*tab)
			break


t = int(input())
for hareen in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	for i in a:
		print(i, end='')
		print(' ', end='')
	print('')
	for i in b:
		print(i, end='')
		print(' ', end='')
	print('')


q = int(input())
for i in range(q):
	x = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a.sort()
	b.sort()
	for i in range(x):
		print(a[i], end=' ')
	print()
	for i in range(x):
		print(b[i], end=' ')
	print()


cases = int(input())
result = []
for _ in range(cases):
	n = int(input())
	necklaces = list(map(int, input().split()))
	bracelets = list(map(int, input().split()))
	necklaces.sort()
	bracelets.sort()
	matrix_brightness = [[0] * n for i in range(n)]
	for i in range(n):
		for j in range(n):
			matrix_brightness[i][j] = necklaces[i] + bracelets[j]
	seen_index = set()
	seen_sum = set()
	result = []
	for i in range(n):
		for j in range(n):
			cur_sum = matrix_brightness[i][j]
			if cur_sum in seen_sum:
				continue
			elif j in seen_index:
				continue
			else:
				seen_sum.add(cur_sum)
				seen_index.add(j)
				result.append((necklaces[i], bracelets[j]))
				break
	for i in range(n):
		print(result[i][0], end=' ')
	print()
	for i in range(n):
		print(result[i][1], end=' ')
	print()


import sys
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_strList_from_str = lambda : list(sys.stdin.readline().strip())
get_int = lambda : int(sys.stdin.readline().strip())
pt = lambda x: sys.stdout.write(str(x))
for i in range(get_int()):
	n = get_int()
	lst1 = sorted(get_list())
	lst2 = sorted(get_list())
	print(*lst1)
	print(*lst2)


t = int(input())
for j in range(0, t):
	n = int(input())
	neck = []
	brace = []
	neck = [int(x) for x in input().split()]
	brace = [int(x) for x in input().split()]
	neck.sort()
	brace.sort()
	for i in neck:
		print(i, end=' ')
	print()
	for i in brace:
		print(i, end=' ')
	if j != t - 1:
		print()


import math, collections, sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)
for _ in range(int(input())):
	solve()


t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	ne = [int(i) for i in input().strip().split()]
	br = [int(i) for i in input().strip().split()]
	ne.sort()
	br.sort()
	print(' '.join((str(i) for i in ne)))
	print(' '.join((str(i) for i in br)))


t = int(input())
for i in range(t):
	n = int(input())
	lista = list(map(int, input().split()))
	listb = list(map(int, input().split()))
	s_lista = sorted(lista)
	s_listb = sorted(listb)
	for i in s_lista:
		print(i, end=' ')
	print()
	for i in s_listb:
		print(i, end=' ')
	print()


for _ in range(int(input())):
	(x, a, b) = (input(), input(), input())
	f = lambda x: ' '.join([str(y) for y in sorted(list(map(int, x.split())))])
	print(f(a))
	print(f(b))


n = int(input())
ans = []
for i in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	k = list(map(int, input().split()))
	l.sort(reverse=True)
	k.sort(reverse=True)
	x = [str(l[j]) for j in range(m)]
	ans.append(x)
	y = [str(k[j]) for j in range(m)]
	ans.append(y)
for i in ans:
	print(' '.join(i))


n = int(input())
for i in range(n):
	n1 = int(input())
	x = list(map(int, input().split()))
	x1 = list(map(int, input().split()))
	x.sort()
	x1.sort()
	for i in range(n1):
		print(x[i], end=' ')
	print('')
	for i in range(n1):
		print(x1[i], end=' ')
	print('')


t = int(input())
for y in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	g = list(map(int, input().split()))
	b.sort()
	g.sort()
	print(*b)
	print(*g)


def testcase():
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a.sort()
	b.sort()
	for i in a:
		print(i, end=' ')
	print()
	for i in b:
		print(i, end=' ')
	print()
t = int(input())
for t_ in range(t):
	testcase()


for _ in range(int(input())):
	n = int(input())
	A = sorted(list(map(int, input().split())))
	B = sorted(list(map(int, input().split())))
	for i in range(len(A)):
		print(A[i], end=' ')
	print()
	for j in range(len(B)):
		print(B[j], end=' ')
	print()


t = int(input().strip())
for i in range(0, t):
	n = int(input())
	a = sorted(list(map(int, input().strip().split()))[:n])
	b = sorted(list(map(int, input().strip().split()))[:n])
	print(*a)
	print(*b)


t = int(input())
while t > 0:
	n = int(input())
	a = map(int, input().split())
	b = map(int, input().split())
	a = sorted(a)
	b = sorted(b)
	for i in a:
		print(i, end=' ')
	print()
	for i in b:
		print(i, end=' ')
	print()
	t -= 1


for _ in range(int(input())):
	n = int(input())
	print(*sorted(map(int, input().split())))
	print(*sorted(map(int, input().split())))


n = int(input())
while n:
	n -= 1
	x = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	l.sort()
	m.sort()
	for i in range(x):
		print(l[i], end=' ')
	print()
	for i in range(x):
		print(m[i], end=' ')
	print()


def solve(A, B):
	print(' '.join([str(x) for x in sorted(A)]))
	print(' '.join([str(x) for x in sorted(B)]))
t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(a) for a in input().split(' ')]
	B = [int(a) for a in input().split(' ')]
	solve(A, B)


for _ in range(int(input())):
	n = int(input())
	arr1 = [int(k) for k in input().split()]
	arr2 = [int(k) for k in input().split()]
	arr1.sort()
	arr2.sort()
	print(*arr1)
	print(*arr2)


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(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(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():
	i = 0
	t = ii()
	while i < t:
		n = ii()
		a = li()
		b = li()
		a.sort()
		b.sort()
		for k in range(0, n):
			print(a[k], end=' ')
		print()
		for k in range(0, n):
			print(b[k], end=' ')
		print()
		i = i + 1
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


t = int(input())
for i in range(t):
	n = int(input())
	neck = [int(i) for i in input().split()]
	brace = [int(i) for i in input().split()]
	neck.sort()
	brace.sort()
	print(*neck)
	print(*brace)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	print(*sorted(l1))
	print(*sorted(l2))


def main():
	times = int(input())
	for _ in range(times):
		n = int(input())
		data1 = list(map(int, input().split()))
		data1.sort()
		print(' '.join(map(str, data1)))
		data2 = list(map(int, input().split()))
		data2.sort()
		print(' '.join(map(str, data2)))
main()


import sys

def get_single_int():
	return int(sys.stdin.readline().strip())

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

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
for i in range(get_single_int()):
	n = get_single_int()
	ar1 = get_list()
	ar2 = get_list()
	print(*list(sorted(ar1)))
	print(*list(sorted(ar2)))


def answer():
	n = int(input())
	while n:
		a = int(input())
		b = [int(x) for x in input().split()]
		c = [int(x) for x in input().split()]
		b.sort()
		c.sort()
		i = 0
		c_out1 = ''
		c_out2 = ''
		while i < len(b):
			c_out1 += str(b[i])
			c_out2 += str(c[i])
			i += 1
			if i != len(b):
				c_out1 += ' '
				c_out2 += ' '
		print(c_out1)
		print(c_out2)
		n -= 1
answer()


T = int(input())
for kase in range(T):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	print(*a)
	print(*b)


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	repeat = True
	while repeat:
		repeat = False
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				(a[i], a[i + 1]) = (a[i + 1], a[i])
				repeat = True
			if b[i] > b[i + 1]:
				(b[i], b[i + 1]) = (b[i + 1], b[i])
				repeat = True
	a = list(map(str, a))
	b = list(map(str, b))
	print(' '.join(a))
	print(' '.join(b))


for _ in range(int(input())):
	n = int(input())
	neck = list(map(int, input().split()))
	brac = list(map(int, input().split()))
	neck.sort()
	brac.sort()
	print(*neck, sep=' ')
	print(*brac, sep=' ')


for _ in range(int(input())):
	x = int(input())
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	li1.sort()
	li2.sort()
	print(*li1)
	print(*li2)


INF = 10 ** 10

def main():
	n = get_list()
	l1 = get_list()
	l2 = get_list()
	l1.sort()
	l2.sort()
	print(' '.join(map(str, l1)))
	print(' '.join(map(str, l2)))
import sys
from collections import defaultdict, Counter, deque
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]
print(*out, sep='\n')


import math
q = int(input())
for _ in range(q):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	print(*l1)
	print(*l2)


neck = []
brace = []
t = int(input())
for z in range(t):
	neck = []
	brace = []
	n = int(input())
	a = input().split()
	b = input().split()
	neck = [int(i) for i in a]
	brace = [int(i) for i in b]
	lneck = len(neck)
	lbrace = len(brace)
	for i in neck:
		if i < 0:
			lneck = -1
	for i in brace:
		if i < 0:
			lbrace = -1
	if lneck != n or lbrace != n:
		break
	neck.sort()
	brace.sort()
	add = [neck[i] + brace[i] for i in range(len(neck))]
	if len(add) == len(set(add)):
		print(*neck)
		print(*brace)


import sys
t = int(sys.stdin.readline())
for i in range(t):
	n = int(sys.stdin.readline())
	a = [int(x) for x in sys.stdin.readline().split()]
	b = [int(y) for y in sys.stdin.readline().split()]
	a.sort()
	b.sort()
	for w in range(n):
		print(a[w], end=' ')
	print()
	for e in range(n):
		print(b[e], end=' ')
	print()


def print_ar(a):
	for i in a:
		print(i, end=' ')
	print()

def solve(n, A, B):
	A.sort()
	B.sort()
	print_ar(A)
	print_ar(B)

def main():
	inp = lambda : [int(x) for x in input().split()]
	tc = int(input())
	for _ in range(tc):
		n = int(input())
		A = inp()
		B = inp()
		solve(n, A, B)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	c1 = list(map(int, input().split(' ')))
	c2 = list(map(int, input().split(' ')))
	c1.sort()
	c2.sort()
	print(*c1, sep=' ')
	print(*c2, sep=' ')


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = [int(x) for x in input().split()]
		B = [int(x) for x in input().split()]
		A.sort()
		B.sort()
		print(*A)
		print(*B)
main()


for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = list(map(int, input().split()))
	d.sort()
	l.sort()
	print(*l)
	print(*d)


for _ in range(int(input())):
	n = int(input())
	arr1 = [int(x) for x in input().split(' ')]
	arr2 = [int(x) for x in input().split(' ')]
	arr1.sort()
	arr2.sort()
	out = ''
	for i in arr1:
		out = out + str(i) + ' '
	print(out)
	out = ''
	for i in arr2:
		out = out + str(i) + ' '
	print(out)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a.sort()
	b.sort()
	works = False
	while not works:
		sums = []
		for i in range(n):
			sums.append(a[i] + b[i])
		st = set(sums)
		if len(st) < n:
			p = a.pop()
			a = [p] + a
		else:
			works = True
	print(*a)
	print(*b)


T = int(input())
for _ in range(T):
	n = int(input())
	A = sorted(list(map(int, input().split())))
	B = sorted(list(map(int, input().split())))
	print(*A)
	print(*B)


I = input
for _ in [0] * int(I()):
	n = I()
	print(*sorted(list(map(int, I().split()))), '\n', *sorted(list(map(int, I().split()))))


def sort(list):
	size = len(list)
	for i in range(size):
		for j in range(i + 1, size):
			if list[i] > list[j]:
				temp = list[i]
				list[i] = list[j]
				list[j] = temp
	return list
test = int(input())
for i in range(test):
	daug = int(input())
	b1 = list(map(int, input().split()))
	b2 = list(map(int, input().split()))
	print(*sort(b1))
	print(*sort(b2))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	necklace = list(map(int, input().split()))
	bracelet = list(map(int, input().split()))
	necklace.sort()
	bracelet.sort()
	print(*necklace)
	print(*bracelet)


num_t = int(input())
for _ in range(num_t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	print(' '.join(map(str, sorted(a))))
	print(' '.join(map(str, sorted(b))))


for hui in range(int(input())):
	n = int(input())
	oz = list(map(int, input().split()))
	br = list(map(int, input().split()))
	oz.sort()
	br.sort()
	print(' '.join(map(str, oz)))
	print(' '.join(map(str, br)))


t = int(input())
ans = []
for _ in range(t):
	tn = int(input())
	ta = list(map(int, input().split()))
	tb = list(map(int, input().split()))
	ta.sort()
	tb.sort()
	ans.append([ta, tb])
for (lx, ly) in ans:
	print(*lx)
	print(*ly)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	arr.sort()
	brr.sort()
	print(*arr)
	print(*brr)


for t in range(int(input())):
	n = int(input())
	print(*sorted([int(i) for i in input().split()]))
	print(*sorted([int(i) for i in input().split()]))


t = int(input())
while t:
	n = input()
	print(*sorted(list(map(int, input().split()))))
	print(*sorted(list(map(int, input().split()))))
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	necklace = list(map(int, input().split()))
	bracelet = list(map(int, input().split()))
	necklace.sort()
	bracelet.sort()
	print(*necklace)
	print(*bracelet)


t = int(input())
while t:
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	print(*l1)
	print(*l2)
	t -= 1


t = int(input())
for i in range(t):
	check = []
	a1 = []
	b1 = []
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	for j in range(len(a)):
		for k in range(len(b)):
			if a[j] + b[k] not in check:
				a1.append(a[j])
				b1.append(b[k])
				check.append(a[j] + b[k])
				b.remove(b[k])
				break
	for j in range(len(a1)):
		print(a1[j], end=' ')
	print()
	for j in range(len(b1)):
		print(b1[j], end=' ')
	print()


t = int(input())
while t:
	n = int(input())
	neck = list(map(int, input().split()))
	brace = list(map(int, input().split()))
	neck.sort()
	brace.sort()
	for i in range(n):
		print(neck[i], end=' ')
	print()
	for i in range(n):
		print(brace[i], end=' ')
	print()
	t -= 1


t = int(input())
for _ in range(t):
	d = int(input())
	n = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	n.sort()
	b.sort()
	s = n[0] + b[0]
	i = 0
	s = 0
	while i < d:
		if n[i] + b[i] != s:
			s = n[i] + b[i]
			i += 1
	if i == d:
		print(*n)
		print(*b)


q = int(input().strip())
for _ in range(q):
	n = int(input().strip())
	necklace_brightness = list(map(int, input().rstrip().split()))
	bracelet_brightness = list(map(int, input().rstrip().split()))
	necklace_brightness.sort()
	bracelet_brightness.sort()
	print(' '.join(map(str, necklace_brightness)))
	print(' '.join(map(str, bracelet_brightness)))


import sys
import math
Input = sys.stdin.readline
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline().strip())
pt = lambda x: sys.stdout.write(str(x))
for _ in range(get_int()):
	n = get_int()
	a = get_list()
	b = get_list()
	print(*sorted(a))
	print(*sorted(b))


def unique_brightness(x, y):
	x.sort()
	y.sort()
	return (x, y)

def read_line():
	num_test = int(input())
	res = []
	for i in range(num_test):
		num_child = int(input())
		x = input().split()
		x = [int(ch) for ch in x]
		y = input().split()
		y = [int(ch) for ch in y]
		(x, y) = unique_brightness(x, y)
		res.append((x, y))
	for (x, y) in res:
		temp = ''
		for num in x:
			temp += str(num)
			temp += ' '
		print(temp)
		temp = ''
		for num in y:
			temp += str(num)
			temp += ' '
		print(temp)
read_line()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	assert len(a) == len(b) == n
	a.sort()
	b.sort()
	print(*a)
	print(*b)


t = int(input())
for g in range(t):
	n = int(input())
	s1 = [int(f) for f in input().split()]
	s2 = [int(f) for f in input().split()]
	f = 1
	while f:
		f = 0
		for i in range(n):
			for j in range(i + 1, n):
				if s1[i] + s2[i] == s1[j] + s2[j]:
					(s1[i], s1[j]) = (s1[j], s1[i])
					f = 1
	print(*s1)
	print(*s2)


from math import *

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

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


def calculate(necklaces, bracelets, n):
	necklaces.sort()
	bracelets.sort()
	for i in range(n):
		print(necklaces[i], end=' ')
	print()
	for i in range(n):
		print(bracelets[i], end=' ')
t = int(input())
for _ in range(t):
	n = int(input())
	necklaces = list(map(int, input().split()))
	bracelets = list(map(int, input().split()))
	calculate(necklaces, bracelets, n)


for _ in range(int(input())):
	n = int(input())
	ar1 = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	ar1.sort()
	ar2.sort()
	print(*ar1)
	print(*ar2)


n = input()
n = int(n)
for i in range(n):
	m = input()
	sums = {}
	m = int(m)
	ar1 = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	ar1.sort()
	ar2.sort()
	print(' '.join(map(str, ar1)))
	print(' '.join(map(str, ar2)))


from sys import stdin

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

def main():
	tc = int(line())
	for _ in range(tc):
		n = line()
		xs = list(map(int, line().split()))
		ys = list(map(int, line().split()))
		xs.sort()
		ys.sort()
		for item in xs:
			print(item, end=' ')
		print()
		for item in ys:
			print(item, end=' ')
		print()
main()


def f():
	n = int(input())
	A = [int(s) for s in input().split()]
	B = [int(s) for s in input().split()]
	A.sort()
	B.sort()
	print(' '.join((str(a) for a in A)))
	print(' '.join((str(b) for b in B)))
t = int(input())
for i in range(t):
	f()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	neck = list(map(int, input().split()))
	brace = list(map(int, input().split()))
	neck.sort()
	brace.sort()
	print(*neck)
	print(*brace)


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

def solve():
	n = int(input())
	a = li()
	b = li()
	a.sort()
	b.sort()
	print(*a)
	print(*b)
for _ in range(int(input())):
	solve()


import sys
input = sys.stdin.readline

def inp():
	return int(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())

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

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

def main():
	tests = inp()
	for test in range(tests):
		n = inp()
		neck = inlt()
		brace = inlt()
		neck.sort()
		brace.sort()
		pr_list(neck)
		pr_list(brace)
	return 0
main()


q = int(input())
for rewrew in range(q):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	ll1 = [[l1[i], i] for i in range(n)]
	ll2 = [[l2[i], i] for i in range(n)]
	ll1.sort()
	ll2.sort()
	odp1 = []
	odp2 = []
	for i in range(n):
		odp1.append(l1[ll1[i][1]])
		odp2.append(l2[ll2[i][1]])
	print(*odp1)
	print(*odp2)


line_n = int(input())
output = ''
for i in range(line_n):
	num = input()
	sa = input()
	sb = input()
	a = [int(n) for n in sa.strip().split()]
	b = [int(n) for n in sb.strip().split()]
	a.sort()
	b.sort()
	output += ' '.join(map(str, a)) + '\n'
	output += ' '.join(map(str, b)) + '\n'
print(output)


t = int(input())
result = []
for i in range(t):
	n = int(input())
	a = input().split()
	b = input().split()
	for j in range(n):
		a[j] = int(a[j])
		b[j] = int(b[j])
	a.sort()
	b.sort()
	result.append(a)
	result.append(b)
for i in range(2 * t):
	for j in range(len(result[i])):
		print(result[i][j], end=' ')
	print()


import math
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a.sort()
	b.sort()
	print(*a)
	print(*b)


t = int(input())
while t:
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	li = [0] * n
	l1.sort()
	l2.sort()
	for i in range(0, n):
		li[i] = l1[i] + l2[i]
	for i in l1:
		print(i, end=' ')
	for i in l2:
		print(i, end=' ')
	t = t - 1


def solve(n, a, b):
	a.sort()
	b.sort()
	return (a, b)
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(l1, l2) = solve(n, a, b)
	print(' '.join(map(str, l1)))
	print(' '.join(map(str, l2)))


col = int(input())
for _ in range(col):
	n = int(input())
	O = sorted(list(map(int, input().split())))
	B = sorted(list(map(int, input().split())))
	print(*O)
	print(*B)


for j in range(int(input())):
	a = int(input())
	t = list(map(int, input().split()))
	p = list(map(int, input().split()))
	t.sort()
	p.sort()
	print(*t)
	print(*p)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	a.sort()
	b.sort()
	print(*a)
	print(*b)


for _ in range(int(input())):
	m = int(input())
	x = [int(i) for i in input().split()]
	y = [int(i) for i in input().split()]
	x = sorted(x)
	y = sorted(y)
	print(*x)
	print(*y)


for i in range(int(input())):
	n = int(input())
	one = list(map(int, input().split()))
	two = list(map(int, input().split()))
	one.sort()
	two.sort()
	print(*one)
	print(*two)


n = int(input())
for i in range(n):
	a = int(input())
	b = sorted(list(map(int, input().split())))
	c = sorted(list(map(int, input().split())))
	print(*b)
	print(*c)


q = int(input())
for j in range(q):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	for i in a:
		print(i, end=' ')
	print()
	for i in b:
		print(i, end=' ')
	print()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	a1 = list(map(str, a))
	b.sort()
	b1 = list(map(str, b))
	print(' '.join(a1))
	print(' '.join(b1))


import sys
from collections import Counter

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 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = LIST()
	B = LIST()
	A.sort()
	B.sort()
	print(*A)
	print(*B)


for i in range(int(input())):
	n = int(input())
	nek = list(map(int, input().split()))
	brc = list(map(int, input().split()))
	nek.sort()
	brc.sort()
	print(*nek)
	print(*brc)


t = int(input())
for i in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arr1.sort()
	arr2.sort()
	print(*arr1)
	print(*arr2)


from sys import stdin, stdout
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()

def main():
	T = int(rl())
	for _ in range(T):
		n = int(rl())
		A = [int(x) for x in rll()]
		B = [int(x) for x in rll()]
		A.sort()
		B.sort()
		stdout.write(' '.join((str(x) for x in A)))
		stdout.write('\n')
		stdout.write(' '.join((str(x) for x in B)))
		stdout.write('\n')
	stdout.close()
main()


import sys
import math
for _ in range(int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	s = list(map(int, input().split()))
	l = sorted(l)
	s = sorted(s)
	for i in l:
		print(i, end=' ')
	print(' ')
	for i in s:
		print(i, end=' ')
	print(' ')


t = int(input())
for i in range(t):
	n = int(input())
	lst1 = list(map(int, input().strip().split(' ')))
	lst2 = list(map(int, input().strip().split(' ')))
	lst1.sort()
	lst2.sort()
	for j in range(n):
		print(lst1[j], end=' ')
	print()
	for j in range(n):
		print(lst2[j], end=' ')
	print()


for i in range(int(input())):
	n = []
	b = []
	input()
	for e in input().split(' '):
		n.append(int(e))
	for e in input().split(' '):
		b.append(int(e))
	n.sort(reverse=True)
	b.sort(reverse=True)
	print(*n)
	print(*b)


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

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

def lmii():
	return list(mii())
for _ in range(ii()):
	x = ii()
	a = sorted(lmii())
	b = sorted(lmii())
	print(*a)
	print(*b)


T = int(input(''))
for i in range(0, T):
	n = int(input(''))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A.sort(reverse=False)
	B.sort(reverse=False)
	for j in range(0, len(A)):
		print(A[j], end=' ')
	print('')
	for j in range(0, len(B)):
		print(B[j], end=' ')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	d = []
	x = []
	y = []
	for i in a:
		for j in b:
			if i + j not in d:
				d.append(i + j)
				x.append(i)
				y.append(j)
				b.remove(j)
				break
	[print(i, end=' ') for i in x]
	print()
	[print(i, end=' ') for i in y]
	print()


def main():
	for _ in range(int(input())):
		_ = input()
		necklace = sorted(list(map(int, input().split())))
		bracelet = sorted(list(map(int, input().split())))
		for i in range(len(necklace)):
			if i == len(necklace) - 1:
				print(necklace[i])
			else:
				print(necklace[i], end=' ')
		for i in range(len(bracelet)):
			if i == len(bracelet) - 1:
				print(bracelet[i])
			else:
				print(bracelet[i], end=' ')
main()


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	ll = list(map(int, input().split()))
	l.sort()
	ll.sort()
	print(*l)
	print(*ll)
	t -= 1


t = int(input())
(M, L) = ([], [])
for i in range(t):
	n = int(input())
	L = [int(x) for x in input().split()]
	M = [int(x) for x in input().split()]
	if len(L) == 1 and len(M) == 1:
		for k in L:
			print(k)
		for k in M:
			print(k)
	else:
		res1 = sorted(L)
		res2 = sorted(M)
		for i in range(len(res1) - 1):
			print(res1[i], end=' ')
		print(res1[len(res1) - 1])
		for k in range(len(res2) - 1):
			print(res2[k], end=' ')
		print(res2[len(res2) - 1])


t = int(input())
n = []
necklackes = []
bracelets = []
for i in range(t):
	n.append(int(input()))
	necklackes.append([int(x) for x in input().split()])
	bracelets.append([int(x) for x in input().split()])
	necklackes[i].sort()
	bracelets[i].sort()
for i in range(t):
	print(*necklackes[i])
	print(*bracelets[i])


numberOfTestCases = int(input())
for _ in range(numberOfTestCases):
	numberOfDaughters = int(input())
	necklaces = sorted(list(map(int, input().split())))
	bracelets = sorted(list(map(int, input().split())))
	print(*necklaces)
	print(*bracelets)


R = lambda : sorted(map(int, input().split()))
(t,) = R()
exec(t * 'R();print(*R(),*R());')


tc = int(input())
for i in range(tc):
	x = int(input())
	y = list(map(int, input().split()))
	z = list(map(int, input().split()))
	y.sort()
	z.sort()
	str1 = ''
	str2 = ''
	for i in y:
		str1 += str(i) + ' '
	for i in z:
		str2 += str(i) + ' '
	print(str1)
	print(str2)


from sys import stdin, stdout
import bisect
import math

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

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

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

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

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

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	n = inp()
	l = li()
	k = li()
	l.sort()
	k.sort()
	print(*l)
	print(*k)
for _ in range(inp()):
	solve()


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


import sys
import math

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()]
t = read_int()
for i in range(t):
	n = read_int()
	a = read_int_line()
	b = read_int_line()
	a.sort()
	b.sort()
	c = []
	print(*a)
	print(*b)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	s1 = sorted(list(map(int, input().split())))
	s2 = sorted(list(map(int, input().split())))
	print(*s1)
	print(*s2)


t = int(input())
while t > 0:
	n = int(input())
	arr_a = []
	arr_b = []
	line = input().split(' ')
	for i in range(0, n):
		tmp = int(line[i])
		arr_a.append({'index': i, 'value': tmp})
	line = input().split(' ')
	for i in range(0, n):
		tmp = int(line[i])
		arr_b.append({'index': i, 'value': tmp})
	sorted_a = sorted(arr_a, key=lambda k: k['value'], reverse=False)
	sorted_b = sorted(arr_b, key=lambda k: k['value'], reverse=False)
	result_a = ''
	for i in sorted_a:
		result_a = result_a + ' ' + str(i['value'])
	result_b = ''
	for i in sorted_b:
		result_b = result_b + ' ' + str(i['value'])
	print(result_a.strip())
	print(result_b.strip())
	t -= 1


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A = sorted(A)
	B = sorted(B)
	s = []
	t = []
	p = 0
	for i in range(N):
		s.append(A[i])
		t.append(B[i])
	print(*s)
	print(*t)


def ntvdm():
	t = int(input())
	for _ in range(t):
		input()
		a = sorted(map(int, input().split()))
		b = sorted(map(int, input().split()))
		print(' '.join((str(e) for e in a)))
		print(' '.join((str(e) for e in b)))
ntvdm()


def solve(n, necklaces, bracelets):
	necklaces.sort()
	bracelets.sort()
	return (necklaces, bracelets)
t = int(input())
for _ in range(t):
	n = int(input())
	necklaces = list(map(int, input().split()))
	bracelets = list(map(int, input().split()))
	(X, Y) = solve(n, necklaces, bracelets)
	print(' '.join(map(str, X)))
	print(' '.join(map(str, Y)))


t = int(input())
for i in range(t):
	n = int(input())
	necklaces = [int(i) for i in input().split()]
	bracelets = [int(i) for i in input().split()]
	necklaces.sort()
	bracelets.sort()
	print(*necklaces)
	print(*bracelets)


t = int(input())
while t > 0:
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	for i in range(n):
		print(a[i], end=' ')
	print()
	for i in range(n):
		print(b[i], end=' ')
	print()
	t -= 1


t = int(input())
output = []
for sample in range(t):
	n = int(input())
	a_s = input().split(' ')
	b_s = input().split(' ')
	a = []
	b = []
	for i in range(n):
		a.append(int(a_s[i]))
		b.append(int(b_s[i]))
	a = sorted(a)
	b = sorted(b)
	output.append(a)
	output.append(b)
for i in output:
	for j in i:
		print(j, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	necklace = [int(__) for __ in input().split()]
	bracelet = [int(___) for ___ in input().split()]
	necklace.sort()
	bracelet.sort()
	for i in necklace:
		print(i, end=' ')
	print('')
	for i in bracelet:
		print(i, end=' ')
	print('')


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7
t = int(input())
for i in range(t):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	print(*a)
	print(*b)


kl = int(input())
for l in range(kl):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a.sort()
	b.sort()
	for i in range(n):
		print(a[i], '', end='')
	print()
	for i in range(n):
		print(b[i], '', end='')
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort(reverse=True)
	b.sort(reverse=True)
	print(*a)
	print(*b)


t = int(input())
for t0 in range(t):
	n = int(input())
	As = list(map(int, input().split()))
	Bs = list(map(int, input().split()))
	As.sort()
	Bs.sort()
	print(' '.join(map(str, As)))
	print(' '.join(map(str, Bs)))


def solve():
	n = int(input())
	a = sorted(map(int, input().split()))
	b = sorted(map(int, input().split()))
	for i in a:
		print(i, end=' ')
	print(end='\n')
	for i in b:
		print(i, end=' ')
	print(end='\n')
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for el in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a = sorted(a)
	b = sorted(b)
	for i in range(n):
		print(a[i], end=' ')
	print()
	for i in range(n):
		print(b[i], end=' ')
	print()


def go():
	n = int(input())
	a = map(str, sorted(map(int, input().split())))
	b = map(str, sorted(map(int, input().split())))
	return '\n'.join([' '.join(a), ' '.join(b)])
t = int(input())
ans = []
for _ in range(t):
	ans.append(go())
print('\n'.join(ans))


T = int(input())
for _ in range(T):
	N = int(input())
	xs = [int(x) for x in input().split(' ')]
	ys = [int(x) for x in input().split(' ')]
	xs.sort()
	ys.sort()
	print(' '.join((str(x) for x in xs)))
	print(' '.join((str(x) for x in ys)))


import collections

def solve(n, necklaces, bracelets):
	necklaces.sort()
	bracelets.sort()
	mSet = set()
	return (necklaces, bracelets)
t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	necklaces = list(map(int, input().strip().split()))
	bracelets = list(map(int, input().strip().split()))
	(n, b) = solve(n, necklaces, bracelets)
	print(' '.join(map(str, n)))
	print(' '.join(map(str, b)))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


cases = int(input().strip())
for case in range(cases):
	n = int(input().strip())
	a = sorted(list(map(int, input().strip().split(' '))))
	b = sorted(list(map(int, input().strip().split(' '))))
	print(' '.join(map(str, a)))
	print(' '.join(map(str, b)))


t = int(input())
for i in range(t):
	n = int(input())
	lisA = list(map(int, input().split()))
	lisB = list(map(int, input().split()))
	lisA.sort()
	lisB.sort()
	for i in range(n):
		print(lisA[i], end=' ')
	print()
	for i in range(n):
		print(lisB[i], end=' ')


q = int(input())
for o in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


import sys
from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
import bisect
import heapq as hq

def main():
	try:
		for _ in range(int(input())):
			n = int(input())
			x = list(map(int, input().split()))
			y = list(map(int, input().split()))
			x.sort()
			y.sort()
			print(*x)
			print(*y)
	except:
		pass
P = 1000000007

def search(l, x):
	(a, b) = (0, len(l) - 1)
	while a <= b:
		k = (a + b) // 2
		if l[k] == x:
			return k
		elif l[k] < x:
			a = k + 1
		else:
			b = k - 1
main()


q = int(input())
a = []
b = []
for pp in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(' '.join(map(str, a)))
	print(' '.join(map(str, b)))


for __ in range(int(input())):
	N = int(input())
	A = sorted(list(map(int, input().split())))
	B = sorted(list(map(int, input().split())))
	print(*A)
	print(*B)


for _ in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	s = sorted(list(map(int, input().split())))
	print(*a)
	print(*s)


i = int
cin = input
for v in range(i(cin())):
	u = i(cin())
	print(*sorted(list(map(int, input().split()))))
	print(*sorted(list(map(int, input().split()))))


ans = []
for i in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A.sort()
	B.sort()
	ans.append((A, B))
for kek in ans:
	print(*kek[0])
	print(*kek[1])


t = int(input())
while t > 0:
	n = int(input())
	a = [int(ele) for ele in input().split()]
	b = [int(ele) for ele in input().split()]
	a.sort()
	b.sort()
	for ele in a:
		print(ele, end=' ')
	print('\r')
	for ele in b:
		print(ele, end=' ')
	t -= 1


t = int(input())
while t > 0:
	dict = {}
	n = int(input())
	necklace = list(map(int, input().split(' ')))
	bracelet = list(map(int, input().split(' ')))
	bracelet.sort()
	necklace.sort()
	necklace = list(map(str, necklace))
	bracelet = list(map(str, bracelet))
	print(' '.join(necklace))
	print(' '.join(bracelet))
	t -= 1


import sys
import os
T = int(input())
for i in range(T):
	temp = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(' '.join(list(map(str, a))))
	print(' '.join(list(map(str, b))))


from math import *
zzz = int(input())
for zz in range(zzz):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a.sort()
	b.sort()
	used = set()
	u2 = set()
	segs = []
	for i in range(n):
		j = 0
		while a[j] + b[i] in used or j in u2:
			j += 1
		segs.append([a[j], b[i]])
		used.add(b[i] + a[j])
		u2.add(j)
	for i in segs:
		print(i[0], end=' ')
	print()
	for i in segs:
		print(i[1], end=' ')
	print()


def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	oneLineArrayPrint(a)
	oneLineArrayPrint(b)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	ntest = int(stdin.readline())
	for test in range(ntest):
		n = int(stdin.readline())
		a = [int(x) for x in stdin.readline().split()]
		b = [int(x) for x in stdin.readline().split()]
		a.sort()
		b.sort()
		stdout.write(' '.join([str(x) for x in a]) + '\n')
		stdout.write(' '.join([str(x) for x in b]) + '\n')
	return 0
main()


t = int(input())
for i in range(t):
	l = int(input())
	n = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = []
	y = []
	for i in range(l):
		x.append(max(n))
		y.append(max(b))
		n.remove(max(n))
		b.remove(max(b))
	for i in x:
		print(i, end=' ')
	print()
	for j in y:
		print(j, end=' ')
	print()


from sys import stdin

def solve(a, b):
	a.sort()
	b.sort()
	print(*a)
	print(*b)

def main():
	t = int(stdin.readline().strip())
	for _ in range(t):
		stdin.readline()
		a = [int(x) for x in stdin.readline().strip().split()]
		b = [int(x) for x in stdin.readline().strip().split()]
		solve(a, b)
main()


n = int(input())
for i in range(n):
	nr = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	print(*a)
	print(*b)


import traceback
import math
from collections import defaultdict
from functools import lru_cache

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		nums1 = list(map(int, input().split()))
		nums2 = list(map(int, input().split()))
		nums1.sort()
		nums2.sort()
		print(' '.join(map(str, nums1)))
		print(' '.join(map(str, nums2)))
try:
	ans = main()
except Exception as e:
	traceback.print_exc()


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	ar.sort()
	br.sort()
	print(*ar)
	print(*br)


t = int(input())
for i in range(t):
	n = int(input())
	li = [int(num) for num in input().split(' ', n - 1)]
	li1 = [int(num) for num in input().split(' ', n - 1)]
	li.sort()
	li1.sort()
	print(*li)
	print(*li1)


T = int(input())
for t in range(T):
	n = int(input())
	for j in range(2):
		print(*sorted([int(i) for i in input().split()]))


n = int(input())
for _ in range(n):
	t = int(input())
	array1 = list(map(int, input().split(' ')))
	array2 = list(map(int, input().split(' ')))
	s_array1 = sorted(array1)
	s_array2 = sorted(array2)
	print(' '.join(map(str, s_array1)))
	print(' '.join(map(str, s_array2)))


for _ in range(int(input())):
	n = int(input())
	ansa = ''
	ansb = ''
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	for i in range(n):
		ansa += str(a[i]) + ' '
		ansb += str(b[i]) + ' '
	print(ansa)
	print(ansb)


n = int(input())
for i in range(n):
	x = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


for _ in range(int(input())):
	n = int(input())
	li1 = list(map(int, input().split()))
	li = list(map(int, input().split()))
	li1.sort()
	li.sort()
	print(*li1)
	print(*li)


for i in range(int(input())):
	m = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	l.sort()
	l1.sort()
	for j in range(m):
		print(l[j], end=' ')
	print()
	for j in range(m):
		print(l1[j], end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	arr1 = sorted([int(x) for x in input().split(' ')])
	arr2 = sorted([int(x) for x in input().split(' ')])
	for i in arr1:
		print(i, end=' ')
	print()
	for i in arr2:
		print(i, end=' ')


query = int(input())
for _ in range(query):
	long = int(input())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	for i in range(long - 1):
		if a[i] + b[i] == a[i + 1] + b[i + 1]:
			(b[i], b[i + 1]) = (b[i + 1], b[i])
	print(' '.join(map(str, a)))
	print(' '.join(map(str, b)))


t = int(input())
for _ in range(t):
	n = int(input())
	first = sorted(list([i for i in map(int, input().split())]), reverse=True)
	second = sorted(list([i for i in map(int, input().split())]), reverse=True)
	for i in range(n):
		print(first[i], end=' ')
	print()
	for i in range(n):
		print(second[i], end=' ')


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline().strip('\n'))
	a = sorted([int(x) for x in stdin.readline().split()])
	b = sorted([int(x) for x in stdin.readline().split()])
	for i in range(n):
		print(a[i], end=' ')
	print()
	for i in range(n):
		print(b[i], end=' ')
	print()


q = int(input())
for i in range(q):
	n = int(input())
	a = sorted([int(i) for i in input().split()])
	b = sorted([int(i) for i in input().split()])
	for i in range(len(a)):
		print(a[i], end=' ')
	print()
	for i in range(len(a)):
		print(b[i], end=' ')
	print()


a = int(input())
for i in range(a):
	c = int(input())
	l = list(map(int, input().split()))
	y = list(map(int, input().split()))
	l.sort()
	y.sort()
	print(*l)
	print(*y)


for i in range(int(input())):
	z = int(input())
	a = sorted([int(x) for x in input().split()])
	b = sorted([int(x) for x in input().split()])
	print(' '.join(map(str, a)))
	print(' '.join(map(str, b)))


n = int(input())
for i in range(n):
	d = int(input())
	m = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m.sort()
	b.sort()
	tmp = ''
	for i in m:
		tmp += str(i) + ' '
	print(tmp)
	tmp = ''
	for i in b:
		tmp += str(i) + ' '
	print(tmp)


t = int(input())
for _ in range(t):
	n = int(input())
	brn = list(map(int, input().split()))
	brb = list(map(int, input().split()))
	brb.sort()
	brn.sort()
	print(*brn)
	print(*brb)


t = int(input())
for _ in range(t):
	input()
	print(*list(sorted((int(x) for x in input().split()))))
	print(*list(sorted((int(x) for x in input().split()))))


import sys

def rr():
	return sys.stdin.readline().rstrip()
rp = print

def print(*args, **kwargs):
	rp('DBG:# ', *args, **kwargs, file=sys.stderr)

def rri():
	return int(rr())

def rrl():
	return list(map(int, rr().split()))

def rrt():
	return tuple(map(int, rr().split()))

def rrle():
	return (line.rstrip() for line in sys.stdin.readlines())

def rrtl():
	return [tuple(map(int, l.split())) for l in rrle()]
from collections import defaultdict

def mus(d=lambda : 0):
	return defaultdict(lambda : defaultdict(d))

def dd0(d=lambda : 0):
	return defaultdict(d)

def ms(x, y, d=0):
	return [[0] * y for i in range(x)]

def ar(x, d=0):
	return [d] * x

def ppm(m, n=0, x=0, y=0):
	print('\n'.join(('\t'.join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))

def ppa(a, n):
	print('\t'.join(map(str, a[0:n])))

def ppl(a=0, x=[1]):
	x[0] = a or x[0] + 1
	print('-' + '- -' * 14 + '-# ' + str(x[0] - 2) + ' #-' + '- -' * 14 + '-')

def fltn(a):
	(i for sub in a for i in sub)

def yn(x):
	return 'YES' if x else 'NO'
from itertools import tee
from itertools import accumulate
from itertools import groupby
from itertools import permutations

def pairwise(iterable):
	(a, b) = tee(iterable)
	next(b, None)
	return zip(a, b)

def grp(x, key=None):
	return ((i, sum((1 for _ in g))) for (i, g) in groupby(x, key=key))
import math

def rnar():
	return (*rrl(), rrl())

def rn():
	return (*rrl(),)

def dpp(a, b=''):
	print('#| {} |#:^ {} ^:'.format(a, b))

def str_join(i, sep=' '):
	return sep.join(map(str, i))
MOD17 = 10 ** 9 + 7

def read():
	return (*rnar(), rrl())
	return (*rrl(),)

def solve(n, arr1, arr2):
	arr1.sort()
	arr2.sort()
	ans = ' '.join(map(str, arr1)) + '\n' + ' '.join(map(str, arr2))
	return ans
test_count = rri()
for _ in range(test_count):
	input_data = read()
	result = solve(*input_data)
	rp(result)


t = int(input())
for i in range(t):
	n = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	ai.sort()
	bi.sort()
	for j in range(n):
		print(ai[j], end=' ')
	print()
	for j in range(n):
		print(bi[j], end=' ')
	print()


n = int(input())
sol = []
for i in range(n):
	sp = []
	v = [0 for k in range(n)]
	x = int(input())
	a = []
	b = []
	a = [int(x) for x in input().split(sep=' ')]
	b = [int(x) for x in input().split(sep=' ')]
	a.sort()
	b.sort()
	for i in range(0, x):
		sp.append((a[i], b[i]))
	sol.append(sp)
for x in sol:
	for t in range(len(x)):
		print(x[t][0], end=' ')
	print()
	for t in range(len(x)):
		print(x[t][1], end=' ')
	print()


import sys
inp = sys.stdin.readline

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

def iin():
	return int(input())

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

def main():
	T = iin()
	while T:
		T -= 1
		n = iin()
		a = lin()
		b = lin()
		print(*sorted(a))
		print(*sorted(b))
main()


tc = int(input())
for _ in range(tc):
	n = int(input())
	(*a,) = map(int, input().split())
	(*b,) = map(int, input().split())
	print(*sorted(a))
	print(*sorted(b))


from sys import stdin, stdout
import bisect

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

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

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

def si():
	return stdin.readline()
for i in range(ii()):
	n = ii()
	l1 = li()
	l2 = li()
	l1.sort()
	l2.sort()
	for i in l1:
		print(i, end=' ')
	print('')
	for i in l2:
		print(i, end=' ')
	print('')


for _ in range(int(input())):
	n = int(input())
	s1 = list(map(int, input().split()))
	s2 = list(map(int, input().split()))
	s11 = [0] * n
	s21 = [0] * n
	for i in range(n):
		s11[i] += min(s1)
		s21[i] += min(s2)
		s1.remove(min(s1))
		s2.remove(min(s2))
	print(*s11)
	print(*s21)


t = int(input())
for _ in range(t):
	n = int(input())
	neck = [int(a) for a in input().split()]
	brace = [int(a) for a in input().split()]
	sn = sorted(range(len(neck)), key=neck.__getitem__)
	bn = sorted(range(len(brace)), key=brace.__getitem__)
	for s in sn:
		print(neck[s], end=' ')
	print('')
	for b in bn:
		print(brace[b], end=' ')
	print('')


t = int(input())
for _ in range(t):
	n = int(input())
	neck = list(map(int, input().split()))
	brac = list(map(int, input().split()))
	neck.sort()
	brac.sort()
	for i in neck:
		print(i, end=' ')
	print(' ')
	for i in brac:
		print(i, end=' ')
	print(' ')


t = int(input())
for i in range(t):
	n = int(input())
	A = map(int, input().split())
	B = map(int, input().split())
	A = list(A)
	B = list(B)
	A = sorted(A)
	B = sorted(B)
	for i in A:
		print(i, end=' ')
	for k in B:
		print(k, end=' ')


n = int(input())
for i in range(n):
	t = int(input())
	one = [int(i) for i in input().split()]
	two = [int(i) for i in input().split()]
	one.sort()
	two.sort()
	print(*one)
	print(*two)


arr = []
t = int(input())
for i in range(t):
	arr.append([0, 0])
for j in range(t):
	n = input()
	arr[j][0] = []
	arr[j][1] = []
	a = input()
	for i in a.split():
		arr[j][0].append(int(i))
	b = input()
	for i in b.split():
		arr[j][1].append(int(i))
	arr[j][0] = sorted(arr[j][0])
	arr[j][1] = sorted(arr[j][1])
	print(*arr[j][0])
	print(*arr[j][1])


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

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

def main():
	t = inin()
	for _ in range(t):
		n = inin()
		a = ain()
		b = ain()
		a.sort()
		b.sort()
		print(*a)
		print(*b)
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')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


import sys

def solve(N, A, B):
	A.sort()
	B.sort()
	return ' '.join(map(str, A)) + '\n' + ' '.join(map(str, B))
input = sys.stdin.readline
T = int(input())
for t in range(T):
	(N,) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = solve(N, A, B)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	neck = list(map(int, input().split()))
	brace = list(map(int, input().split()))
	print(' '.join(map(str, sorted(neck))))
	print(' '.join(map(str, sorted(brace))))


t = int(input())
for j in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	d1 = a[0] + b[0]
	i = 1
	while i < n:
		d = a[i] + b[i]
		if d1 == d:
			(b[i + 1], b[i + 2]) = (b[i + 2], b[i + 1])
		else:
			i += 1
			d1 = d
	for j in range(n):
		print(a[j], end=' ')
	print()
	for j in range(n):
		print(b[j], end=' ')
	print()


t = int(input())

def solve():
	n = int(input())
	necklaces = sorted([int(x) for x in input().split()])
	bracelets = sorted([int(x) for x in input().split()])
	for x in necklaces:
		print(x, end=' ')
	print()
	for x in bracelets:
		print(x, end=' ')
	print()
for _ in range(t):
	solve()


from itertools import permutations
t = int(input())
for i in range(t):
	n = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	c = list(map(sum, zip(ai, bi)))
	if len(c) == len(set(c)):
		ai = list(map(str, ai))
		bi = list(map(str, bi))
		print(' '.join(ai))
		print(' '.join(bi))
	else:
		ai.sort()
		c = list(map(sum, zip(ai, bi)))
		if len(c) == len(set(c)):
			ai = list(map(str, ai))
			bi = list(map(str, bi))
			print(' '.join(ai))
			print(' '.join(bi))
		else:
			bi.sort()
			c = list(map(sum, zip(ai, bi)))
			if len(c) == len(set(c)):
				ai = list(map(str, ai))
				bi = list(map(str, bi))
				print(' '.join(ai))
				print(' '.join(bi))
			else:
				ai.sort(reversed=True)
				ai = list(map(str, ai))
				bi = list(map(str, bi))
				print(' '.join(ai))
				print(' '.join(bi))


q = int(input())
for i in range(q):
	n = int(input())
	s = set()
	f = 0
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


def solve():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		a = sorted(a)
		b = sorted(b)
		print(*a)
		print(*b)
solve()


t = int(input())
a = []
for i in range(t):
	b = input()
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	a.append([c, d])
for i in a:
	x = i[0]
	y = i[1]
	x.sort()
	y.sort()
	for j in x:
		print(j, end=' ')
	print()
	for j in y:
		print(j, end=' ')
	print()


import sys
import bisect
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

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

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

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

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 [[val for i in range(n)] for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	a = l()
	b = l()
	a.sort()
	b.sort()
	print(*a)
	print(*b)


for _ in range(int(input())):
	input()
	x = sorted(list(map(int, input().split())))
	y = sorted(list(map(int, input().split())))
	for i in x:
		print(i, end=' ')
	print()
	for j in y:
		print(j, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	s = list(map(int, input().split()))
	w.sort()
	s.sort()
	print(*w)
	print(*s)


cases = int(input())
while cases:
	cases -= 1
	num = int(input())
	arr1 = sorted(map(int, input().split()))
	arr2 = sorted(map(int, input().split()))
	print(*arr1)
	print(*arr2)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.sort()
	l2.sort()
	for i in range(n):
		print(l1[i], end=' ')
	print(end='\n')
	for i in range(n):
		print(l2[i], end=' ')
	print(end='\n')


for _ in range(int(input())):
	n = int(input())
	o = list(map(int, input().split()))
	b = list(map(int, input().split()))
	o.sort()
	b.sort()
	for i in range(len(o)):
		print(o[i], end=' ')
	print(sep='\n')
	for i in range(len(b)):
		print(b[i], end=' ')


PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

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

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

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

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

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

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

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

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

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

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

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

def ls():
	return [i for i in input().split()]
for t in range(ii()):
	t += 1
	n = ii()
	a = li()
	b = li()
	a.sort()
	b.sort()
	print(*a)
	print(*b)


for _ in range(int(input())):
	x = int(input())
	s = list(map(int, input().split()))
	z = sorted(list(map(int, input().split())))
	s.sort()
	print(*s)
	print(*z)


import math
testCases = int(input())
for _ in range(testCases):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	print(*a)
	print(*b)


n = int(input())
for i in range(n):
	ne = int(input())
	a = sorted([int(x) for x in input().split(' ')])
	b = sorted([int(x) for x in input().split(' ')])
	for i in range(ne):
		print(a[i], end=' ')
	print()
	for i in range(ne):
		print(b[i], end=' ')


import sys
input = sys.stdin.readline
t = int(input())
for test in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	print(*sorted(A))
	print(*sorted(B))


terns = int(input())
for tern in range(terns):
	kids = int(input())
	nec = [int(k) for k in input().split()]
	bra = [int(k) for k in input().split()]
	nec.sort()
	bra.sort()
	s1 = ''
	s2 = ''
	for i in range(kids):
		s1 += str(nec[i]) + ' '
		s2 += str(bra[i]) + ' '
	print(s1.rstrip())
	print(s2.rstrip())


def arrange(n, arr1, arr2):
	arr1.sort()
	arr2.sort()
	arr1 = list(map(str, arr1))
	arr2 = list(map(str, arr2))
	print(' '.join(arr1))
	print(' '.join(arr2))
testcases = int(input())
for i in range(testcases):
	size = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arrange(size, arr1, arr2)


T = int(input())
while T != 0:
	T -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	for i in a:
		print(i, end=' ')
	print()
	for i in b:
		print(i, end=' ')
	print()


i = lambda : sorted(map(int, input().split()))
for _ in [0] * i()[0]:
	i()
	for _ in [0, 0]:
		print(*i())


q = int(input().strip())
for _ in range(q):
	n = int(input().strip())
	nb = list(map(int, input().rstrip().split()))
	bb = list(map(int, input().rstrip().split()))
	print(' '.join(map(str, sorted(nb))))
	print(' '.join(map(str, sorted(bb))))


for _ in range(int(input())):
	n = int(input())
	for j in range(2):
		print(*sorted(list(map(int, input().split()))))


t = int(input())
for i in range(t):
	n = int(input())
	ni = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	ni.sort()
	bi.sort()
	print(*ni)
	print(*bi)


t = int(input())
while t > 0:
	n = int(input())
	x = [int(i) for i in input().split()]
	y = [int(i) for i in input().split()]
	x.sort()
	y.sort()
	print(*x)
	print(*y)
	t = t - 1


def main():
	for _ in range(int(input())):
		_ = input()
		necklace = list(map(int, input().split()))
		bracelet = list(map(int, input().split()))
		for i in sorted(necklace):
			print(i, end=' ')
		print()
		for i in sorted(bracelet):
			print(i, end=' ')
main()


tests = int(input())
for te in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	print(*a)
	print(*b)


n = int(input())
for _ in range(n):
	count = int(input())
	for _ in range(2):
		a = list(map(int, input().split()))
		a.sort()
		print(' '.join(map(str, a)))


arr = []
t = int(input())
for i in range(t):
	arr.append([0, 0])

def quicksort(array):
	if len(array) < 2:
		return array
	else:
		pivot = array[0]
	less = [i for i in array[1:] if i <= pivot]
	greater = [i for i in array[1:] if i > pivot]
	return quicksort(less) + [pivot] + quicksort(greater)
for j in range(t):
	n = input()
	arr[j][0] = []
	arr[j][1] = []
	a = input()
	for i in a.split():
		arr[j][0].append(int(i))
	b = input()
	for i in b.split():
		arr[j][1].append(int(i))
	arr[j][0] = quicksort(arr[j][0])
	arr[j][1] = quicksort(arr[j][1])
for i in arr:
	for j in i:
		for k in j:
			print(k, end=' ')
		print()


n = int(input())
Result = []
for i in range(0, n):
	len_ = int(input())
	List_necklace_brightness = list(map(int, input().strip().split()))[0:len_]
	List_bracelet_brightness = list(map(int, input().strip().split()))[0:len_]
	List_necklace_brightness.sort(reverse=True)
	List_bracelet_brightness.sort(reverse=True)
	for j in List_necklace_brightness:
		Result.append(j)
	for j in List_bracelet_brightness:
		Result.append(j)
for i in range(0, len(Result)):
	print(Result[i], end=' ')
	if i % len_ == len_ - 1:
		print('')


for _ in range(int(input())):
	children = int(input())
	necklace = list(map(int, input().split()))
	bracelet = list(map(int, input().split()))
	necklace.sort()
	bracelet.sort()
	print(*necklace)
	print(*bracelet)


t = int(input())

def somaUnica(sum):
	if len(set(sum)) == len(sum):
		return True
	else:
		return False
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sum = [r + s for (r, s) in zip(a, b)]
	if somaUnica(sum):
		print(*a)
		print(*b)
		continue
	a.sort()
	sum = [r + s for (r, s) in zip(a, b)]
	if somaUnica(sum):
		print(*a)
		print(*b)
		continue
	b.sort()
	sum = [r + s for (r, s) in zip(a, b)]
	if somaUnica(sum):
		print(*a)
		print(*b)
		continue
	a.sort(reverse=True)
	sum = [r + s for (r, s) in zip(a, b)]
	if somaUnica(sum):
		print(*a)
		print(*b)
		continue


t = int(input())
while t:
	n = int(input())
	a = input().split()
	b = input().split()
	for i in range(n):
		a[i] = int(a[i])
		b[i] = int(b[i])
	a.sort()
	b.sort()
	print(*a)
	print(*b)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	ne = list(map(int, input().split()))
	br = list(map(int, input().split()))
	ne.sort()
	br.sort()
	print(' '.join(map(str, ne)))
	print(' '.join(map(str, br)))


for _ in range(int(input())):
	n = int(input())
	li1 = sorted(list(map(int, input().split())))
	li2 = sorted(list(map(int, input().split())))
	print(*li1)
	print(*li2)


from math import *
T = int(input())
while T:
	T -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a.sort()
	b.sort()
	for i in a:
		print(i, end=' ')
	print()
	for i in b:
		print(i, end=' ')
	print()


def distribution(l, neck, brace):
	neck.sort()
	brace.sort()
	neck = list(map(str, neck))
	brace = list(map(str, brace))
	seperator = ' '
	print(seperator.join(neck))
	print(seperator.join(brace))
tCase = int(input())
for i in range(tCase):
	l = int(input())
	necklace = list(map(int, input().rstrip().split()))
	bracelet = list(map(int, input().rstrip().split()))
	distribution(l, necklace, bracelet)


test = int(input())
for i in range(test):
	n = int(input())
	nec = [int(j) for j in input().split()]
	brac = [int(k) for k in input().split()]
	nec.sort()
	brac.sort()
	x = ''
	y = ''
	for c in range(n):
		x = x + str(nec[c]) + ' '
		y = y + str(brac[c]) + ' '
	print(x)
	print(y)


hm = int(input())
for _ in range(hm):
	u = int(input())
	lis1 = list(map(int, input().split()))
	lis2 = list(map(int, input().split()))
	lis1 = sorted(lis1)
	lis2 = sorted(lis2)
	print(*lis1, sep=' ')
	print(*lis2, sep=' ')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(j) for j in input().split()]
	c = sorted(a)
	d = sorted(b)
	for i in c:
		print(i, end=' ')
	print()
	for j in d:
		(print(j, end=' '),)
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	A = sorted(map(int, input().split()))
	B = sorted(map(int, input().split()))
	print(*A)
	print(*B)


V = []
T = int(input())
for i in range(T):
	L = int(input())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	V.append(sorted(A))
	V.append(sorted(B))
for X in V:
	print(*X, sep=' ')


for _ in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	set_a = []
	set_b = []
	for i in range(n):
		set_a.append(str(a[i]))
		set_b.append(str(b[i]))
	print(' '.join(set_a))
	print(' '.join(set_b))


n = int(input())
for i in range(n):
	fake = int(input())
	nec = list(map(int, input().strip().split(' ')))
	bre = list(map(int, input().strip().split(' ')))
	su = []

	def vala():
		for j in range(len(nec)):
			su.append(nec[j] + bre[j])
	vala()
	c = True
	t = 0
	while c:
		if len(su) != len(set(su)):
			if t == 0:
				nec.sort(reverse=True)
				bre.sort(reverse=True)
				su.clear()
				vala()
				t += 1
			elif t == 1:
				nec.sort()
				bre.sort()
				su.clear()
				vala()
				t += 1
			elif t == 2:
				nec.sort(reverse=True)
				bre.sort()
				su.clear()
				vala()
				t += 1
			elif t == 3:
				nec.sort()
				bre.sort(reverse=True)
				su.clear()
				vala()
				t += 1
		else:
			c = False
	print(*nec, sep=' ')
	print(*bre, sep=' ')


def main():
	data = []
	n_tasks = int(input())
	for _ in range(n_tasks):
		n_daughters = int(input())
		a_list = list(map(int, input().split()))
		b_list = list(map(int, input().split()))
		data.append([a_list, b_list])
	for task in data:
		a_list = sorted(task[0])
		b_list = sorted(task[1])
		print(' '.join(map(str, a_list)))
		print(' '.join(map(str, b_list)))
main()


tc = int(input())
necklaces = []
bracelets = []
for t in range(tc):
	n = int(input())
	necklaces = list(map(int, input().split()))
	bracelets = list(map(int, input().split()))
	necklaces.sort()
	bracelets.sort()
	for i in range(n):
		print(necklaces[i], end=' ')
	print()
	for i in range(n):
		print(bracelets[i], end=' ')
	print()


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for i in range(t):
	n = int(inp())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	swap = False
	for i in range(n):
		print(a[i], end=' ')
	print('')
	for i in range(n):
		if i == 0:
			print(b[i], end=' ')
		else:
			if swap:
				print[b[i - 1]]
				swap = False
			if not swap:
				if a[i] + b[i] == a[i - 1] + b[i - 1]:
					print(b[i + 1], end=' ')
					swap = True
				else:
					print(b[i], end=' ')
	print('')


def get(*arg):
	if arg[0] == 0:
		cnt = int(input())
		flag = 1
	else:
		flag = 0
	lst = list()
	for i in range(cnt):
		lst2 = list()
		for ii in range(len(arg) - flag):
			if arg[ii + flag] == 1:
				t = input().split()
				tmp = list()
				for iii in t:
					tmp.append(int(iii))
			elif arg[ii + flag] == 2:
				tmp = input().split()
			else:
				tmp = input()
			lst2.append(tmp)
		lst.append(lst2)
	return lst
a = get(0, 1, 1, 1)
for _ in range(len(a)):
	cur = a[_]
	b = sorted(cur[1])
	c = sorted(cur[2])
	print(*b)
	print(*c)


import sys

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

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

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

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

def main():
	input()
	print(' '.join(map(lambda a: str(a[0]), sorted(list(map(lambda a: (int(a[1]), a[0]), enumerate(input().split())))))))
	print(' '.join(map(lambda a: str(a[0]), sorted(list(map(lambda a: (int(a[1]), a[0]), enumerate(input().split())))))))
for i in range(int(sys.stdin.readline())):
	main()


def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a.sort()
	b.sort()
	print(*a)
	print(*b)
t = int(input())
for _ in range(t):
	solve()


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
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 [int(x) for x in sys.stdin.readline().split()]

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

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

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	ans = []
	for _ in range(n):
		a = []
		k = I()
		l1 = LI()
		l2 = LI()
		l1.sort()
		l2.sort()
		a = [l1, l2]
		ans.append(a)
	for (x, y) in ans:
		print(' '.join((str(a) for a in x)))
		print(' '.join((str(a) for a in y)))
main()


for _ in range(int(input())):
	n = int(input())
	a1 = sorted([int(i) for i in input().split()])
	a2 = sorted([int(i) for i in input().split()])
	print(*a1)
	print(*a2)


def main():
	from sys import stdin, stdout
	for _ in range(int(stdin.readline())):
		n = int(stdin.readline())
		a = list(map(int, stdin.readline().split()))
		b = list(map(int, stdin.readline().split()))
		a.sort()
		b.sort()
		for i in a:
			stdout.write(str(i) + ' ')
		stdout.write('\n')
		for i in b:
			stdout.write(str(i) + ' ')
		stdout.write('\n')
main()


for _ in range(int(input())):
	input()
	for _ in range(2):
		print(' '.join(map(str, sorted(map(int, input().split())))))


t = int(input())
for _ in range(t):
	n = int(input())
	print(*sorted([int(el) for el in input().split()]))
	print(*sorted([int(el) for el in input().split()]))


def I():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	print(*sorted(list(I())))
	print(*sorted(list(I())))


T = int(input())
for t in range(T):
	N = int(input())
	necklace = list(map(int, input().split()))
	bracelet = list(map(int, input().split()))
	necklace.sort()
	bracelet.sort()
	for i in range(N):
		print(necklace[i], end=' ')
	print()
	for i in range(N):
		print(bracelet[i], end=' ')
	print()


for u in range(int(input())):
	n = int(input())
	x = [int(q) for q in input().split()]
	y = [int(q) for q in input().split()]
	x = sorted(x)
	y = sorted(y)
	print(*x)
	print(*y)


import sys
from random import shuffle
t = int(input())
for T in range(t):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = sorted(list(map(int, input().split())))
	print(' '.join(map(str, a)))
	print(' '.join(map(str, b)))


def func(l):
	for i in l:
		print(i, end=' ')
	print()
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	z = list(map(int, input().split()))
	l.sort()
	z.sort()
	func(l)
	func(z)


for k in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	jew1 = []
	jew2 = []
	a.sort()
	b.sort()
	for i in range(n):
		jew1.append(a[i])
		jew2.append(b[i])
	print(*jew1)
	print(*jew2)