Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.

You are given a sequence A_{1}, A_{2}, \ldots, A_{N} which contains pairwise distinct elements and a sequence B_{1}, B_{2}, \ldots, B_{N}, which also contains pairwise distinct elements (but not necessarily distinct from elements of A). For each valid i, 1 ≤ A_{i}, B_{i} ≤ 2 \cdot N.

You may rotate B as many times as you want. A rotation consists of moving the first element of the sequence to the end. Afterwards, let's define a sequence C_{1}, C_{2}, \ldots, C_{N} as C_{i} = (A_{i} + B_{i}) \% N for each valid i.

There are N possible sequences C. Find the lexicographically smallest of these sequences.

Note: A sequence x is lexicographically smaller than a different sequence y if x_{i} < y_{i}, where i is the smallest valid index where the sequences x and y differ.

------ Input Format ------ 

- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N.
- The second line contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. 
- The third line contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}. 

------ Output Format ------ 

For each test case, print a single line containing N space-separated integers C_{1}, C_{2}, \ldots, C_{N} denoting the lexicographically smallest sequence.

------ Constraints ------ 

$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10^{5}$
$1 ≤ A_{i}, B_{i} ≤ 2 \cdot N$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$

------ subtasks ------ 

Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
1
3
1 4 5
1 3 4
----- Sample Output 1 ------ 
1 2 0
----- explanation 1 ------ 
Example case 1: After rotating $B$ once, it becomes $(3,4,1)$. Now $C = (1,2,0)$. This is the lexicographically smallest of all possible sequences $C$.

Difficulty: MEDIUM_HARD

Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	a1 = 0
	m = (A[0] + B[0]) % n
	for i in range(1, n):
		b = (A[0] + B[i]) % n
		if m > b:
			m = b
			a1 = i
	a2 = -1
	for i in range(0, n):
		if (A[0] + B[i]) % n == m and i != a1:
			a2 = i
			break
	B *= 2
	C = []
	for i in range(n):
		C.append((A[i] + B[i + a1]) % n)
	if a2 == -1:
		print(*C)
	else:
		D = []
		for i in range(n):
			D.append((A[i] + B[i + a2]) % n)
		if D < C:
			print(*D)
		else:
			print(*C)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	r = n
	f = 0
	i1 = 0
	i2 = 0
	for j in range(n):
		if (a[0] + b[j]) % n <= r:
			if (a[0] + b[j]) % n == r:
				i2 = j
				f = 1
			else:
				i1 = j
				r = (a[0] + b[j]) % n
				f = 0
	l1 = []
	l2 = []
	for k in range(n):
		l1.append((a[k] + b[(k + i1) % n]) % n)
		l2.append((a[k] + b[(k + i2) % n]) % n)
	if f == 1:
		if l1 < l2:
			for z in range(n):
				if z == n - 1:
					print(l1[z])
				else:
					print(l1[z], end=' ')
		else:
			for z in range(n):
				if z == n - 1:
					print(l2[z])
				else:
					print(l2[z], end=' ')
	else:
		for z in range(n):
			if z == n - 1:
				print(l1[z])
			else:
				print(l1[z], end=' ')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	rem = n
	flag = 0
	ind1 = 0
	ind2 = 0
	for i in range(n):
		if (a[0] + b[i]) % n <= rem:
			if (a[0] + b[i]) % n == rem:
				ind2 = i
				flag = 1
			else:
				ind1 = i
				rem = (a[0] + b[i]) % n
				flag = 0
	l1 = []
	l2 = []
	for j in range(n):
		l1.append((a[j] + b[(j + ind1) % n]) % n)
		l2.append((a[j] + b[(j + ind2) % n]) % n)
	if flag == 1:
		if l1 < l2:
			for k in range(n):
				if k == n - 1:
					print(l1[k])
				else:
					print(l1[k], end=' ')
		else:
			for k in range(n):
				if k == n - 1:
					print(l2[k])
				else:
					print(l2[k], end=' ')
	else:
		for k in range(n):
			if k == n - 1:
				print(l1[k])
			else:
				print(l1[k], end=' ')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = a[0]
	cam = n + 1
	for i in range(n):
		if (b[i] + k) % n <= cam:
			cam = (b[i] + k) % n
			z = i
	if b[z] <= n:
		new = b[z] + n
		if new in b:
			x = b.index(new)
		else:
			x = z
	else:
		new = b[z] - n
		if new in b:
			x = b.index(new)
		else:
			x = z
	if x == z:
		for ele in a:
			print((ele + b[z]) % n, end=' ')
			z += 1
			if z >= n:
				z = 0
	else:
		s = []
		p = []
		for ele in a:
			s.append((ele + b[z]) % n)
			p.append((ele + b[x]) % n)
			z += 1
			if z >= n:
				z = 0
			x += 1
			if x >= n:
				x = 0
		if s < p:
			print(*s)
		else:
			print(*p)


try:
	for t in range(int(input())):
		N = int(input())
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		C = []
		small = 1e+18
		array = []
		for i in range(N):
			if (B[i] + A[0]) % N < small:
				small = (B[i] + A[0]) % N
		for i in range(N):
			if (B[i] + A[0]) % N == small:
				array.append(i)
		for i in range(len(array)):
			C.append([])
			y = list(B)
			for j in range(array[i]):
				x = y.pop(0)
				y.append(x)
			for r in range(N):
				C[i].append((y[r] + A[r]) % N)
		minimum = min(C)
		for num in minimum:
			print(num, end=' ')
		print('')
except:
	pass


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	h = []
	(ck, m) = (999999, 999999)
	for i in range(n):
		ck = a[0] + b[i]
		ck = ck % n
		m = min(ck, m)
	for i in range(n):
		ck = a[0] + b[i]
		ck = ck % n
		if ck == m:
			h.append(i)
	if len(h) == 1:
		a1 = h[0]
		pk = 0
		for j in range(a1, n):
			print((a[pk] + b[j]) % n, end=' ')
			pk += 1
		for j in range(a1):
			print((a[pk] + b[j]) % n, end=' ')
			pk += 1
	else:
		a5 = []
		a6 = []
		a1 = h[0]
		pk = 0
		for j in range(a1, n):
			a5.append((a[pk] + b[j]) % n)
			pk += 1
		for j in range(a1):
			a5.append((a[pk] + b[j]) % n)
			pk += 1
		a1 = h[1]
		pk = 0
		for j in range(a1, n):
			a6.append((a[pk] + b[j]) % n)
			pk += 1
		for j in range(a1):
			a6.append((a[pk] + b[j]) % n)
			pk += 1
		if a5 < a6:
			print(*a5)
		else:
			print(*a6)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = []
	loop = range(n)
	for i in a:
		vmin = 2 * n + 1
		idx = []
		for j in loop:
			x = (i + b[j]) % n
			if x < vmin:
				vmin = x
				idx = []
			if x == vmin:
				idx.append((j + 1) % n)
		ans.append(vmin)
		loop = idx
	print(*ans)


def app(A, B, s):
	k = []
	for i in range(N):
		k.append((A[i] + B[i]) % N)
	s.append(k)

def cout(arr):
	for i in range(N):
		print(arr[i], '', end='')
