import sys
input = sys.stdin.readline
def bin_search(target):
start = 0
end = m - 1
while start < end:
mid = (start + end) // 2
if b[mid] == target:
return mid
elif b[mid] < target:
start = mid + 1
elif b[mid] > target:
end = mid - 1
return end
def find_c():
cur = c[2]
idx = 2
if c[1] <= cur:
cur = c[1]
idx = 1
if c[0] <= cur:
idx = 0
return idx
for _ in range(int(input().rstrip())):
n, m = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
b = sorted(list(map(int, input().rstrip().split())))
sum_val = 0
for i in range(n):
idx = bin_search(a[i])
c = []
c.append(abs(b[idx - 1] - a[i]))
c.append(abs(b[idx] - a[i]))
c.append(abs(b[(idx + 1) % m] - a[i]))
sum_val += b[idx + find_c() - 1]
print(sum_val)
c 찾는 부분에서 검색했다..