def solution():
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = 0
lookup = [0]*(n+m+1)
j = -1
for i in range(n+m):
if (a[i] > b[i] and n) or (a[i] < b[i] and not m):
if (a[i] < b[i] and not m) and j == -1:
j = i
lookup[i] = a[i]
total += a[i]
n -= 1
else:
if (a[i] > b[i] and not n) and j == -1:
j = i
lookup[i] = b[i]
total += b[i]
m -= 1
result = [0]*len(lookup)
result[-1] = total
for i in range(len(lookup)-1):
if i < j and (lookup[i] == a[i]) == (lookup[j] != a[j]):
result[i] = total-lookup[i]+(-lookup[j]+((a[j]+b[j])-lookup[j]))+(a[-1] if lookup[i] != a[i] else b[-1])
else:
result[i] = total-lookup[i]+(a[-1] if lookup[i] == a[i] else b[-1])
return " ".join(map(str, result))
for _ in range(int(input())):
print(solution())
1283B - Candies Division | 1451B - Non-Substring Subsequence |
1408B - Arrays Sum | 1430A - Number of Apartments |
1475A - Odd Divisor | 1454B - Unique Bid Auction |
978C - Letters | 501B - Misha and Changing Handles |
1496A - Split it | 1666L - Labyrinth |
1294B - Collecting Packages | 1642B - Power Walking |
1424M - Ancient Language | 600C - Make Palindrome |
1669D - Colorful Stamp | 1669B - Triple |
1669A - Division | 1669H - Maximal AND |
1669E - 2-Letter Strings | 483A - Counterexample |
3C - Tic-tac-toe | 1669F - Eating Candies |
1323B - Count Subrectangles | 991C - Candies |
1463A - Dungeon | 1671D - Insert a Progression |
1671A - String Building | 1671B - Consecutive Points Segment |
1671C - Dolce Vita | 1669G - Fall Down |