for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	m = (A[0] + B[0]) % N
	for i in range(N):
		if m > (A[0] + B[i]) % N:
			m = (A[0] + B[i]) % N
	i1 = -1
	i2 = -1
	for i in range(N):
		if m == (A[0] + B[i]) % N:
			if i1 == -1:
				i1 = i
			else:
				i2 = i
	k1 = B[i1:] + B[:i1]
	if i2 != -1:
		k2 = B[i2:] + B[:i2]
	s = []
	app(A, k1, s)
	if i2 != -1:
		app(A, k2, s)
	cout(min(s))


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	minn = 1000000000
	for i in range(n):
		if (arr1[0] + arr2[i]) % n < minn:
			minn = (arr1[0] + arr2[i]) % n
			index = i
	minn2 = 1000000000
	for i in range(n):
		if (arr1[0] + arr2[i]) % n < minn2 and index != i:
			minn2 = (arr1[0] + arr2[i]) % n
			index2 = i
	list1 = arr2[index:] + arr2[:index]
	list2 = arr2[index2:] + arr2[:index2]
	flag = 0
	for i in range(n):
		if (arr1[i] + list1[i]) % n < (arr1[i] + list2[i]) % n:
			print(*[(arr1[i] + list1[i]) % n for i in range(n)])
			flag = 1
			break
		elif (arr1[i] + list1[i]) % n > (arr1[i] + list2[i]) % n:
			print(*[(arr1[i] + list2[i]) % n for i in range(n)])
			flag = 1
			break
	if flag == 0:
		print(*[(arr1[i] + list1[i]) % n for i in range(n)])


def compare(x, y, n):
	for i in range(n):
		if x[i] > y[i]:
			return False
		if x[i] < y[i]:
			return True
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	val = 4 * n + 1
	for i in range(n):
		val = min(val, (a[0] + b[i]) % n)
	ind = []
	for i in range(n):
		if (a[0] + b[i]) % n == val:
			ind.append(i)
	x = [(a[i] + b[(i + ind[0]) % n]) % n for i in range(n)]
	if len(ind) == 1:
		print(*x)
	else:
		y = [(a[i] + b[(i + ind[1]) % n]) % n for i in range(n)]
		if compare(x, y, n):
			print(*x)
		else:
			print(*y)


from collections import *
import sys
input = sys.stdin.readline

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

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

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	a = lis()
	b = lis()
	po = 0
	m = 1133223232323
	for i in range(n):
		if (a[0] + b[i]) % n < m:
			m = (a[0] + b[i]) % n
			po = i
	h = []
	for i in range(n):
		if (a[0] + b[i]) % n == m:
			h.append(i)
	res = []
	for i in h:
		l = []
		b1 = b[i:] + b[:i]
		for j in range(n):
			l.append((a[j] + b1[j]) % n)
		res.append(l)
	res.sort()
	print(*res[0])


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	best = n
	bestind = 0
	for i in range(n):
		if (a[0] + b[i]) % n < best:
			best = (a[0] + b[i]) % n
			bestind = i
	choices = [bestind]
	for i in range(n):
		if i != bestind:
			if b[bestind] % n == b[i] % n:
				choices.append(i)
	res = []
	for ind in choices:
		c = b[ind:] + b[:ind]
		lst = []
		for i in range(n):
			lst.append((a[i] + c[i]) % n)
		res.append(lst)
	res = sorted(res)
	ans = res[0]
	ans = [str(i) for i in ans]
	ans = ' '.join(ans)
	print(ans)


def rotate(ind):
	Result = []
	for i in range(n):
		Result.append((A[i] + B[ind]) % n)
		ind += 1
		ind %= n
	return Result

def compute(A, B):
	minn = n
	indexarr = []
	for i in range(n):
		minn = min(minn, (A[0] + B[i]) % n)
	for i in range(n):
		if minn == (A[0] + B[i]) % n:
			indexarr.append(i)
	if len(indexarr) == 1:
		ind = indexarr[0]
		return rotate(ind)
	if len(indexarr) == 2:
		return min(rotate(indexarr[0]), rotate(indexarr[1]))
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	Res = compute(A, B)
	print(*Res)


for _ in range(int(input())):
	n = int(input())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	possible = [[i, i] for i in range(n)]
	i = 0
	while i < n and len(possible) != 1:
		mn = 2 * n + 1
		arr = []
		for (_, j) in possible:
			mn = min(mn, (A[i] + B[j]) % n)
		for (_, j) in possible:
			if (A[i] + B[j]) % n == mn:
				arr.append([_, (j + 1) % n])
		possible = arr
		i += 1
	shift = possible[0][0]
	ans = []
	for i in range(n):
		ans.append((A[i] + B[shift]) % n)
		shift += 1
		shift %= n
	print(*ans)


for i in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	mn = n
	s = []
	for i in range(n):
		cur = (a[0] + b[i]) % n
		if cur < mn:
			mn = cur
			s = [i]
		elif cur == mn:
			s.append(i)
	i = s[0]
	c = b[i:] + b[:i]
	res = [(c[i] + a[i]) % n for i in range(n)]
	if len(s) == 1:
		print(*res)
	if len(s) == 2:
		i = s[1]
		c = b[i:] + b[:i]
		res1 = [(c[i] + a[i]) % n for i in range(n)]
		for i in range(n):
			if res[i] < res1[i]:
				print(*res)
				break
			elif res[i] > res1[i]:
				print(*res1)
				break
			elif i == n - 1:
				print(*res)


def fun1(p, ar, pos):
	if p < ar[0]:
		ar[0] = p
		ar[1] = [pos]
	elif ar[0] == p:
		ar[1].append(pos)
	return ar
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ls = [5 * n, []]
	for i in range(n):
		t = (a[0] + b[i]) % n
		ls = fun1(t, ls, i)
	temp = []
	pos = []
	i = 0
	while i < 2 and i < len(ls[1]):
		temp.append([])
		pos.append(ls[1][i])
		i += 1
	nn = len(pos)
	for i in range(n):
		for j in range(nn):
			temp[j].append((a[i] + b[(i + pos[j]) % n]) % n)
	temp.sort()
	print(*temp[0])


def getSeq(A, B, N):
	s = []
	for i in range(N):
		s.append((A[i] + B[i]) % N)
	return s

def getStr(A):
	s = ''
	for i in A:
		s += str(i) + ' '
	return s.strip()
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()]
	D = {}
	for i in range(N):
		x = (A[0] + B[i]) % N
		if x in D:
			D[x].append(i)
		else:
			D[x] = [i]
	k = float('inf')
	e = None
	for (i, j) in D.items():
		if k > i:
			k = i
			e = j
	C = []
	for i in e:
		C.append(getSeq(A, B[i:] + B[:i], N))
	print(getStr(min(C)), flush=True)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = []
	l4 = []
	l5 = []
	l6 = []
	l7 = []
	for i in range(n):
		l3.append((l1[0] + l2[i]) % n)
	k = min(l3)
	a = l3.index(k)
	l4.append(a)
	for i in range(a + 1, n):
		if l3[i] == k:
			b = i
			l4.append(b)
	if len(l4) == 1:
		l2 = l2[a:] + l2[:a]
		for i in range(n):
			l5.append((l1[i] + l2[i]) % n)
		print(*l5)
	if len(l4) == 2:
		l2 = l2[a:] + l2[:a]
		for i in range(n):
			l5.append((l1[i] + l2[i]) % n)
		l6.append(l5)
		l2 = l2[-a:] + l2[:-a]
		l2 = l2[b:] + l2[:b]
		for i in range(n):
			l7.append((l1[i] + l2[i]) % n)
		l6.append(l7)
		ans = min(l6)
		print(*ans)


import sys
import inspect
import re
import time
import numpy as np

def debug(arg):
	frame = inspect.currentframe()
	try:
		context = inspect.getframeinfo(frame.f_back).code_context
		caller_lines = ''.join([line.strip() for line in context])
		m = re.search('debug\\s*\\((.+?)\\)$', caller_lines)
		if m:
			caller_lines = m.group(1)
		sys.stderr.write(caller_lines + ' = ' + str(arg) + '\n')
	finally:
		del frame
M = 1000000007
yes = lambda : print('YES')
no = lambda : print('NO')

def solve():
	n = int(input())
	a = np.array(input().split(), dtype='int64')
	b = np.array(input().split(), dtype='int64')
	for i in range(n):
		a[i] %= n
		b[i] %= n
	(ind, last) = (0, (a[0] + b[0]) % n)
	for i in range(1, n):
		if (a[0] + b[i]) % n < last:
			ind = i
			last = (a[0] + b[i]) % n
		elif (a[0] + b[i]) % n == last:
			j = 1
			while j < n:
				if (a[j] + b[(i + j) % n]) % n < (a[j] + b[(ind + j) % n]) % n:
					ind = i
					break
				elif (a[j] + b[(i + j) % n]) % n > (a[j] + b[(ind + j) % n]) % n:
					break
				j += 1
	for i in range(ind, n):
		print((a[i - ind] + b[i]) % n, end=' ')
	for i in range(ind):
		print((a[i + n - ind] + b[i]) % n, end=' ')
	pass

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()
if __name__ == 'CP':
	sys.stdin = open('ip.txt', 'r')
	sys.stdout = open('op.txt', 'w')
	sys.stderr = open('error.txt', 'w')
	cs = time.time()
	main()
	ce = time.time()
	sys.stderr.write('%.5f ms' % (ce - cs))


import math
t = int(input())

def make_move(vec, n):
	if n == 0:
		return vec
	else:
		return vec[n:] + vec[:n]
for _ in range(t):
	n = int(input())
	a_vec = input().split(' ')
	b_vec = input().split(' ')
	a_vec = [int(a) for a in a_vec]
	b_vec = [int(b) for b in b_vec]
	if n == 1:
		print((a_vec[0] + b_vec[0]) % n)
		continue
	a0 = a_vec[0]
	c_zero_min = math.inf
	index_zero_min = None
	for i in range(n):
		c0 = (a0 + b_vec[i]) % n
		if c0 < c_zero_min:
			c_zero_min = c0
			index_zero_min = i
	c_one_min = math.inf
	index_one_min = None
	for i in range(n):
		if i == index_zero_min:
			continue
		c0 = (a0 + b_vec[i]) % n
		if c0 < c_one_min:
			c_one_min = c0
			index_one_min = i
	b_zero = make_move(b_vec, index_zero_min)
	b_one = make_move(b_vec, index_one_min)
	c_zero = [(a_vec[i] + b_zero[i]) % n for i in range(n)]
	c_one = [(a_vec[i] + b_one[i]) % n for i in range(n)]
	smaller = c_zero
	for i in range(n):
		if c_zero[i] == c_one[i]:
			continue
		elif c_zero[i] < c_one[i]:
			smaller = c_zero
			break
		elif c_zero[i] > c_one[i]:
			smaller = c_one
			break
	smaller = [str(s) for s in smaller]
	print(' '.join(smaller))


try:
	import math as m
	T = int(input())
	for i in range(T):
		N = int(input())
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		minn = m.inf
		l = list()
		for i in range(N):
			if (A[0] + B[i]) % N < minn:
				l = list()
				minn = (A[0] + B[i]) % N
				l.append(i)
			elif (A[0] + B[i]) % N == minn:
				l.append(i)
		if len(l) > 1:
			i = l[0]
			j = l[1]
			t1 = B[i:] + B[:i]
			t2 = B[j:] + B[:j]
			flg = 0
			for i in range(N):
				x = (A[i] + t1[i]) % N
				y = (A[i] + t2[i]) % N
				if x > y:
					ans = t2
					flg = 1
					break
				elif y > x:
					ans = t1
					flg = 1
					break
			if flg == 0:
				ans = t1
		elif len(l) == 1:
			i = l[0]
			ans = B[i:] + B[:i]
		for i in range(N):
			print((ans[i] + A[i]) % N, end=' ')
		print()
except:
	pass


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mini = n
	for i in range(n):
		if mini > (a[0] + b[i]) % n:
			mini = (a[0] + b[i]) % n
	lists = []
	for i in range(n):
		if mini == (a[0] + b[i]) % n:
			lists2 = []
			for j in range(n):
				padd = (i + j) % n
				lists2.append((a[j] + b[padd]) % n)
			lists.append(lists2)
	ans = lists[0]
	if len(lists) > 1:
		for i in range(n):
			if lists[0][i] > lists[1][i]:
				ans = lists[1]
				break
			elif lists[0][i] < lists[1][i]:
				ans = lists[0]
				break
			else:
				continue
		print(*ans)
	else:
		print(*lists[0])


from sys import stdin

def calc(tarr, j):
	for i in range(j, n):
		res.append((a[i] + tarr[i]) % n)
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	s = 0
	res = []
	one = False
	for i in range(n):
		temp = (a[0] + b[i]) % n
		if i == 0 or temp < s:
			s = temp
			ind1 = i
			one = True
		elif temp == s:
			ind2 = i
			one = False
	res.append(s)
	tarr1 = b[ind1:] + b[:ind1]
	if one == False:
		tarr2 = b[ind2:] + b[:ind2]
		for i in range(1, n):
			temp1 = (a[i] + tarr1[i]) % n
			temp2 = (a[i] + tarr2[i]) % n
			if temp1 < temp2:
				one = True
				break
			elif temp2 < temp1:
				one = False
				break
			else:
				res.append(temp1)
	if one:
		calc(tarr1, len(res))
	else:
		calc(tarr2, len(res))
	print(*res)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ix = 0
	ans = []
	send = []
	l = [i for i in range(n)]
	while ix < n:
		minx = n
		for i in l:
			cool = (b[i] + a[ix]) % n
			if cool == minx:
				send.append((i + 1) % n)
			if cool < minx:
				minx = cool
				send = [(i + 1) % n]
		ans.append(minx)
		l = send
		ix += 1
	for i in ans:
		print(i, end=' ')
	print()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sm = []
	req = -1
	mini = math.inf
	for i in range(n):
		k = (a[0] + b[i]) % n
		if k < mini:
			mini = k
			req = i
	sm.append(req)
	for i in range(n):
		k = (a[0] + b[i]) % n
		if sm[0] != i and k == mini:
			sm.append(i)
			break
	if len(sm) == 1:
		i = sm[0]
		temp = b[i:n] + b[0:i]
		ans = []
		for j in range(n):
			d = (a[j] + temp[j]) % n
			ans.append(d)
		print(*ans)
	else:
		i1 = sm[0]
		temp1 = b[i1:n] + b[0:i1]
		ans1 = []
		for j in range(n):
			d = (a[j] + temp1[j]) % n
			ans1.append(d)
		i2 = sm[1]
		temp2 = b[i2:n] + b[0:i2]
		ans2 = []
		for j in range(n):
			d = (a[j] + temp2[j]) % n
			ans2.append(d)
		ans = min(ans1, ans2)
		print(*ans)


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

	def calc(index, offset):
		return (a[index] + b[(index + offset) % n]) % n
	candidates = list(range(n))
	index = 0
	while len(candidates) > 1 and index < n:
		best_val = n
		for offset in candidates:
			best_val = min(best_val, calc(index, offset))
		best = []
		for offset in candidates:
			if calc(index, offset) == best_val:
				best.append(offset)
		candidates = best
		index += 1
	ans = candidates[0]
	print(' '.join((str(calc(i, ans)) for i in range(n))))


def rotate(i, A, B):
	C = B[i:] + B[0:i]
	return [(C[i] + A[i]) % len(A) for i in range(len(B))]

def fun(A, B):
	ind = []
	n = len(A)
	mini = float('inf')
	for i in range(0, n):
		mini = min(mini, (B[i] + A[0]) % n)
	for i in range(0, n):
		if mini == (A[0] + B[i]) % n:
			ind.append(i)
	if len(ind) == 1:
		return rotate(ind[0], A, B)
	else:
		return min([rotate(ind[i], A, B) for i in range(0, len(ind))])
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = fun(A, B)
	print(*C)


from math import *
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()))
	ans = 10 ** 9
	for i in range(n):
		ans = min((a[0] + b[i]) % n, ans)
	kmp = []
	for i in range(n):
		if (a[0] + b[i]) % n == ans:
			kmp.append(i)
	if len(kmp) == 1:
		b = b[kmp[0]:] + b[:kmp[0]]
		c = []
		for i in range(n):
			c.append((a[i] + b[i]) % n)
		print(*c)
	else:
		b1 = b[kmp[0]:] + b[:kmp[0]]
		c1 = []
		for i in range(n):
			c1.append((a[i] + b1[i]) % n)
		b2 = b[kmp[1]:] + b[:kmp[1]]
		c2 = []
		for i in range(n):
			c2.append((a[i] + b2[i]) % n)
		print(*min(c1, c2))


a = int(input())
for i in range(a):
	n = int(input())
	al = [int(p) for p in input().split()]
	bl = [int(p) % n for p in input().split()]
	fa = al[0]
	tl = [(fa + k) % n for k in bl]
	mi = min(tl)
	mli = []
	nl = [i for (i, x) in enumerate(tl) if x == mi]
	for p in nl:
		nbl = bl[p:n] + bl[0:p]
		c = []
		for j in range(n):
			c.append((al[j] + nbl[j]) % n)
		mli.append(c)
	z = min(mli)
	for f in z:
		print(f, end=' ')


t = int(input())
for z in range(0, t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	min1 = 2 * n + 1
	for i in range(0, n):
		min1 = min(min1, (arr1[0] + arr2[i]) % n)
	count = 0
	for i in range(0, n):
		if (arr1[0] + arr2[i]) % n == min1:
			if count > 0:
				id2 = i
			else:
				id1 = i
			count += 1
	flag = 1
	if count > 1:
		temp1 = arr2[id1:] + arr2[0:id1]
		temp2 = arr2[id2:] + arr2[0:id2]
		for j in range(1, n):
			if (temp1[j] + arr1[j]) % n < (temp2[j] + arr1[j]) % n:
				flag = 1
				break
			elif (temp2[j] + arr1[j]) % n < (temp1[j] + arr1[j]) % n:
				flag = 2
				break
			else:
				continue
	else:
		temp1 = arr2[id1:] + arr2[0:id1]
		flag = 1
	if flag == 1:
		final = temp1
		for j in range(0, n):
			print((arr1[j] + final[j]) % n, end=' ')
		print()
	else:
		final = temp2
		for j in range(0, n):
			print((arr1[j] + final[j]) % n, end=' ')
		print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mine = 10 ** 6 + 5
	for i in range(n):
		m = (a[0] + b[i]) % n
		mine = min(mine, m)
	st = []
	for i in range(n):
		m = (a[0] + b[i]) % n
		if m == mine:
			st.append(i)
	pk = []
	for i in st:
		ans = []
		g = b[i:] + b[:i]
		for j in range(n):
			ans.append((a[j] + g[j]) % n)
		pk.append(ans)
	for i in min(pk):
		print(i, end=' ')
	print()


try:

	def findmin_rotated(pos_match, arrA, arrB, n):
		tmpA = arrB[pos_match[0]:] + arrB[:pos_match[0]]
		if len(pos_match) == 1:
			return tmpA
		else:
			tmpB = arrB[pos_match[1]:] + arrB[:pos_match[1]]
			for i in range(n):
				calA = (tmpA[i] + arrA[i]) % n
				calB = (tmpB[i] + arrA[i]) % n
				if calA < calB:
					return tmpA
				elif calB < calA:
					return tmpB
			return tmpA

	def solve(arrA, arrB, n):
		min_ = 4 * n
		for i in range(n):
			min_ = min(min_, (arrA[0] + arrB[i]) % n)
		pos_match = []
		for i in range(n):
			if (arrA[0] + arrB[i]) % n == min_:
				pos_match.append(i)
		return pos_match
	t = int(input())
	for _ in range(t):
		n = int(input())
		arrA = list(map(int, input().split()))
		arrB = list(map(int, input().split()))
		pos_match = solve(arrA, arrB, n)
		res = findmin_rotated(pos_match, arrA, arrB, n)
		arr = []
		for i in range(n):
			arr.append((res[i] + arrA[i]) % n)
		print(' '.join(map(str, arr)))
except:
	pass


def arrayRotation():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		a = [a[i] for i in range(n)]
		b = [b[i] for i in range(n)]
		minima = 10 ** 5
		for i in range(n):
			minima = min(minima, (a[0] + b[i]) % n)
		index = []
		for i in range(n):
			if (a[0] + b[i]) % n == minima:
				index.append(i)
		ans = [10 ** 9 for i in range(n)]
		for i in index:
			k = 0
			flag = 1
			for j in range(i, n):
				if (a[k] + b[j]) % n > ans[k] and flag:
					break
				elif (a[k] + b[j]) % n < ans[k]:
					flag = 0
					ans[k] = (a[k] + b[j]) % n
				elif not flag:
					ans[k] = (a[k] + b[j]) % n
				k += 1
			for j in range(i):
				if (a[k] + b[j]) % n > ans[k] and flag:
					break
				elif not flag:
					ans[k] = (a[k] + b[j]) % n
				elif (a[k] + b[j]) % n < ans[k]:
					flag = 0
					ans[k] = (a[k] + b[j]) % n
				k += 1
		print(*ans)
arrayRotation()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	hm = dict()
	for i in range(n):
		rem = (a[0] + b[i]) % n
		if rem not in hm:
			hm[rem] = [i]
		else:
			hm[rem].append(i)
	res = []
	mini = min(hm.keys())
	for i in hm[mini]:
		c = b[i:] + b[0:i]
		ans = []
		for j in range(n):
			ans.append((a[j] + c[j]) % n)
		res.append(ans)
	k = min(res)
	print(*k)


from collections import Counter
inp = lambda x: map(int, x.split())
t = int(input())
for _ in range(t):
	n = int(input())
	(a, b) = (list(inp(input())), list(inp(input())))
	(loc, off) = (list(range(n)), 0)
	while len(loc) > 1 and off < n:
		val = n
		for ind in loc:
			if (b[(ind + off) % n] + a[off]) % n < val:
				val = (b[(ind + off) % n] + a[off]) % n
		loc1 = []
		for ind in loc:
			if (b[(ind + off) % n] + a[off]) % n == val:
				loc1.append(ind)
		loc = loc1.copy()
		off += 1
	s = ''
	j = loc[0]
	for i in range(n):
		s += str((a[i] + b[(j + i) % n]) % n) + ' '
	s = s[:-1]
	print(s)


for _ in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mini = 1000000000.0
	for i in range(0, n):
		mini = min(mini, (a[0] + b[i]) % n)
	id1 = id2 = -1
	for i in range(0, n):
		if (a[0] + b[i]) % n == mini:
			if id1 != -1:
				id2 = i
			else:
				id1 = i

	def get(i):
		ans = list()
		cnt = 0
		for j in range(i, n):
			ans.append((a[cnt] + b[j]) % n)
			cnt += 1
		for j in range(0, i):
			ans.append((a[cnt] + b[j]) % n)
			cnt += 1
		return ans
	(r, s) = (list(), list())
	r = get(id1)
	if id2 != -1:
		s = get(id2)
		if r > s:
			(r, s) = (s, r)
	for i in r:
		print(i, end=' ')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ind = []
	mn = 2 * n + 100
	for i in range(n):
		if mn >= (a[0] + b[i]) % n:
			mn = (a[0] + b[i]) % n
	for i in range(n):
		if mn == (a[0] + b[i]) % n:
			ind.append(i)
	ans = []
	for j in ind:
		temp = []
		for i in range(n):
			temp.append((a[i] + b[(j + i) % n]) % n)
		ans.append(temp)
	print(*min(ans))


from collections import Counter

def create(A, B, n, ind):
	C = [(A[i] + B[(i + ind) % n]) % n for i in range(n)]
	return C

def solve(A, B, n):
	index_list = []
	small = float('inf')
	for i in range(n):
		v = (A[0] + B[i]) % n
		if v < small:
			index_list = [i]
			small = v
		elif v == small:
			index_list.append(i)
	ans = [float('inf')] * n
	for ind in index_list:
		ans = min(ans, create(A, B, n, ind))
	return ans
for case in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = solve(A, B, n)
	print(*ans)


import sys

def helper(n, a, b):
	min_val = float('inf')
	ind = []
	for i in range(n):
		temp = (a[0] + b[i]) % n
		if temp == min_val:
			ind.append(i)
		elif temp < min_val:
			min_val = temp
			ind = [i]
	l = []
	for i in ind:
		for j in range(n):
			temp = (a[j] + b[(i + j) % n]) % n
			l.append(temp)
	if len(l) == n:
		return l
	for i in range(n):
		if l[i] < l[i + n]:
			return l[:n]
		elif l[i] > l[i + n]:
			return l[n:]
	return l[:n]
t = int(sys.stdin.readline().strip())
for tt in range(t):
	n = int(sys.stdin.readline().strip())
	a = list(map(int, sys.stdin.readline().strip().split()))
	b = list(map(int, sys.stdin.readline().strip().split()))
	print(*helper(n, a, b))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = 200000
	for i in range(n):
		m = min(m, (a[0] + b[i]) % n)
	l = -1
	r = -1
	for i in range(n):
		if (a[0] + b[i]) % n == m:
			if l == -1:
				l = i
			else:
				r = i
	if r == -1:
		i = 0
		li = []
		for j in range(l, n):
			li.append((a[i] + b[j]) % n)
			i += 1
		for k in range(l):
			li.append((a[i] + b[k]) % n)
			i += 1
		print(*li)
	else:
		i = 0
		li1 = []
		for j in range(l, n):
			li1.append((a[i] + b[j]) % n)
			i += 1
		for k in range(l):
			li1.append((a[i] + b[k]) % n)
			i += 1
		i = 0
		li2 = []
		for j in range(r, n):
			li2.append((a[i] + b[j]) % n)
			i += 1
		for k in range(r):
			li2.append((a[i] + b[k]) % n)
			i += 1
		if li1 > li2:
			print(*li2)
		else:
			print(*li1)


for k in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	minMod = N
	arr = []
	for i in range(N):
		val = (A[0] + B[i]) % N
		if val < minMod:
			minMod = val
	for i in range(N):
		val = (A[0] + B[i]) % N
		if val == minMod:
			arr.append(B[i:] + B[:i])
	res = []
	for arri in arr:
		resi = []
		for i in range(N):
			val = (A[i] + arri[i]) % N
			resi.append(val)
		res.append(resi)
	res = sorted(res)
	print(*res[0])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mini = n
	for i in range(n):
		val = (a[0] + b[i]) % n
		if val < mini:
			mini = val
	lists = []
	for i in range(n):
		val = (a[0] + b[i]) % n
		if val == mini:
			lists.append(b[i:] + b[:i])
	result = []
	for lis in lists:
		ans = []
		for i in range(n):
			val = (a[i] + lis[i]) % n
			ans.append(val)
		result.append(ans)
	result.sort()
	print(*result[0])


from itertools import permutations as per
from math import factorial as fact
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = 10 ** 8
	ind1 = ind2 = -1
	for i in range(n):
		if (a[0] + b[i]) % n < m:
			m = (a[0] + b[i]) % n
			ind1 = i
			ind2 = -1
		elif (a[0] + b[i]) % n == m:
			ind2 = i
	b1 = [] + b[ind1:] + b[:ind1]
	(c1, c2) = ([], [])
	for i in range(n):
		c1.append((a[i] + b1[i]) % n)
	if ind2 != -1:
		b2 = [] + b[ind2:] + b[:ind2]
		for i in range(n):
			c2.append((a[i] + b2[i]) % n)
	if len(c2):
		for i in range(n):
			if c1[i] > c2[i]:
				for j in c2:
					print(j, end=' ')
				break
			elif c1[i] < c2[i]:
				for j in c1:
					print(j, end=' ')
				break
		else:
			for j in c1:
				print(j, end=' ')
	else:
		for i in c1:
			print(i, end=' ')
	print()


import math
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ind = []
	mini = math.inf
	for i in range(n):
		if (a[0] + b[i]) % n < mini:
			ind = []
			ind.append(i)
			mini = (a[0] + b[i]) % n
		elif (a[0] + b[i]) % n <= mini:
			ind.append(i)
	l = []
	for i in ind:
		s = b[i:] + b[:i]
		x = []
		for j in range(n):
			x.append((a[j] + s[j]) % n)
		l.append(x)
	l.sort()
	print(*l[0])


o = int(input())
for i in range(o):
	x = int(input())
	y = list(map(int, input().split()))
	z = list(map(int, input().split()))
	a = []
	b = y[0]
	for k in range(x):
		a.append((b + z[k]) % x)
	l = min(a)
	m = []
	for k in range(x):
		if l == a[k]:
			m.append(k)
	if len(m) == 1:
		for j in range(x):
			print((y[j] + z[(j + m[0]) % x]) % x, end=' ')
	else:
		n = []
		l = []
		for j in range(x):
			n.append(z[(j + m[0]) % x])
			l.append(z[(j + m[1]) % x])
		p = 0
		for j in range(x):
			w = (y[j] + n[j]) % x
			r = (y[j] + l[j]) % x
			if w > r:
				p = 1
				break
			elif r > w:
				p = 0
				break
		if p == 1:
			for j in range(x):
				print((y[j] + l[j]) % x, end=' ')
		else:
			for j in range(x):
				print((y[j] + n[j]) % x, end=' ')
	print()


from collections import deque
t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = deque(b)
	y = deque(b)
	m = 1000000000
	for i in range(n):
		c = (a[0] + b[i]) % n
		if c < m:
			m = c
	d = []
	k = 0
	for i in range(n):
		c = (a[0] + b[i]) % n
		if c == m:
			k += 1
			d.append(i)
	e = []
	f = []
	if k == 2:
		x.rotate(-d[0])
		for i in range(n):
			e.append((a[i] + x[i]) % n)
		y.rotate(-d[1])
		for i in range(n):
			f.append((a[i] + y[i]) % n)
		if e > f:
			for i in range(n):
				print(f[i], end=' ')
		else:
			for i in range(n):
				print(e[i], end=' ')
	else:
		x.rotate(-d[0])
		for i in range(n):
			print((a[i] + x[i]) % n, end=' ')


import sys

def gtt(ind):
	r = []
	c = 0
	for i in range(ind, n):
		r.append((a[c] + b[i]) % n)
		c += 1
	for i in range(ind):
		r.append((a[c] + b[i]) % n)
		c += 1
	return r
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mini = sys.maxsize
	for i in range(n):
		mini = min(mini, (a[0] + b[i]) % n)
	i1 = -1
	i2 = -1
	for i in range(n):
		if (a[0] + b[i]) % n == mini:
			if i1 == -1:
				i1 = i
			else:
				i2 = i
	p = gtt(i1)
	if i2 != -1:
		q = gtt(i2)
		if p > q:
			(p, q) = (q, p)
	for i in p:
		print(i, end=' ')
	print('')


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	min = n
	m = []
	for j in range(n):
		if (a[0] + b[j]) % n < min:
			min = (a[0] + b[j]) % n
			m = [j]
		elif (a[0] + b[j]) % n == min:
			m.append(j)
	if len(m) == 1:
		for j in range(n):
			print((a[j] + b[(j + m[0]) % n]) % n, end=' ')
	else:
		for j in range(n):
			if (a[j] + b[(j + m[0]) % n]) % n < (a[j] + b[(j + m[1]) % n]) % n:
				min = 0
				break
			elif (a[j] + b[(j + m[0]) % n]) % n > (a[j] + b[(j + m[1]) % n]) % n:
				min = 1
				break
		for j in range(n):
			print((a[j] + b[(j + m[min]) % n]) % n, end=' ')


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n == 1:
		print((a[0] + b[0]) % n)
		continue
	l = []
	for x in range(n):
		l.append([(a[0] + b[x]) % n, x])
	l.sort()
	ans = []
	mini = l[0][0]
	for x in l:
		if x[0] == mini:
			index = x[1]
			l1 = []
			i = 0
			for x in range(index, n):
				l1.append((a[i] + b[x]) % n)
				i += 1
			for x in range(index):
				l1.append((a[i] + b[x]) % n)
				i += 1
			ans.append(l1)
		else:
			break
	print(*min(ans))


for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	minim = (a[0] + b[0]) % n
	min_indx = 0
	for j in range(n):
		if (a[0] + b[j]) % n < minim:
			minim = (a[0] + b[j]) % n
			min_indx = j
	arr = []
	for j in range(n):
		if (a[0] + b[j]) % n == minim:
			arr.append(j)
	temp1 = b[arr[0]:] + b[:arr[0]]
	seq1 = []
	for k in range(n):
		seq1.append((a[k] + temp1[k]) % n)
	for j in range(len(arr)):
		temp = b[arr[j]:] + b[:arr[j]]
		seq = []
		for k in range(n):
			seq.append((a[k] + temp[k]) % n)
		k = 0
		while seq1[k] == seq[k]:
			k += 1
			if k == n:
				k -= 1
				break
		if seq1[k] > seq[k]:
			ans = seq
		else:
			ans = seq1
	for j in range(n):
		print(ans[j], end=' ')
	print()


def make_Seq(a, b):
	string = ''
	n = len(a)
	for i in range(n):
		string += str((a[i] + b[i]) % n) + ' '
	return string
for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	minim = (a[0] + b[0]) % n
	min_indx = 0
	for j in range(n):
		if (a[0] + b[j]) % n < minim:
			minim = (a[0] + b[j]) % n
			min_indx = j
	arr = []
	for j in range(n):
		if (a[0] + b[j]) % n == minim:
			arr.append(j)
	if len(arr) == 1:
		b = b[arr[0]:] + b[:arr[0]]
		print(make_Seq(a, b))
	else:
		str1 = b[arr[0]:] + b[:arr[0]]
		str2 = b[arr[1]:] + b[:arr[1]]
		ans1 = [int(x) for x in make_Seq(a, str1).split()]
		ans2 = [int(x) for x in make_Seq(a, str2).split()]
		stringg = min(ans1, ans2)
		ans_String = ''
		for j in range(n):
			ans_String += str(stringg[j]) + ' '
		print(ans_String)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	x = 0
	y = -1
	for i in range(1, n):
		if (arr[0] + brr[i]) % n < (arr[0] + brr[x]) % n:
			y = -1
			x = i
		elif (arr[0] + brr[i]) % n == (arr[0] + brr[x]) % n:
			y = i
	if y < 0:
		for i in range(0, n):
			print((arr[i] + brr[(i + x) % n]) % n, end=' ')
	else:
		i = 0
		while i < n and (arr[i] + brr[(i + x) % n]) % n == (arr[i] + brr[(i + y) % n]) % n:
			print((arr[i] + brr[(i + x) % n]) % n, end=' ')
			i += 1
		if i < n:
			if (arr[i] + brr[(i + x) % n]) % n < (arr[i] + brr[(i + y) % n]) % n:
				while i < n:
					print((arr[i] + brr[(i + x) % n]) % n, end=' ')
					i += 1
			else:
				while i < n:
					print((arr[i] + brr[(i + y) % n]) % n, end=' ')
					i += 1
	print()


def make_Seq(a, b):
	string = ''
	n = len(a)
	for i in range(n):
		string += str((a[i] + b[i]) % n) + ' '
	return string
for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	minim = (a[0] + b[0]) % n
	min_indx = 0
	for j in range(n):
		if (a[0] + b[j]) % n < minim:
			minim = (a[0] + b[j]) % n
			min_indx = j
	arr = []
	for j in range(n):
		if (a[0] + b[j]) % n == minim:
			arr.append(j)
	if len(arr) == 1:
		b = b[arr[0]:] + b[:arr[0]]
		print(make_Seq(a, b))
	else:
		str1 = b[arr[0]:] + b[:arr[0]]
		str2 = b[arr[1]:] + b[:arr[1]]
		flg = 0
		for j in range(n):
			a1 = (a[j] + str1[j]) % n
			b1 = (a[j] + str2[j]) % n
			if a1 > b1:
				ans = str2
				flg = 1
				break
			elif b1 > a1:
				ans = str1
				flg = 1
				break
		if flg != 1:
			ans = str1
		print(make_Seq(a, ans))


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()]
	m = pow(10, 6)
	id2 = id1 = -1
	for i in range(n):
		c = (a[0] + b[i]) % n
		if c == m:
			id2 = i
		if c < m:
			m = c
			id1 = i
	b += b
	c1 = []
	for i in range(n):
		c1.append((a[i] + b[i + id1]) % n)
	if id2 == -1:
		for x in c1:
			print(x, end=' ')
		print()
	else:
		c2 = []
		flag = 0
		for i in range(n):
			c2.append((a[i] + b[i + id2]) % n)
		for i in range(n):
			if c1[i] > c2[i]:
				flag = 1
				break
			elif c1[i] < c2[i]:
				flag = 0
				break
		if flag:
			for x in c2:
				print(x, end=' ')
			print()
		else:
			for x in c1:
				print(x, end=' ')
			print()


import sys
import math
import heapq
from collections import defaultdict as dd
from collections import OrderedDict as od
from collections import deque
from itertools import permutations as pp
from itertools import combinations as cc
from sys import stdin
from functools import cmp_to_key
from functools import lru_cache
from bisect import bisect_left as bs_l
from bisect import bisect_right as bs_r
input = sys.stdin.readline
mod = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 5)
T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	if n == 1:
		print((arr[0] + brr[0]) % n)
		continue
	ll = []
	for i in range(n):
		kk = (arr[0] + brr[i]) % n
		ll.append([kk, i])
	ll.sort()
	mn = ll[0][0]
	ans = []
	for i in ll:
		if i[0] == mn:
			idx = i[1]
			bb = brr[idx:] + brr[:idx]
			res = []
			for j in range(n):
				res.append((arr[j] + bb[j]) % n)
			ans.append(res)
		else:
			break
	print(*min(ans))


import collections
from collections import defaultdict
import math
from math import factorial
from math import gcd
from collections import Counter

def fun(p, q):
	r = []
	for i in range(n):
		r.append((p[i] + q[i]) % n)
	return r

def fun1(p, q):
	for i in range(n):
		if p[i] < q[i]:
			return True
		elif q[i] < p[i]:
			return False
	return False
for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(c) for c in input().split()]
	m = (a[0] + b[0]) % n
	z = [0]
	for i in range(1, n):
		if (a[0] + b[i]) % n < m:
			z = [i]
			m = (a[0] + b[i]) % n
		elif (a[0] + b[i]) % n == m:
			z.append(i)
	ans = []
	for i in z:
		temp = list(b[i:] + b[:i])
		ans.append(fun(a, temp))
	ind = 0
	for i in range(1, len(ans)):
		if not fun1(ans[ind], ans[i]):
			ind = i
	print(*ans[ind])


def soln(a, b):
	mini = pow(10, 9) + 7
	n = len(a)
	for i in range(n):
		mini = min(mini, (a[0] + b[i]) % n)
	index1 = 0
	index2 = 0
	for i in range(n):
		if (a[0] + b[i]) % n == mini:
			if index1 == 0:
				index1 = i
			else:
				index2 = i
	b1 = b[index1:] + b[:index1]
	b2 = b[index2:] + b[:index2]
	s1 = []
	s2 = []
	for i in range(n):
		s1.append((a[i] + b1[i]) % n)
		s2.append((a[i] + b2[i]) % n)
	ans = []
	ans.append(s1)
	ans.append(s2)
	ans.sort()
	print(*ans[0])
T = int(input())
i = 0
ans = []
while i < T:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	soln(a, b)
	i += 1


for _ in range(int(input())):
	n = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	j = -1
	x = 0
	aj = []
	bj = []
	a = f = k = 0
	mi = 10 ** 9
	for i in range(n):
		x = ai[0] + bi[i]
		if x % n < mi:
			k = i
			mi = x % n
	for i in range(n):
		x = ai[0] + bi[i]
		if x % n == mi:
			if i != k:
				j = i
	for i in range(k, k + n):
		a = (ai[i - k] + bi[i % n]) % n
		aj.append(a)
	if j != -1:
		for i in range(j, j + n):
			a = (ai[i - j] + bi[i % n]) % n
			if f == 1:
				aj[i - j] = a
			elif aj[i - j] < a:
				break
			elif aj[i - j] > a:
				f = 1
				aj[i - j] = a
	print(*aj)


for _ in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = a[0]
	m = 1000000000000000000000000000
	index = 0
	for i in range(0, n):
		if (p + b[i]) % n <= m:
			m = (p + b[i]) % n
	index1 = -1
	index2 = -1
	for i in range(0, n):
		if (p + b[i]) % n == m:
			if index1 == -1:
				index1 = i
			else:
				index2 = i
	b1 = []
	for i in range(index1, n):
		b1.append(b[i])
	for i in range(0, index1):
		b1.append(b[i])
	c1 = []
	c2 = []
	if index2 != -1:
		b2 = []
		for i in range(index2, n):
			b2.append(b[i])
		for i in range(0, index2):
			b2.append(b[i])
		for i in range(0, n):
			c1.append((a[i] + b1[i]) % n)
		for i in range(0, n):
			c2.append((a[i] + b2[i]) % n)
		if c1 < c2:
			for i in range(0, n):
				print(c1[i], end=' ')
		else:
			for i in range(0, n):
				print(c2[i], end=' ')
		print()
	else:
		for i in range(0, n):
			c1.append((a[i] + b1[i]) % n)
		for i in range(0, n):
			print(c1[i], end=' ')
		print()


for t in range(int(input())):
	N = int(input())
	A = list(map(lambda x: int(x) % N, input().strip().split(' ')))
	B = list(map(lambda x: int(x) % N, input().strip().split(' ')))
	C = []
	minC = N
	for i in B:
		a = (i + A[0]) % N
		minC = min(minC, a)
	C.append(str(minC))
	checkindice = [i for (i, x) in enumerate(B) if (x + A[0]) % N == minC]
	for checkcounter in range(1, N):
		ref = A[checkcounter]
		if len(checkindice) == 1:
			C.append(str((B[(checkindice[0] + checkcounter) % N] + ref) % N))
		elif B[(checkindice[0] + checkcounter) % N] == B[(checkindice[1] + checkcounter) % N]:
			C.append(str((B[(checkindice[0] + checkcounter) % N] + ref) % N))
		else:
			posC = [(ref + B[(i + checkcounter) % N]) % N for i in checkindice]
			minC = min(posC)
			C.append(str(minC))
			checkindice = [checkindice[posC.index(minC)]]
	print(' '.join(C))


for test in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [0 for x in range(n)]
	x = list()
	u = list()
	t = n
	for i in range(n):
		k = (a[0] + b[i]) % n
		if k <= t:
			t = k
			pos = i
	for i in range(n):
		k = (a[0] + b[i]) % n
		if k == t:
			x.append(i)
	for i in x:
		u.append(b[i:] + b[:i])
	y = len(u)
	for i in range(y):
		for j in range(n):
			u[i][j] = (u[i][j] + a[j]) % n
	u.sort()
	print(*u[0])


def take_arr_input():
	return list(map(int, input().split()))
for _ in range(int(input())):
	n = int(input())
	arr = take_arr_input()
	brr = take_arr_input()
	in_a = arr[0]
	res = (arr[0] + brr[0]) % n
	idx = 0
	for i in range(1, n):
		cal = (in_a + brr[i]) % n
		if cal < res:
			res = cal
			idx = i
		elif cal == res:
			for j in range(1, n):
				a = (arr[j] + brr[(j + idx) % n]) % n
				b = (arr[j] + brr[(j + i) % n]) % n
				if b < a:
					idx = i
					break
				elif b > a:
					break
	new_res = []
	for i in range(n):
		new_res.append((brr[(i + idx) % n] + arr[i]) % n)
	print(*new_res)


def fun(st):
	i = 0
	j = st
	c = []
	while i < n:
		c.append((a[i] + b[j]) % n)
		i += 1
		j += 1
		j %= n
	return c
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	st1 = -1
	st2 = -1
	mn = float('inf')
	for i in range(n):
		x = (a[0] + b[i]) % n
		if x < mn:
			mn = x
			st1 = i
		elif x == mn:
			st2 = i
	if st2 != -1 and (a[0] + b[st1]) % n != (a[0] + b[st2]) % n:
		print(' '.join(map(str, fun(st1))))
	else:
		print(' '.join(map(str, min(fun(st1), fun(st2)))))


def sol(l1, l2, n):
	e = l1[0]
	currminindx = []
	currmin = float('inf')
	for i in range(len(l2)):
		t = (l2[i] + l1[0]) % n
		if t == currmin:
			currminindx.append(i)
		elif t < currmin:
			currminindx = [i]
			currmin = t
	res = []
	for index in currminindx:
		res.append([(i + j) % n for (i, j) in zip(l1, l2[index:] + l2[:index])])
	return min(res)
for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	print(*sol(l1, l2, n))


def calc(a, b, ind, n):
	b1 = ind[0]
	b2 = ind[1]
	i = 0
	while i < n and (a[i] + b[b1]) % n == (a[i] + b[b2]) % n:
		b1 = (b1 + 1) % n
		b2 = (b2 + 1) % n
		i += 1
	if i < n and (b[b1] + a[i]) % n <= (b[b2] + a[i]) % n:
		return ind[0]
	return ind[1]
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	ind = []
	m = int(4 * n) + 1
	for bi in b:
		m = min(m, (bi + a[0]) % n)
	i = 0
	for bi in b:
		if (bi + a[0]) % n == m:
			ind.append(i)
		i += 1
	if len(ind) > 1:
		b_ind = calc(a, b, ind, n)
	else:
		b_ind = ind[0]
	b = b[b_ind:] + b[:b_ind]
	c = []
	for (ai, bi) in zip(a, b):
		c.append((ai + bi) % n)
	for ci in c:
		print(ci, end=' ')
	print()


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

def helper(n, a, b):
	c = []
	for i in range(n):
		c.append((a[i] + b[i]) % n)
	return c

def solve(n, a, b):
	mi = float('inf')
	for i in range(n):
		mi = min((a[0] + b[i]) % n, mi)
	(id1, id2) = (-1, -1)
	for i in range(n):
		if (a[0] + b[i]) % n == mi:
			if id1 == -1:
				id1 = i
			else:
				id2 = i
	if id2 == -1:
		b = b[id1:] + b[:id1]
		print(*helper(n, a, b))
	else:
		x = b[id1:] + b[:id1]
		y = b[id2:] + b[:id2]
		xarr = helper(n, a, x)
		yarr = helper(n, a, y)
		if xarr < yarr:
			print(*xarr)
		else:
			print(*yarr)
for _ in range(int(input())):
	n = int(input())
	(a, b) = (int_arr(), int_arr())
	solve(n, a, b)


t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mn = 1000000007
	sind = -1
	eqcond = {}
	eq = -1
	for i in range(n):
		x = (b[i] + a[0]) % n
		if x < mn:
			mn = x
			sind = i
			eqcond[mn] = [i]
		elif x == mn:
			try:
				eqcond[mn].append(i)
			except:
				eqcond[mn] = [i]
			mn = x
	z = eqcond[mn]
	if len(z) == 1:
		x = z[0]
		y = 0
		for j in range(x, n):
			print((a[y] + b[j]) % n, end=' ')
			y += 1
		for j in range(x):
			print((a[y] + b[j]) % n, end=' ')
			y += 1
		print(end='\n')
	else:
		(res1, res2) = ([], [])
		x = z[0]
		y = 0
		for j in range(x, n):
			res1.append((a[y] + b[j]) % n)
			y += 1
		for j in range(x):
			res1.append((a[y] + b[j]) % n)
			y += 1
		x = z[1]
		y = 0
		for j in range(x, n):
			res2.append((a[y] + b[j]) % n)
			y += 1
		for j in range(x):
			res2.append((a[y] + b[j]) % n)
			y += 1
		if res1 < res2:
			for i in range(n):
				print(res1[i], end=' ')
			print(end='\n')
		else:
			for i in range(n):
				print(res2[i], end=' ')
			print(end='\n')


for _ in range(int(input())):
	n = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	first = ai[0]
	min_ = (first + bi[0]) % n
	j = [0]
	for i in range(1, len(bi)):
		if (first + bi[i]) % n <= min_:
			min_ = (first + bi[i]) % n
			j.append(i)
	cnt = 1
	res = []
	for j_in in j:
		i_ind = 0
		j_ind = j_in
		cnt = 1
		arr = []
		while cnt <= n:
			arr.append((ai[i_ind] + bi[j_ind]) % n)
			i_ind += 1
			j_ind += 1
			i_ind = i_ind % n
			j_ind = j_ind % n
			cnt += 1
		res.append(arr)
		del arr
	ans = res[0]
	for i in range(1, len(res)):
		if res[i] < ans:
			ans = res[i]
	for i in ans:
		print(i, end=' ')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	pref = (a[0] + b[0]) % n
	cache = []
	index = 0
	for i in range(1, n):
		if (a[0] + b[i]) % n < pref:
			pref = (a[0] + b[i]) % n
			index = i
	for i in range(len(a)):
		if (a[0] + b[i]) % n == pref:
			cache.append(i)
	ans = b[:]
	for ele in cache:
		temp = []
		for i in range(n):
			temp.append((a[i] + b[ele % n]) % n)
			ele += 1
		ans = min(ans, temp)
	print(' '.join(map(str, ans)))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_mod = (a[0] + b[0]) % n
	for j in range(n):
		min_mod = min(min_mod, (a[0] + b[j]) % n)
	points = []
	for j in range(n):
		if (a[0] + b[j]) % n == min_mod:
			points.append(j)
	for k in range(n):
		res = [(a[k] + b[(x + k) % n]) % n for x in points]
		min_val = min(res)
		if res.count(min_val) == 1:
			res = points[res.index(min_val)]
			print(*[(a[p] + b[(res + p) % n]) % n for p in range(n)])
			break
	else:
		print(*[(a[p] + b[p]) % n for p in range(n)])


t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	best = [0]
	for i in range(n):
		if (b[i] + a[0]) % n < (b[best[0]] + a[0]) % n:
			while len(best) != 0:
				best.pop()
			best.append(i)
		elif (b[i] + a[0]) % n == (b[best[0]] + a[0]) % n:
			if i == best[0]:
				pass
			else:
				best.append(i)
		else:
			pass
	bestest = -1
	if len(best) == 1:
		bestest = best[0]
	elif len(best) == 2:
		for j in range(n):
			if (b[(best[0] + j) % n] + a[j]) % n < (b[(best[1] + j) % n] + a[j]) % n:
				bestest = best[0]
				break
			elif (b[(best[1] + j) % n] + a[j]) % n < (b[(best[0] + j) % n] + a[j]) % n:
				bestest = best[1]
				break
			else:
				continue
	for j in range(n):
		print((b[(bestest + j) % n] + a[j]) % n, end=' ')
	print()