You have $n$ gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The $i$-th gift consists of $a_i$ candies and $b_i$ oranges.

During one move, you can choose some gift $1 \le i \le n$ and do one of the following operations:

  eat exactly one candy from this gift (decrease $a_i$ by one);  eat exactly one orange from this gift (decrease $b_i$ by one);  eat exactly one candy and exactly one orange from this gift (decrease both $a_i$ and $b_i$ by one). 

Of course, you can not eat a candy or orange if it's not present in the gift (so neither $a_i$ nor $b_i$ can become less than zero).

As said above, all gifts should be equal. This means that after some sequence of moves the following two conditions should be satisfied: $a_1 = a_2 = \dots = a_n$ and $b_1 = b_2 = \dots = b_n$ (and $a_i$ equals $b_i$ is not necessary).

Your task is to find the minimum number of moves required to equalize all the given gifts.

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains one integer $n$ ($1 \le n \le 50$) — the number of gifts. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the number of candies in the $i$-th gift. The third line of the test case contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the number of oranges in the $i$-th gift.


-----Output-----

For each test case, print one integer: the minimum number of moves required to equalize all the given gifts.


-----Example-----
Input
5
3
3 5 6
3 2 3
5
1 2 3 4 5
5 4 3 2 1
3
1 1 1
2 2 2
6
1 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1
3
10 12 8
7 5 4

Output
6
16
0
4999999995
7



-----Note-----

In the first test case of the example, we can perform the following sequence of moves:

  choose the first gift and eat one orange from it, so $a = [3, 5, 6]$ and $b = [2, 2, 3]$;  choose the second gift and eat one candy from it, so $a = [3, 4, 6]$ and $b = [2, 2, 3]$;  choose the second gift and eat one candy from it, so $a = [3, 3, 6]$ and $b = [2, 2, 3]$;  choose the third gift and eat one candy and one orange from it, so $a = [3, 3, 5]$ and $b = [2, 2, 2]$;  choose the third gift and eat one candy from it, so $a = [3, 3, 4]$ and $b = [2, 2, 2]$;  choose the third gift and eat one candy from it, so $a = [3, 3, 3]$ and $b = [2, 2, 2]$.

Difficulty: EASY

Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	res = 0
	for i in range(n):
		s1 = a[i] - amin
		s2 = b[i] - bmin
		res += max(s1, s2)
	print(res)


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()]
	ans = 0
	for i in range(n):
		ans += max(a[i] - min(a), b[i] - min(b))
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	min1 = min(l1)
	min2 = min(l2)
	ans = 0
	for x in range(len(l1)):
		if l1[x] - min1 <= l2[x] - min2:
			first = l1[x] - min1
			second = l2[x] - first - min2
		else:
			first = l2[x] - min2
			second = l1[x] - first - min1
		ans += first + second
	print(ans)


T = int(input())
for _ in range(T):
	n = int(input())
	A = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		A.append([a[i], b[i]])
	f1 = min(a)
	f2 = min(b)
	ans = 0
	for i in range(n):
		d1 = A[i][0] - f1
		d2 = A[i][1] - f2
		diff = min(d1, d2)
		ans += diff
		A[i][0] -= diff
		A[i][1] -= diff
		ans += A[i][0] - f1 + A[i][1] - f2
	print(ans)


def answer(n, A, B):
	count = 0
	min1 = min(A)
	min2 = min(B)
	for i in range(n):
		k1 = A[i] - min1
		k2 = B[i] - min2
		kmin = min(k1, k2)
		count += k1 + k2 - kmin
	return count
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(answer(n, a, b))


from bisect import bisect_left
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	l = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	ans = 0
	for j in range(l):
		temp = max(a[j] - ma, b[j] - mb)
		ans += temp
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	ans = 0
	for i in range(n):
		(a_more, b_more) = (0, 0)
		if a[i] > a_min:
			a_more = a[i] - a_min
		if b[i] > b_min:
			b_more = b[i] - b_min
		ans += max(a_more, b_more)
	print(ans)


production = True
import sys, math, collections, bisect, itertools, heapq, decimal, random, copy, re

def input(f=0, m=0):
	if m > 0:
		return [input(f) for i in range(m)]
	else:
		l = sys.stdin.readline()[:-1]
		if f >= 10:
			u = False
			f = int(str(f)[-1])
		else:
			u = True
		if f == 0:
			p = [l]
		elif f == 1:
			p = list(map(int, l.split()))
		elif f == 2:
			p = list(map(float, l.split()))
		elif f == 3:
			p = list(l)
		elif f == 4:
			p = list(map(int, list(l)))
		elif f == 5:
			p = l.split()
		return p if u else p[0]

def out(l, f=0, n=True):
	if f == 0:
		p = str(l)
	elif f == 1:
		p = ' '.join(map(str, l))
	elif f == 2:
		p = '\n'.join(map(str, l))
	elif f == 3:
		p = ''.join(map(str, l))
	print(p, end='\n' if n else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enu = enumerate
ter = lambda a, b, c: b if a else c
ceil = lambda a, b: -(-a // b)
flip = lambda a: a + 1 & 1

def mapl(i, f=0):
	if f == 0:
		return list(map(int, i))
	elif f == 1:
		return list(map(str, i))
	elif f == 2:
		return list(map(list, i))

def solve():
	n = input(11)
	a = input(1)
	b = input(1)
	ma = min(a)
	mb = min(b)
	t = 0
	for (i, j) in zip(a, b):
		da = i - ma
		db = j - mb
		t += max(da, db)
	out(t)
	return
for i in range(input(11)):
	solve()


for case in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	mina = min(a)
	minb = min(b)
	c = 0
	i = 0
	while i != n:
		if a[i] > mina and b[i] > minb and (i != n):
			mm = min(mina, minb)
			if minb == mm:
				c += b[i] - minb
				a[i] = a[i] - (b[i] - minb)
				b[i] = minb
			else:
				c += a[i] - mina
				b[i] = b[i] - (a[i] - mina)
				a[i] = mina
		if a[i] > mina:
			c += a[i] - mina
			a[i] = mina
		if b[i] > minb:
			c += b[i] - minb
			b[i] = minb
		i += 1
	print(c)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		d1 = a[i] - mina
		d2 = b[i] - minb
		ans += max(d1, d2)
	print(ans)


t = int(input())
for i in range(t):
	steps = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(a_min, b_min) = (min(a), min(b))
	for ith in range(n):
		dif = [a[ith] - a_min, b[ith] - b_min]
		steps += max(dif)
	print(steps)


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	(minA, minB) = (min(A), min(B))
	moves = 0
	for (a, b) in zip(A, B):
		(movesA, movesB) = (a - minA, b - minB)
		moves += max(movesB, movesA)
	print(moves)


t = int(input())
for _ in range(t):
	n = int(input())
	candies = [int(x) for x in input().split()]
	oranges = [int(x) for x in input().split()]
	minCandy = min(candies)
	minOrange = min(oranges)
	moves = 0
	for i in range(n):
		orangeEatable = oranges[i] - minOrange
		candyEatable = candies[i] - minCandy
		eatable = min([orangeEatable, candyEatable])
		moves += eatable
		orangeEatable -= eatable
		candyEatable -= eatable
		moves += orangeEatable + candyEatable
	print(moves)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	d = min(b)
	m = 0
	for i in range(n):
		if a[i] == c and b[i] > d:
			m += b[i] - d
		elif a[i] > c and b[i] == d:
			m += a[i] - c
		elif a[i] > c and b[i] > d:
			mi = min(a[i] - c, b[i] - d)
			m += mi
			if mi == a[i] - c:
				m += b[i] - mi - d
			else:
				m += a[i] - mi - c
	print(m)


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()]
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		if a[i] > ma and b[i] > mb:
			c += max(a[i] - ma, b[i] - mb)
		elif a[i] > ma and b[i] == mb:
			c += max(a[i] - ma, b[i] - mb)
		elif a[i] == ma and b[i] > mb:
			c += max(a[i] - ma, b[i] - mb)
	print(c)


t = int(input())
for _ in range(t):
	cnt = 0
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	min_a = min(a)
	min_b = min(b)
	for i in range(n):
		cnt_a = a[i] - min_a
		cnt_b = b[i] - min_b
		cnt += cnt_a + cnt_b - min(cnt_a, cnt_b)
	print(cnt)


t = int(input())
for q in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	minsweet = min(a)
	minapel = min(b)
	amount = 0
	for i in range(n):
		if a[i] > minsweet and b[i] > minapel:
			r = min(a[i] - minsweet, b[i] - minapel)
			amount += r
			a[i] -= r
			b[i] -= r
		if a[i] > minsweet:
			amount += a[i] - minsweet
		if b[i] > minapel:
			amount += b[i] - minapel
	print(amount)


t = int(input())
while t:
	n = int(input())
	a = [[0] * n for x in range(2)]
	a[0] = list(map(int, input().split()))
	h = min(a[0])
	a[1] = list(map(int, input().split()))
	k = min(a[1])
	ans = 0
	for x in range(0, n):
		ans += max(a[0][x] - h, a[1][x] - k)
	print(ans)
	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_min = min(a)
	b_min = min(b)
	no_moves = 0
	for i in range(N):
		moves_a = a[i] - a_min
		moves_b = b[i] - b_min
		min_comm = min(moves_a, moves_b)
		no_moves += moves_a + moves_b - min_comm
	print(no_moves)


T = int(input())
for t in range(T):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	min_a = min(a)
	min_b = min(b)
	moves = 0
	for i in range(n):
		moves += max(a[i] - min_a, b[i] - min_b)
	print(moves)


def find_step_cnt(a, b):
	min_a = min(a)
	min_b = min(b)
	step_cnt = 0
	for i in range(len(a)):
		delta_a = a[i] - min_a
		delta_b = b[i] - min_b
		if delta_a < delta_b:
			step_cnt += delta_b
		else:
			step_cnt += delta_a
	return step_cnt

def main():
	test_num = int(input())
	for _ in range(test_num):
		_ = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		print(find_step_cnt(a, b))
main()


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	(m1, m2) = (min(a), min(b))
	ct = 0
	for i in range(n):
		x = min(a[i] - m1, b[i] - m2)
		ct += a[i] - m1 + b[i] - m2 - x
	print(ct)


from sys import stdin, stdout
import math
from collections import Counter, deque
L = lambda : deque(list(map(int, stdin.readline().strip().split())))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
IN = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()
mod = 1000000007

def s(a):
	print(''.join(list(map(str, a))))

def solve():
	n = I()
	a = L()
	b = L()
	x = min(a)
	y = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - x, b[i] - y)
	print(ans)
for _ in range(I()):
	solve()


tests = int(input())
for _ in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(ma, mb) = (min(a), min(b))
	res = [max(a[i] - ma, b[i] - mb) for i in range(n)]
	print(sum(res))


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = min(l1)
	m2 = min(l2)
	moves = 0
	for j in range(n):
		if l1[j] - m1 > l2[j] - m2:
			moves += l1[j] - m1
		elif l1[j] - m1 < l2[j] - m2:
			moves += l2[j] - m2
		else:
			moves += l1[j] - m1
	print(moves)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

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

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

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	for t in range(I()):
		n = I()
		arr1 = L()
		arr2 = L()
		(m1, m2) = (min(arr1), min(arr2))
		c = 0
		for i in range(n):
			c += arr1[i] - m1 + arr2[i] - m2 - min(arr1[i] - m1, arr2[i] - m2)
		print(c)
main()


def find(can, org):
	c = min(can)
	indexc = can.index(c)
	o = min(org)
	indexo = org.index(o)
	sum = 0
	for i in range(0, len(can)):
		if i == indexc or i == indexo:
			sum = sum + (can[i] - c)
			sum = sum + (org[i] - o)
		else:
			m = max(can[i] - c, org[i] - o)
			sum = sum + m
	return sum
t = int(input())
while t > 0:
	n = int(input())
	can = [int(ele) for ele in input().split()]
	org = [int(ele) for ele in input().split()]
	print(find(can, org))
	t = t - 1


t = int(input())
for i in range(t):
	n = int(input())
	sweets = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	sweet = min(sweets)
	orange = min(oranges)
	ans = 0
	for i in range(n):
		ans += max(sweets[i] - sweet, oranges[i] - orange)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	sum = 0
	for i in range(n):
		sum += max(a[i] - amin, b[i] - bmin)
	print(sum)


for _ in range(int(input())):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	c = min(candy)
	o = min(orange)
	i = 0
	count = 0
	while i < n:
		if candy[i] == c and orange[i] == o:
			i += 1
		elif candy[i] > c and orange[i] == o:
			count += candy[i] - c
			candy[i] = c
		elif candy[i] == c and orange[i] > o:
			count += orange[i] - o
			orange[i] = o
		elif candy[i] > c and orange[i] > o:
			a = candy[i] - c
			b = orange[i] - o
			count += max(a, b)
			candy[i] = c
			orange[i] = o
	print(count)


def main():
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	(a, b) = (min(candy), min(orange))
	moves = 0
	for i in range(n):
		moves += max(candy[i] - a, orange[i] - b)
	print(moves)
for _ in range(int(input())):
	main()


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())
tests = inp()
testCount = 0
while testCount < tests:
	n = inp()
	a = inlt()
	b = inlt()
	c = min(a)
	d = min(b)
	e = []
	f = []
	for elem in a:
		e.append(elem - c)
	for elem in b:
		f.append(elem - d)
	i = 0
	count = 0
	while i < n:
		count += max(e[i], f[i])
		i += 1
	print(count)
	testCount += 1


t = int(input())
for _ in range(t):
	n = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	sum = 0
	for i in range(n):
		sum = sum + max(lst1[i] - min(lst1), lst2[i] - min(lst2))
	print(sum)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mna = min(a)
	mnb = min(b)
	ans = 0
	for i in range(n):
		diffa = a[i] - mna
		diffb = b[i] - mnb
		ans += max(diffa, diffb)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))[:n]
	b = list(map(int, input().split()))[:n]
	x = 0
	for j in range(n):
		x += max(a[j] - min(a), b[j] - min(b))
	print(x)


t = int(input())
list_ans = []
for i in range(t):
	n = input()
	list_index = []
	list_num = []
	cnt = 0
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	min_a = min(a)
	min_b = min(b)
	for i in range(len(a)):
		if a[i] > min_a:
			cnt += a[i] - min_a
			list_index.append(i)
			list_num.append(a[i] - min_a)
	for i in range(len(b)):
		if b[i] > min_b:
			if i in list_index:
				if b[i] - min_b > list_num[list_index.index(i)]:
					cnt += b[i] - min_b - list_num[list_index.index(i)]
			else:
				cnt += b[i] - min_b
	list_ans.append(cnt)
for i in range(len(list_ans)):
	print(list_ans[i])


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	a = list(mints())
	b = list(mints())
	am = min(a)
	bm = min(b)
	r = 0
	for i in range(n):
		r += max(a[i] - am, b[i] - bm)
	print(r)
for i in range(mint()):
	solve()


q = int(input())
for i in range(q):
	w = int(input())
	e = list(map(int, input().split()))
	r = list(map(int, input().split()))
	n = min(e)
	m = min(r)
	s = 0
	for i in range(w):
		s += max(e[i] - n, r[i] - m)
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	s = 0
	for i in range(n):
		s = s + max(a[i] - min_a, b[i] - min_b)
	print(s)


t = int(input())
results = []
nec = 0
for i in range(t):
	n = int(input())
	a = input().split()
	b = input().split()
	a = [int(i) for i in a]
	b = [int(j) for j in b]
	mina = min(a)
	minb = min(b)
	nec = 0
	for (ea, eb) in zip(a, b):
		ad = ea - mina
		bd = eb - minb
		nec = nec + abs(ad - bd) + min(ad, bd)
	results.append(nec)
for every in results:
	print(every)


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	a = min(ar)
	b = min(br)
	s = 0
	for i in range(n):
		s += max(ar[i] - a, br[i] - b)
	print(s)


TC = int(input())
for tc in range(TC):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	mA = min(A)
	mB = min(B)
	result = 0
	for i in range(N):
		a = A[i] - mA
		b = B[i] - mB
		result += max(a, b)
	print(result)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	ma = min(a)
	mb = min(b)
	for i in range(n):
		ans += max(a[i] - ma, b[i] - mb)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	d = min(b)
	s = 0
	for i in range(n):
		s += max(a[i] - c, b[i] - d)
	print(s)


for _ in range(int(input())):
	n = int(input())
	a_lis = list(map(int, input().split()))
	b_lis = list(map(int, input().split()))
	a_min = min(a_lis)
	b_min = min(b_lis)
	ctr = 0
	for i in range(n):
		ctr += max(a_lis[i] - a_min, b_lis[i] - b_min)
	print(ctr)


def main():
	for _ in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		b = [int(x) for x in input().split()]
		am = min(a)
		bm = min(b)
		c = 0
		for i in range(0, n):
			x = a[i] - am
			y = b[i] - bm
			c = c + max(x, y)
		print(c)
main()


import sys
readline = lambda : sys.stdin.readline().strip('\n')
readgen = lambda : map(int, readline().split())
for _ in range(int(input())):
	n = int(input())
	a = [*readgen()]
	b = [*readgen()]
	ma = min(a)
	mb = min(b)
	print(sum([max(i - ma, j - mb) for (i, j) in zip(a, b)]))
quit()
for _ in range(int(input())):
	n = int(input())
	a = sorted(readgen())
	b = sorted(readgen())
	flag = any([a[i + 1] - a[i] > 1 for i in range(len(a) - 1)])
	print('YNEOS'[flag::2])


test = int(input())
while test:
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	mina = min(a)
	minb = min(b)
	i = 0
	while i < n:
		a[i] -= mina
		b[i] -= minb
		i += 1
	i = 0
	result = 0
	while i < n:
		if a[i] >= b[i]:
			a[i] -= b[i]
			result += b[i]
			b[i] = 0
		else:
			b[i] -= a[i]
			result += a[i]
			a[i] = 0
		i += 1
	i = 0
	while i < n:
		result += max(a[i], b[i])
		i += 1
	print(result)
	test -= 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 [int(i) for i in 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):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	n = ii()
	a = li()
	b = li()
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		bothmin = min(a[i] - amin, b[i] - bmin)
		ans += bothmin
		ans += max(a[i] - amin - bothmin, b[i] - bmin - bothmin)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	L = list(map(int, input().split()))
	M = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	MIN1 = min(L)
	MIN2 = min(M)
	diff = 0
	for i in range(n):
		count1 += L[i] - MIN1
		count2 += M[i] - MIN2
		if L[i] > MIN1 and M[i] > MIN2:
			diff = diff + min(L[i] - MIN1, M[i] - MIN2)
	print(count1 + count2 - diff)


from sys import stdin, stdout

def INPUT():
	return list((int(i) for i in stdin.readline().split()))

def inp():
	return stdin.readline()

def out(x):
	return stdout.write(x)
import math
for _ in range(int(input())):
	n = int(input())
	A = INPUT()
	B = INPUT()
	ans = 0
	a = min(A)
	b = min(B)
	for i in range(n):
		if A[i] != a and B[i] != b:
			ans += max(A[i] - a, B[i] - b)
		elif A[i] == a and B[i] != b:
			ans += B[i] - b
		elif A[i] != a and B[i] == b:
			ans += A[i] - a
	print(ans)


a = int(input())
for i in range(0, a):
	b = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	a = min(arr)
	b = min(brr)
	ans = 0
	for i in range(0, len(arr)):
		da = arr[i] - a
		db = brr[i] - b
		mind = min(da, db)
		arr[i] = arr[i] - mind
		brr[i] = brr[i] - mind
		if not arr[i] == a:
			ans = ans + arr[i] - a
		if not brr[i] == b:
			ans = ans + brr[i] - b
		ans = ans + mind
	print(ans)


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()
		mn = min(ar)
		m = min(br)
		ans = 0
		for i in range(n):
			mx = max(abs(ar[i] - mn), abs(br[i] - m))
			mxx = min(abs(ar[i] - mn), abs(br[i] - m))
			ans += mxx
			ans += mx - mxx
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
for i in range(n):
	m = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	c = 0
	for i in range(m):
		c += max(a[i] - x, b[i] - y)
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	A = min(a)
	B = min(b)
	res = 0
	for i in range(n):
		res += max(a[i] - A, b[i] - B)
	print(res)


tc = int(input())
for _ in range(tc):
	n = int(input())
	arr1 = list(map(int, input().split()))
	enkck1 = min(arr1)
	farr = []
	arr2 = list(map(int, input().split()))
	enkck2 = min(arr2)
	for i in range(n):
		enbyk = max(arr1[i] - enkck1, arr2[i] - enkck2)
		farr.append(enbyk)
	print(sum(farr))


import sys, math, heapq, copy
from collections import defaultdict, deque
from bisect import bisect_left, bisect_right
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	ans = 0
	for i in range(n):
		p = a[i] - x
		q = b[i] - y
		ans += abs(p - q) + min(p, q)
	print(ans)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	diffa = 0
	diffb = 0
	count = 0
	for i in range(n):
		diffa = a[i] - mina
		diffb = b[i] - minb
		count += min(diffa, diffb) + abs(diffa - diffb)
	print(count)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		if a[i] > mina and b[i] > minb:
			ans += min(a[i] - mina, b[i] - minb)
			x = min(a[i] - mina, b[i] - minb)
			a[i] -= x
			b[i] -= x
	for i in range(n):
		if a[i] > mina:
			ans += a[i] - mina
			a[i] = mina
	for i in range(n):
		if b[i] > minb:
			ans += b[i] - minb
			b[i] = minb
	print(ans)


n = int(input())
for _ in range(n):
	n1 = int(input())
	nums1 = list(map(int, input().split()))
	nums2 = list(map(int, input().split()))
	min1 = min(nums1)
	min2 = min(nums2)
	res = 0
	for i in range(n1):
		res += min(min1 - nums1[i], min2 - nums2[i])
	print(-res)


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()]
	mini_a = min(a)
	mini_b = min(b)
	ans = 0
	for j in range(n):
		tmp_a = a[j]
		tmp_b = b[j]
		tog = min([tmp_a - mini_a, tmp_b - mini_b])
		ans += tog
		ans += tmp_a - mini_a - tog
		ans += tmp_b - mini_b - tog
	print(ans)


import math
from collections import deque
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < abs(max_ending_here):
			max_so_far = max_ending_here
	return max_so_far

def longestsubarray(arr, n, k):
	current_count = 0
	max_count = 0
	for i in range(0, n, 1):
		if arr[i] % k != 0:
			current_count += 1
		else:
			current_count = 0
		max_count = max(current_count, max_count)
	return max_count

def main():
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = min(l1)
	m2 = min(l2)
	c = 0
	for i in range(0, n):
		d1 = l1[i] - m1
		d2 = l2[i] - m2
		c += max(d1, d2)
	print(c)
t = int(input())
for i in range(0, t):
	main()


import math
t = int(input())
for i in range(t):
	n = int(input())
	c = []
	o = []
	c[0:n] = map(int, input().split())
	o[0:n] = map(int, input().split())
	minic = min(c)
	minio = min(o)
	for j in range(n):
		c[j] = c[j] - minic
		o[j] = o[j] - minio
	total = 0
	for j in range(n):
		total = total + max(c[j], o[j])
	print(total)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	c = 0
	for i in range(n):
		c += max(a[i] - mina, b[i] - minb)
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	k = 0
	for i in range(n):
		k += max(a[i] - a1, b[i] - b1)
	print(k)


test = int(input())
for t in range(test):
	n = int(input())
	c = list(map(int, input().split(' ')))
	o = list(map(int, input().split(' ')))
	c_min = min(c)
	o_min = min(o)
	op = 0
	for x in range(len(c)):
		if c[x] > c_min and o[x] > o_min:
			choco = c[x] - c_min
			orange = o[x] - o_min
			op += max([choco, orange])
		elif c[x] > c_min:
			op += c[x] - c_min
		elif o[x] > o_min:
			op += o[x] - o_min
	print(op)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for q in range(n):
		if a[q] == min_a and b[q] == min_b:
			pass
		else:
			ans += max(a[q] - min_a, b[q] - min_b)
	print(ans)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = 0
	for i in range(len(a)):
		if a[i] != min(a) and b[i] == min(b):
			k += a[i] - min(a)
		elif a[i] == min(a) and b[i] != min(b):
			k += b[i] - min(b)
		elif a[i] != min(a) and b[i] != min(b):
			k += max(a[i] - min(a), b[i] - min(b))
	print(k)


def equal_gifts(a, b):
	moves = 0
	min_a = min(a)
	min_b = min(b)
	for i in range(len(a)):
		moves += max(a[i] - min_a, b[i] - min_b)
	return moves
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(equal_gifts(a, b))


n = int(input())
tests = [(input(), input(), input()) for _ in range(n)]
for case in tests:
	a = list(map(int, case[1].split()))
	b = list(map(int, case[2].split()))
	amn = min(a)
	bmn = min(b)
	steps = 0
	for (i, j) in zip(a, b):
		tmp = max(abs(amn - i), abs(bmn - j))
		steps += tmp
	print(steps)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(z) for z in input().split()]
	b = [int(z) for z in input().split()]
	m1 = min(a)
	m2 = min(b)
	sum1 = 0
	for i in range(n):
		if a[i] > m1 and b[i] > m2:
			m = min(a[i] - m1, b[i] - m2)
			sum1 += m
			a[i] -= m
			b[i] -= m
		if a[i] > m1 or b[i] > m2:
			if a[i] > m1:
				sum1 += a[i] - m1
				a[i] -= m1
			else:
				sum1 += b[i] - m2
				b[i] -= m2
	print(sum1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_index_a = a.index(min_a)
	min_b = min(b)
	min_index_b = b.index(min_b)
	count = 0
	count += b[min_index_a] - min_b
	count += a[min_index_b] - min_a
	for i in range(len(a)):
		if i != min_index_a and i != min_index_b:
			count += max(a[i] - min_a, b[i] - min_b)
	print(count)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	min_a = min(a)
	min_b = min(b)
	cnt = 0
	for i in range(len(a)):
		lcl_a = a[i] - min_a
		lcl_b = b[i] - min_b
		cnt += max(lcl_a, lcl_b)
	stdout.write(f'{cnt}\n')


t = int(input())
while t:
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	min1 = min(l1)
	min2 = min(l2)
	s = 0
	for i in range(n):
		s += max(l1[i] - min1, l2[i] - min2)
	print(s)
	t = t - 1


from math import ceil

def main():
	for _ in range(int(input())):
		g = int(input())
		a = [int(i) for i in input().split()]
		b = [int(i) for i in input().split()]
		minA = min(a)
		minB = min(b)
		moves = 0
		for i in range(g):
			if a[i] > minA and b[i] > minB:
				amoves = a[i] - minA
				bmoves = b[i] - minB
				moves += max(amoves, bmoves)
			elif a[i] > minA:
				moves += a[i] - minA
			elif b[i] > minB:
				moves += b[i] - minB
		print(moves)
main()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = True
	mina = float('inf')
	minb = float('inf')
	for i in range(n):
		mina = min(mina, a[i])
		minb = min(minb, b[i])
	sum = 0
	for i in range(n):
		da = 0
		db = 0
		if a[i] > mina:
			da = a[i] - mina
		if b[i] > minb:
			db = b[i] - minb
		sum += max(da, db)
	print(sum)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(minA, minB) = (min(a), min(b))
	cnt = 0
	for i in range(n):
		difA = a[i] - minA
		difB = b[i] - minB
		if difA > 0 and difB > 0:
			tmp = min(difA, difB)
			difA -= tmp
			difB -= tmp
			cnt += tmp
			cnt += max(difA, difB)
		elif difA > 0 or difB > 0:
			if difA > 0:
				cnt += difA
			else:
				cnt += difB
	print(cnt)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ax = min(a)
	bx = min(b)
	ans = 0
	for i in range(n):
		nea = a[i] - ax
		neb = b[i] - bx
		me = min(nea, neb)
		ans += me
		nea -= me
		neb -= me
		ans += nea + neb
	print(ans)


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()
while t > 0:
	n = inp()
	a = inlt()
	b = inlt()
	amin = min(a)
	bmin = min(b)
	cnt = 0
	k = 0
	for i in range(n):
		if a[i] > amin and b[i] > bmin:
			if b[i] - bmin > a[i] - amin:
				cnt += b[i] - bmin
			else:
				cnt += a[i] - amin
		elif a[i] > amin:
			cnt += a[i] - amin
		elif b[i] > bmin:
			cnt += b[i] - bmin
	print(cnt)
	t -= 1


for __ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	x = min(l1)
	p = l1.index(x)
	y = min(l2)
	q = l2.index(y)
	i = 0
	c = 0
	for i in range(n):
		if l1[i] == x and l2[i] == y:
			pass
		else:
			c += max(l1[i] - x, l2[i] - y)
	print(c)


import sys
input = sys.stdin.readline
LI = lambda : list(map(int, input().split()))
MI = lambda : map(int, input().split())
SI = lambda : input().strip('\n')
II = lambda : int(input())
for _ in range(II()):
	n = II()
	a = LI()
	b = LI()
	acnt = [0] * n
	bcnt = [0] * n
	amin = min(a)
	bmin = min(b)
	for i in range(n):
		acnt[i] = a[i] - amin
		bcnt[i] = b[i] - bmin
	ans = 0
	for i in range(n):
		ans += max(acnt[i], bcnt[i])
	print(ans)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mn1 = min(a)
	mn2 = min(b)
	for i in range(len(a)):
		a[i] = a[i] - mn1
		b[i] = b[i] - mn2
	ans = 0
	for i in range(len(a)):
		if a[i] == b[i]:
			ans += a[i]
		else:
			ans += min(a[i], b[i])
			ans += max(a[i], b[i]) - min(a[i], b[i])
	print(ans)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
	return
test()


import sys
inint = lambda : int(sys.stdin.readline())
inintm = lambda : map(int, sys.stdin.readline().split())
inintl = lambda : list(inintm())
instrm = lambda : map(str, sys.stdin.readline().split())
instrl = lambda : list(instrm())
t = inint()
for _ in range(t):
	n = inint()
	A = inintl()
	B = inintl()
	min_a = min(A)
	min_b = min(B)
	ans = 0
	for i in range(n):
		ans += max(A[i] - min_a, B[i] - min_b)
	print(ans)


R = lambda : [*map(int, input().split())]
(t,) = R()
exec(t * 'R();a=R();b=R();print(sum(max(x-min(a),y-min(b))for x,y in zip(a,b)));')


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

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

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

def si():
	return input().split()
t = ii()
for _ in range(t):
	n = ii()
	a = li()
	b = li()
	ab = []
	ma = a[0]
	mb = b[0]
	for i in range(n):
		ab.append([a[i], b[i]])
		ma = min(ma, a[i])
		mb = min(mb, b[i])
	ans = 0
	for i in range(n):
		ans += max(-ma + a[i], b[i] - mb)
	print(ans)


cases = int(input())
for t in range(cases):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	a1 = set()
	b1 = set()
	for i in range(n):
		if a[i] == amin:
			a1.add(i)
		if b[i] == bmin:
			b1.add(i)
	common = list(a1 & b1)
	if common:
		aidx = common[0]
		bidx = common[0]
		s = 0
		for i in range(n):
			if i != aidx:
				adiff = a[i] - amin
				bdiff = b[i] - bmin
				s += max(adiff, bdiff)
		print(s)
	else:
		s = 0
		aidx = a.index(amin)
		bidx = b.index(bmin)
		for i in range(n):
			if i != aidx and i != bidx:
				adiff = a[i] - amin
				bdiff = b[i] - bmin
				s += max(adiff, bdiff)
		s += b[aidx] - bmin
		s += a[bidx] - amin
		print(s)


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()))
	(mina, minb) = (min(a), min(b))
	ans = 0
	for i in range(n):
		chnga = a[i] - mina
		chngb = b[i] - minb
		ans += max(chnga, chngb)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	minc = min(c)
	mino = min(o)
	ans = 0
	for j in range(n):
		ans += max(abs(minc - c[j]), abs(mino - o[j]))
	print(ans)


def ans():
	pass
t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	(min_a, min_b) = (float('inf'), float('inf'))
	for i in range(n):
		min_a = min(a[i], min_a)
		min_b = min(b[i], min_b)
	ans = 0
	for i in range(n):
		(ax, bx) = (0, 0)
		if a[i] > min_a:
			ax = a[i] - min_a
		if b[i] > min_b:
			bx = b[i] - min_b
		ans += ax + bx - min(ax, bx)
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(j) for j in input().split()]
	k = 0
	min_a = min(a)
	min_b = min(b)
	for i in range(n):
		k = k + max(a[i] - min_a, b[i] - min_b)
	print(k)


def solve(arr, brr):
	dp = [[0] * n] * n
t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	a = min(arr)
	b = min(brr)
	indexes = set()
	moves = 0
	for i in range(n):
		if arr[i] != a and brr[i] == b:
			moves += abs(a - arr[i])
			indexes.add(i)
		elif brr[i] != b and arr[i] == a:
			moves += abs(b - brr[i])
			indexes.add(i)
		elif arr[i] != a and brr[i] != b:
			x = abs(a - arr[i])
			y = abs(b - brr[i])
			if x == y:
				moves += x
			elif x > y:
				moves += x
			else:
				moves += y
	print(moves)
	t -= 1


t = int(input())
while t:
	n = int(input())
	ls1 = list(map(int, input().split()))
	ls2 = list(map(int, input().split()))
	(mn1, mn2) = (min(ls1), min(ls2))
	res = 0
	for i in range(n):
		x = min(ls1[i] - mn1, ls2[i] - mn2)
		res += x + ls1[i] - x - mn1 + ls2[i] - x - mn2
	print(res)
	t -= 1


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(c, o) = (min(a), min(b))
	ans = 0
	for i in range(n):
		cd = abs(c - a[i])
		od = abs(o - b[i])
		ans += max(cd, od)
	print(ans)
	t -= 1


t = int(input())
for i in range(0, t):
	n = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	m1 = min(l1)
	m2 = min(l2)
	count = 0
	for i in range(len(l1)):
		v1 = l1[i]
		v2 = l2[i]
		a = abs(v1 - m1)
		b = abs(v2 - m2)
		if a != 0 and b != 0:
			if a < b:
				k = a
			else:
				k = b
		else:
			k = abs(a - b)
		count += k
		if a != 0:
			count += abs(a - k)
		if b != 0:
			count += abs(b - k)
	print(count)


def fun(a, n, m1, m2):
	l = 0
	for i in range(n):
		if a[i] > m1 and b[i] > m2:
			k = min(a[i] - m1, b[i] - m2)
			a[i] = a[i] - k
			b[i] = b[i] - k
			l = l + k
		if a[i] > m1:
			l = l + a[i] - m1
			a[i] = a[i] - (a[i] - m1)
		if b[i] > m2:
			l = l + b[i] - m2
			b[i] = b[i] - (b[i] - m2)
	return l
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	print(fun(a, n, ma, mb))


def m(a, b):
	if a >= b:
		return a
	else:
		return b
t = int(input())
for i in range(t):
	n = int(input())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	ma = min(la)
	mb = min(lb)
	s = 0
	for j in range(n):
		s += m(la[j] - ma, lb[j] - mb)
	print(s)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	p = min(l)
	q = min(l1)
	count = 0
	for i in range(0, n):
		if l[i] > p and l1[i] > q:
			z = l[i] - p
			x = l1[i] - q
			k = min(z, x)
			count += k
			l[i] -= k
			l1[i] -= k
	for i in range(0, n):
		if l[i] > p:
			count += l[i] - p
	for i in range(0, n):
		if l1[i] > q:
			count += l1[i] - q
	print(count)


cases = int(input())
while cases:
	n = int(input())
	a_arr = list(map(int, input().split()))
	a = [i - min(a_arr) for i in a_arr]
	b_arr = list(map(int, input().split()))
	b = [j - min(b_arr) for j in b_arr]
	cases -= 1
	total = 0
	for x in range(n):
		total += max(a[x], b[x])
	print(total)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amn = min(a)
	bmn = min(b)
	cnt = 0
	for i in range(n):
		mid = min(a[i] - amn, b[i] - bmn)
		cnt += mid + a[i] - mid - amn + b[i] - mid - bmn
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		t = min(a[i] - amin, b[i] - bmin)
		ans += t
		a[i] -= t
		b[i] -= t
		ans += a[i] - amin
		ans += b[i] - bmin
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	x = min(l)
	y = min(m)
	c = 0
	i = 0
	while i < n:
		c += max(l[i] - x, m[i] - y)
		i += 1
	print(c)


import math
from decimal import Decimal
import heapq
import copy
import heapq
from collections import deque
from collections import defaultdict

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def da():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(n):
	tc = []
	ans = {}
	d = 2
	while d * d <= n:
		if n % d == 0:
			tc.append(d)
			n //= d
		else:
			d += 1
	if n > 1:
		tc.append(n)
	for i in tc:
		ans[i] = ans.get(i, 0) + 1
	return ans

def to_zero(n, s):
	lst = s[0]
	ans = []
	for i in range(n):
		if lst == s[i]:
			continue
		elif lst == '0':
			lst = '1'
			ans.append(i)
		else:
			lst = '0'
			ans.append(i)
	if lst == '1':
		ans.append(n)
	return ans
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k1 = min(a)
	k2 = min(b)
	ans = 0
	for i in range(n):
		if a[i] > k1 and b[i] > k2:
			d = a[i] - k1
			d2 = b[i] - k2
			d3 = min(d, d2)
			ans += d3
			ans += max(d, d2) - d3
		elif a[i] > k1:
			ans += a[i] - k1
		elif b[i] > k2:
			ans += b[i] - k2
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	am = min(arr)
	bm = min(brr)
	c = 0
	for j in range(0, len(arr)):
		m = []
		if arr[j] > am and brr[j] > bm:
			p = arr[j] - am
			m.append(p)
			q = brr[j] - bm
			m.append(q)
			m.sort()
			c += min(m) + (m[1] - m[0])
		elif arr[j] > am and brr[j] == bm:
			c += arr[j] - am
		elif brr[j] > bm and arr[j] == am:
			c += brr[j] - bm
	print(c)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
sys.setrecursionlimit(200000)
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

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

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

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	n = int(input())
	a = list_input()
	b = list_input()
	(min_a, min_b) = (min(a), min(b))
	op = 0
	for i in range(n):
		if a[i] == min_a and b[i] == min_b:
			continue
		if a[i] == min_a:
			op += b[i] - min_b
		elif b[i] == min_b:
			op += a[i] - min_a
		else:
			minn = min(b[i] - min_b, a[i] - min_a)
			op += minn
			if b[i] - min_b != minn:
				b[i] -= minn
				op += b[i] - min_b
			else:
				a[i] -= minn
				op += a[i] - min_a
	print(op)
t = 1
t = int(input())
for _ in range(t):
	solve()


import sys
import math

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

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	a = LI()
	b = LI()
	x = min(a)
	y = min(b)
	count = 0
	for i in range(n):
		count += max(a[i] - x, b[i] - y)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		c += max(a[i] - ma, b[i] - mb)
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	c = list(map(int, input().strip().split()))[:n]
	global_a = min(a)
	global_c = min(c)
	total_moves = 0
	for i in range(n):
		move_a = a[i] - global_a
		move_c = c[i] - global_c
		total_moves += max(move_a, move_c)
	print(total_moves)


t = int(input())
while t:
	n = int(input())
	l1 = input().split()
	l2 = input().split()
	orang = []
	cnd = []
	mnOrg = int(l2[0])
	mnCand = int(l1[0])
	for i in range(n):
		mnCand = min(int(l1[i]), mnCand)
		mnOrg = min(mnOrg, int(l2[i]))
	s = 0
	for i in range(n):
		s += max(int(l1[i]) - mnCand, int(l2[i]) - mnOrg)
	print(s)
	t -= 1


T = int(input())
while T > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(x, y) = (min(a), min(b))
	res = 0
	for i in range(n):
		res += max(a[i] - x, b[i] - y)
	print(res)
	T -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	c = [max(a[i] - am, b[i] - bm) for i in range(n)]
	print(sum(c))


def ans(a, b, n):
	x = min(a)
	y = min(b)
	ans = 0
	for i in range(n):
		d1 = a[i] - x
		d2 = b[i] - y
		ans += max(d1, d2)
	return ans
m = int(input())
for i in range(m):
	n = int(input())
	arr = input().split()
	arr2 = input().split()
	a = []
	b = []
	for i in arr:
		a.append(int(i))
	for i in arr2:
		b.append(int(i))
	print(ans(a, b, n))


for _ in range(int(input())):
	answer = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_target = min(a)
	b_target = min(b)
	for (x, y) in zip(a, b):
		answer += max(x - a_target, y - b_target)
	print(answer)


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 = min(A)
	b = min(B)
	res = 0
	for (x, y) in zip(A, B):
		x -= a
		y -= b
		res += max(x, y)
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	s = 0
	for i in range(n):
		if a[i] - am >= b[i] - bm:
			s += b[i] - bm
			s += a[i] - am - (b[i] - bm)
		else:
			s += a[i] - am
			s += b[i] - bm - (a[i] - am)
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	count = 0
	for i in range(len(a)):
		count += max(a[i] - am, b[i] - bm)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	(x, y) = (min(a), min(b))
	ans = 0
	for i in range(n):
		(val1, val2) = (a[i] - x, b[i] - y)
		val = min(val1, val2)
		ans += val
		a[i] -= val
		b[i] -= val
		ans += abs(val1 - val2)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = 0
	sa = min(A)
	sb = min(B)
	for i in range(n):
		ans += max(A[i] - sa, B[i] - sb)
	print(ans)


final = []
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()]
	amin = min(a)
	bmin = min(b)
	count = 0
	for j in range(n):
		if a[j] > amin and b[j] > bmin:
			if a[j] - amin > b[j] - bmin:
				count = count + a[j] - amin
			elif a[j] - amin == b[j] - bmin:
				count = count + a[j] - amin
			else:
				count = count + b[j] - bmin
		elif a[j] > amin and b[j] == bmin:
			count = count + a[j] - amin
		elif a[j] == amin and b[j] > bmin:
			count = count + b[j] - bmin
	final.append(count)
for i in range(len(final)):
	print(final[i])


def min_ar(arr, n):
	min_var = arr[0]
	for i in range(1, n):
		if arr[i] < min_var:
			min_var = arr[i]
	return min_var
t = int(input())
while t:
	t -= 1
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	minA = min_ar(A, n)
	minB = min_ar(B, n)
	result = 0
	for i in range(n):
		result += max(A[i] - minA, B[i] - minB)
	print(result)


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

def case():
	n = IN()
	a = LI()
	b = LI()
	x = min(a)
	y = min(b)
	s = 0
	for i in range(n):
		if a[i] > x and b[i] > y:
			p = a[i] - x
			q = b[i] - y
			s += min(p, q) + abs(p - q)
		elif a[i] > x:
			s += a[i] - x
		elif b[i] > y:
			s += b[i] - y
	print(s)
for _ in range(IN()):
	case()


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]

def solve():
	n = int(ii())
	a = idata()
	b = idata()
	(a1, b1) = (min(a), min(b))
	ans = 0
	for i in range(n):
		ans += max(b[i] - b1, a[i] - a1)
	print(ans)
	return
for t in range(int(ii())):
	solve()


from sys import stdin, stdout
import bisect
n = int(stdin.readline())
for i in range(n):
	ans = 0
	a = int(stdin.readline())
	x = [int(i) for i in stdin.readline().split()]
	y = [int(j) for j in stdin.readline().split()]
	eq1 = min(x)
	eq2 = min(y)
	for i in range(a):
		rex = x[i] - eq1
		rey = y[i] - eq2
		ans += max(rex, rey)
	stdout.write(str(ans) + '\n')


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())
n = inp()
for _ in range(n):
	l = inp()
	a = inlt()
	b = inlt()
	count = 0
	mina = min(a)
	minb = min(b)
	for g in range(l):
		diffa = a[g] - mina
		diffb = b[g] - minb
		mini = min(diffa, diffb)
		diffa -= mini
		diffb -= mini
		count += mini + diffa + diffb
	print(count)


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()]
	p = min(a)
	q = min(b)
	res = 0
	for i in range(n):
		if a[i] == p and b[i] == q:
			continue
		elif a[i] == p:
			res = res + abs(b[i] - q)
		elif b[i] == q:
			res = res + abs(a[i] - p)
		elif a[i] > p and b[i] > q:
			x = abs(a[i] - p)
			y = abs(b[i] - q)
			res = res + abs(x - y) + min(x, y)
	print(res)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	min_a = min(a)
	min_b = min(b)
	cnt = 0
	for i in range(n):
		if a[i] != min_a and b[i] != min_b:
			temp = min(a[i] - min_a, b[i] - min_b)
			a[i] -= temp
			b[i] -= temp
			cnt += temp
	for i in range(n):
		if a[i] != min_a:
			cnt += a[i] - min_a
		if b[i] != min_b:
			cnt += b[i] - min_b
	print(cnt)


import math

def ans():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	sum = 0
	for i in range(n):
		if a[i] - a1 > b[i] - b1:
			sum += a[i] - a1
		elif a[i] - a1 < b[i] - b1:
			sum += b[i] - b1
		else:
			sum += a[i] - a1
	print(sum)
	return
t = int(input())
while t > 0:
	ans()
	t -= 1


import sys
input = sys.stdin.readline
from collections import *
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	ans = 0
	for (ai, bi) in zip(a, b):
		ans += max(ai - ma, bi - mb)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	tot = 0
	for i in range(n):
		tot += max(a[i] - min(a[i], am), b[i] - min(b[i], bm))
	print(tot)


for i in range(int(input())):
	sum1 = 0
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	(x1, y1) = (min(x), min(y))
	for j in range(n):
		sum1 = sum1 + max(x[j] - x1, y[j] - y1)
	print(sum1)


n = int(input())
for i in range(n):
	a = int(input())
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	count = 0
	mb = min(b)
	mc = min(c)
	for i in range(a):
		b[i] = b[i] - mb
		c[i] = c[i] - mc
	for i in range(a):
		m = min(b[i], c[i])
		b[i] -= m
		c[i] -= m
		count += m
	sumb = sum(b)
	sumc = sum(c)
	ans = count + sumc + sumb
	print(ans)


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = a[0]
	min_b = b[0]
	for i in range(0, n):
		if min_a > a[i]:
			min_a = a[i]
		if min_b > b[i]:
			min_b = b[i]
	turns = 0
	for i in range(0, n):
		t_a = a[i] - min_a
		t_b = b[i] - min_b
		turns += max(t_a, t_b)
	print(turns)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		xa = abs(ma - a[i])
		xb = abs(mb - b[i])
		y = min(xa, xb)
		c += y
		(xa, xb) = (xa - y, xb - y)
		c += xa + xb
	print(c)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - mina, b[i] - minb)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	candy = list(map(int, input().split(' ')))
	orange = list(map(int, input().split(' ')))
	sc = min(candy)
	so = min(orange)
	c = 0
	for i in range(n):
		c = c + max(candy[i] - sc, orange[i] - so)
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = min(l1)
	m2 = min(l2)
	l3 = [0] * n
	l4 = [0] * n
	for i in range(n):
		if l1[i] >= m1:
			l3[i] = l1[i] - m1
	for i in range(n):
		if l2[i] >= m2:
			l4[i] = l2[i] - m2
	c = 0
	for i in range(n):
		c += max(l3[i], l4[i])
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	moves = 0
	for i in range(n):
		x = a[i]
		y = b[i]
		xm = x - amin
		ym = y - bmin
		tm = min(xm, ym)
		moves += tm
		x -= tm
		y -= tm
		moves += x - amin
		moves += y - bmin
	print(moves)


s = int(input())
for a in range(s):
	h = int(input())
	i = list(map(int, input().split()))
	t = list(map(int, input().split()))
	i1 = min(i)
	t1 = min(t)
	c = 0
	for (x, y) in zip(i, t):
		if x - i1 > y - t1:
			c += x - i1
		else:
			c += y - t1
	print(c)


t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = 10000000000.0
	m2 = 10000000000.0
	for i in range(n):
		m1 = min(m1, a[i])
		m2 = min(m2, b[i])
	ans = 0
	for i in range(n):
		ans += max(a[i] - m1, b[i] - m2)
	print(ans)


t = int(input())
for i in range(0, t):
	n = int(input())
	a = input().split()
	b = input().split()
	for i in range(0, n):
		(a[i], b[i]) = (int(a[i]), int(b[i]))
	(mna, mnb) = (min(a), min(b))
	moves = 0
	for i in range(0, n):
		(amoves, bmoves) = (0, 0)
		if a[i] > mna:
			amoves = a[i] - mna
		if b[i] > mnb:
			bmoves = b[i] - mnb
		moves = moves + amoves if amoves > bmoves else moves + bmoves
	print(moves)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if max(a) > max(b):
		(a, b) = (b, a)
	p = min(a)
	q = min(b)
	l = 0
	for i in range(n):
		k = min(a[i] - p, b[i] - q)
		l = l + k
		a[i] = a[i] - k
		b[i] = b[i] - k
	for i in range(n):
		l = l + (a[i] - p)
		l = l + (b[i] - q)
	print(l)


t = int(input())
for _ in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_c = min(candies)
	min_o = min(oranges)
	count_c = []
	count_o = []
	count = 0
	for i in range(n):
		if candies[i] > min_c:
			count_c.append(candies[i] - min_c)
		else:
			count_c.append(0)
	for i in range(n):
		if oranges[i] > min_o:
			count_o.append(oranges[i] - min_o)
		else:
			count_o.append(0)
	for i in range(n):
		if count_o[i] >= count_c[i]:
			count += count_o[i]
		else:
			count += count_c[i]
	print(count)


for t in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	minA = min(A)
	minB = min(B)
	moves = 0
	for i in range(n):
		a = A[i] - minA
		b = B[i] - minB
		moves += max(a, b)
	print(moves)


t = int(input())
for i in range(t):
	n = int(input())
	arr1 = list(map(lambda x: int(x), input().split(' ')))
	arr2 = list(map(lambda x: int(x), input().split(' ')))
	apples = min(arr1)
	oranges = min(arr2)
	moves = 0
	for j in range(n):
		moves += max(arr1[j] - apples, arr2[j] - oranges)
	print(moves)


def check():
	t = int(input())
	i = 0
	while i < t:
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		s1 = 0
		s2 = 0
		s3 = 0
		c1 = min(a)
		c2 = min(b)
		for j in range(n):
			if a[j] > c1 and b[j] > c2:
				temp = min(a[j], b[j])
				if temp == a[j]:
					temp1 = a[j] - c1
				else:
					temp1 = b[j] - c2
				a[j] -= temp1
				b[j] -= temp1
				s3 += temp1
			if b[j] > c2:
				temp = 0
				temp = b[j] - c2
				b[j] -= temp
				s2 += temp
			if a[j] > c1:
				temp = 0
				temp = a[j] - c1
				a[j] -= temp
				s1 += temp
		i += 1
		print(s1 + s2 + s3)
check()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	l1 = min(arr)
	l2 = min(ar)
	c = 0
	for i in range(n):
		c += max(arr[i] - l1, ar[i] - l2)
	print(c)


t = int(input())

def calc(A, B):
	min_a = min(A)
	min_b = min(B)
	c = 0
	for i in range(len(A)):
		(a, b) = (A[i], B[i])
		(dif_a, dif_b) = (a - min_a, b - min_b)
		c += max(dif_a, dif_b)
	return c
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	print(calc(A, B))


import collections
from functools import lru_cache

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

def readInt():
	return int(input().strip())

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

def solve(N, arr1, arr2):
	(min1, min2) = (min(arr1), min(arr2))
	minBoth = min(min1, min2)
	ans = 0
	for (a, b) in zip(arr1, arr2):
		minTwo = min(a, b)
		aDiff = a - min1
		bDiff = b - min2
		minDiff = min(aDiff, bDiff)
		a -= minDiff
		b -= minDiff
		ans += a - min1
		ans += b - min2
		ans += minDiff
	return ans
t = readInt()
for i in range(t):
	N = readInt()
	arr1 = readList()
	arr2 = readList()
	print(solve(N, arr1, arr2))


import sys
import math
from functools import *
from itertools import *
from collections import *
sys.setrecursionlimit(10 ** 7)
ti = int(input())
for i in range(ti):
	ni = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	(ma, mb) = (min(ai), min(bi))
	print(sum((max(ai[i] - ma, bi[i] - mb) for i in range(ni))))


def GiftsFixing():
	for i in range(int(input())):
		x = int(input())
		y = list(map(int, input().split()))
		z = list(map(int, input().split()))
		a = min(y)
		b = min(z)
		counter = 0
		for i in range(x):
			counter += max(y[i] - a, z[i] - b)
		print(counter)
GiftsFixing()


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

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

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
for _ in range(n):
	m = inp()
	candy = inlt()
	orange = inlt()
	min_candy = min(candy)
	min_orange = min(orange)
	moves = 0
	for x in range(m):
		moves += max(candy[x] - min_candy, orange[x] - min_orange)
	print(moves)


def solve():
	N = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	res = 0
	for i in range(N):
		a[i] -= min_a
		b[i] -= min_b
		res += max(a[i], b[i])
	print(res)
	return

def main():
	T = int(input())
	for i in range(T):
		solve()
	return
main()


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')
for j in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	moves = 0
	for s in range(n):
		moves += max(a[s] - mina, b[s] - minb)
	print(moves)


for _ in range(int(input())):
	input()
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	min_a = min(a)
	min_b = min(b)
	total = 0
	for (i, j) in zip(a, b):
		total += max(i - min_a, j - min_b)
	print(total)


n = int(input())
for i in range(1, n + 1):
	k = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	c = 0
	m = min(arr1)
	m2 = min(arr2)
	for i in range(k):
		c += max(arr1[i] - m, arr2[i] - m2)
	print(c)


import sys

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

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

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

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def solve(n, a, b):
	am = min(a)
	bm = min(b)
	cnt = 0
	for i in range(n):
		aim = a[i] - am
		bim = b[i] - bm
		x = min(aim, bim)
		cnt += x
		cnt += aim - x
		cnt += bim - x
	return cnt

def main():
	for _ in range(ri()):
		n = ri()
		a = ria()
		b = ria()
		wi(solve(n, a, b))
main()


tc = int(input())
mySum = 0
for i in range(tc):
	n = int(input())
	arrayA = list(map(int, input().split()))
	arrayB = list(map(int, input().split()))
	minA = min(arrayA)
	minB = min(arrayB)
	for j in range(0, n):
		diffA = arrayA[j] - minA
		diffB = arrayB[j] - minB
		mySum = mySum + max(diffA, diffB)
	print(mySum)
	mySum = 0


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	c = 0
	k = 0
	for i in range(n):
		if a[i] - a1 > 0 and b[i] - b1 > 0:
			c = c + max(a[i] - a1, b[i] - b1)
		else:
			if a[i] - a1 <= 0 and b[i] - b1 > 0:
				c = c + b[i] - b1
			if a[i] - a1 > 0 and b[i] - b1 <= 0:
				c = c + a[i] - a1
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	moves = []
	min_a = min(a)
	min_b = min(b)
	i = 0
	while i < n:
		moves.append(max(a[i] - min_a, b[i] - min_b))
		i += 1
	print(sum(moves))


t = int(input())
while t > 0:
	ans = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	for i in range(n):
		ans += a[i] - am
		ans += b[i] - bm
		if a[i] != am and b[i] != bm:
			ans -= min(a[i] - am, b[i] - bm)
	print(ans)
	t -= 1


def readn():
	return int(input())

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

def readnos():
	return map(int, input().split())
for _ in range(readn()):
	n = int(input())
	a = readlist()
	b = readlist()
	am = min(a)
	bm = min(b)
	cnt = 0
	for i in range(n):
		if a[i] > am and b[i] == bm:
			cnt += a[i] - am
		elif a[i] == am and b[i] > bm:
			cnt += b[i] - bm
		elif a[i] > am and b[i] > bm:
			x = a[i] - am
			y = b[i] - bm
			if x > y:
				cnt += y + (a[i] - y - am)
			elif y > x:
				cnt += x + (b[i] - x - bm)
			else:
				cnt += x + (b[i] - x - bm)
	print(cnt)


t = int(input())

def func(mat, i, j, n):
	if i == n - 1 and j == n - 1:
		return mat[i][j]
	elif i > n - 1 or i < 0 or j > n - 1 or (j < 0):
		return 100000
	elif mat[i][j] == -1:
		return 100000
	else:
		k = mat[i][j]
		mat[i][j] = -1
		ans = k + min(func(mat, i + 1, j, n), func(mat, i - 1, j, n), func(mat, i, j + 1, n), func(mat, i, j - 1, n))
		print(i, j, ans)
		return ans
		mat[i][j] = k
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	a1 = min(l1)
	a2 = min(l2)
	ans = 0
	for i in range(n):
		a = l1[i] - a1
		b = l2[i] - a2
		ans += min(a, b) + abs(b - a)
	print(ans)


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		amin = min(a)
		bmin = min(b)
		cnt = 0
		for i in range(0, n):
			diffa = a[i] - amin
			diffb = b[i] - bmin
			while diffa != 0 or diffb != 0:
				if diffa == diffb:
					a[i] = amin
					b[i] = bmin
					cnt += diffa
				elif diffa >= diffb:
					a[i] -= diffa - diffb
					cnt += diffa - diffb
				elif diffb > diffa:
					b[i] -= diffb - diffa
					cnt += diffb - diffa
				diffa = a[i] - amin
				diffb = b[i] - bmin
		print(cnt)
main()


import sys, collections, math

def in_out():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for c in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	cost = 0
	for i in range(n):
		cost += max(abs(min_a - a[i]), abs(min_b - b[i]))
	print(cost)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

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

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	ans = ''
	for _ in range(ii()):
		n = ii()
		a = li()
		b = li()
		a_min = min(a)
		b_min = min(b)
		cnt = 0
		for i in range(n):
			if a[i] > a_min and b[i] > b_min:
				cnt += max(a[i] - a_min, b[i] - b_min)
			elif a[i] > a_min:
				cnt += a[i] - a_min
			elif b[i] > b_min:
				cnt += b[i] - b_min
		ans += str(cnt) + '\n'
	print(ans)
main()


t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	p = min(l)
	p1 = min(l1)
	mov = 0
	for i in range(0, n):
		if p == l[i] and p1 == l1[i]:
			continue
		else:
			h = l[i] - p
			h1 = l1[i] - p1
			a = min(h, h1)
			mov += a
			mov += h - a + (h1 - a)
	print(mov)
	t -= 1


a = int(input())
for _ in range(a):
	p = int(input())
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	x = min(li1)
	y = min(li2)
	count = 0
	for i in range(p):
		z = min(li1[i] - x, li2[i] - y)
		count += z
		li1[i] -= z
		li2[i] -= z
		count += li1[i] - x
		count += li2[i] - y
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	moves = 0
	for j in range(n):
		moves += max(a[j] - min_a, b[j] - min_b)
	print(moves)


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	b = []
	sum = 0
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = min(a)
	o = min(b)
	for j in range(n):
		x = a[j] - c
		y = b[j] - o
		maxi = max(x, y)
		mini = min(x, y)
		sum = sum + (maxi - mini) + mini
	print(sum)


from sys import stdin
_input = stdin.readline
(_min, _range, _abs, _int) = (min, range, abs, int)

def solution():
	for _ in _range(_int(_input())):
		n = _int(_input())
		a = [_int(i) for i in _input().split()]
		b = [_int(i) for i in _input().split()]
		ma = _min(a)
		mb = _min(b)
		ans = 0
		for i in _range(n):
			da = a[i] - ma
			db = b[i] - mb
			ans += _min(da, db)
			ans += _abs(da - db)
		print(ans)
solution()


t = int(input(''))
while t > 0:
	n = int(input(''))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - a_min, b[i] - b_min)
	print(ans)
	t -= 1


def solve(n, a, b):
	m1 = min(a)
	m2 = min(b)
	moves = 0
	for i in range(n):
		if a[i] > m1 and b[i] > m2:
			diff1 = a[i] - m1
			diff2 = b[i] - m2
			min_diff = min(diff1, diff2)
			moves += min_diff
			a[i] -= min_diff
			b[i] -= min_diff
		if a[i] > m1:
			diff = a[i] - m1
			moves += diff
			a[i] -= diff
		if b[i] > m2:
			diff = b[i] - m2
			moves += diff
			b[i] -= diff
	print(moves)
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()]
	solve(n, a, b)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		ans += min(a[i] - min_a, b[i] - min_b)
		ans += max(a[i] - min_a, b[i] - min_b) - min(a[i] - min_a, b[i] - min_b)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	min_a = min(a)
	b = list(map(int, input().split()))
	min_b = min(b)
	result = 0
	for i in range(n):
		(a[i], b[i]) = (a[i] - min_a, b[i] - min_b)
		d = min(a[i], b[i])
		result += a[i] + b[i] - d
	print(result)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	result = 0
	for i in range(n):
		rem_a = a[i] - min_a
		rem_b = b[i] - min_b
		result += rem_a if rem_a > rem_b else rem_b
	print(result)


for i in range(int(input())):
	a = int(input())
	b = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
	min1 = min(b)
	min2 = min(c)
	counter = 0
	for i in range(a):
		x = b[i] - min1 - (c[i] - min2)
		if x >= 0:
			counter += b[i] - min1
		else:
			counter += c[i] - min2
	print(counter)


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()]
	(x, y) = (min(a), min(b))
	d = 0
	for j in range(n):
		d += max(abs(a[j] - x), abs(b[j] - y))
	print(d)


T = int(input())
for t in range(1, T + 1):
	N = int(input())
	answer = 0
	a = input().split()
	for i in range(N):
		a[i] = int(a[i])
	b = input().split()
	for i in range(N):
		b[i] = int(b[i])
	min_a = min(a)
	min_b = min(b)
	answer1 = 0
	answer2 = 0
	dif = 0
	for i in range(N):
		if a[i] > min_a and b[i] > min_b:
			dif += min(a[i] - min_a, b[i] - min_b)
		answer1 += a[i] - min_a
		answer2 += b[i] - min_b
	answer = answer1 + answer2 - dif
	print(answer)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	t1 = min(l1)
	t2 = min(l2)
	s = 0
	for j in range(n):
		s = s + max(l1[j] - t1, l2[j] - t2)
	print(s)


t = int(input())
for ti in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	xa = min(a)
	xb = min(b)
	c = 0
	for i in range(n):
		if a[i] > xa and b[i] > xb:
			c += max(a[i] - xa, b[i] - xb)
		else:
			c += a[i] - xa
			c += b[i] - xb
	print(c)


from sys import stdin

def readline():
	return stdin.readline()
tests = int(readline())

def solve(n, a, b):
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		ans1 = min(a[i] - amin, b[i] - bmin)
		ans += ans1 + max(a[i] - amin - ans1, b[i] - bmin - ans1)
	return ans
for t in range(0, tests):
	n = int(readline().rstrip('\n'))
	a = list(map(int, readline().rstrip('\n').split(' ')))
	b = list(map(int, readline().rstrip('\n').split(' ')))
	print(solve(n, a, b))


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()]
	mina = min(a)
	minb = min(b)
	maxa = max(a)
	maxb = max(b)
	count = 0
	if 1:
		for i in range(n):
			if a[i] == mina and b[i] == minb:
				pass
			if a[i] > mina and b[i] > minb:
				if mina > minb:
					z = b[i] - minb
					count += z
					a[i] -= z
					b[i] = minb
				else:
					z = a[i] - mina
					count += z
					b[i] -= z
					a[i] = mina
			if a[i] > mina:
				count += a[i] - mina
			if b[i] > minb:
				count += b[i] - minb
		print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	ans = 0
	j = 0
	while j < n:
		ans += max(a[j] - m1, b[j] - m2)
		j += 1
	print(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()]
	ma = min(a)
	mb = min(b)
	ans = 0
	for i in range(n):
		c = 0
		if a[i] > ma and b[i] > mb:
			c = min(a[i] - ma, b[i] - mb)
			ans += c
			(a[i], b[i]) = (a[i] - c, b[i] - c)
		ans += a[i] - ma + b[i] - mb
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = min(a)
	q = min(b)
	ans = 0
	for j in range(n):
		ans += max(a[j] - p, b[j] - q)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	moves = 0
	i = 0
	for i in range(n):
		if a[i] > ma and b[i] > mb:
			na = a[i] - ma
			nb = b[i] - mb
			nn = min(na, nb)
			moves += nn
			a[i] -= nn
			b[i] -= nn
		if a[i] > ma:
			moves += a[i] - ma
			a[i] -= ma
		if b[i] > mb:
			moves += b[i] - mb
			b[i] -= mb
	print(moves)


import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		(m1, m2) = (min(a), min(b))
		ans = 0
		for i in range(n):
			(x, y) = (a[i] - m1, b[i] - m2)
			ans += max(x, y)
		print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	b = input().split()
	r = 0
	while r < n:
		a[r] = int(a[r])
		b[r] = int(b[r])
		r = r + 1
	amin = min(a)
	bmin = min(b)
	sumi = 0
	p = 0
	while p < n:
		sumi = sumi + max(a[p] - amin, b[p] - bmin)
		p = p + 1
	print(sumi)


t = int(input())
for i in range(0, t):
	n = int(input())
	L = list(map(int, input().split()))
	M = list(map(int, input().split()))
	a = min(L)
	b = min(M)
	count = 0
	for i in range(0, n):
		if L[i] > a and M[i] == b:
			count += L[i] - a
		elif M[i] > b and L[i] == a:
			count += M[i] - b
		else:
			count += max(L[i] - a, M[i] - b)
	print(count)


for _ in range(int(input())):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	moves = 0
	for (a_i, b_i) in zip(a, b):
		a_i -= min_a
		b_i -= min_b
		moves += max(a_i, b_i)
	print(moves)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, a, b):
	ma = min(a)
	mb = min(b)
	a = [a[i] - ma for i in range(n)]
	b = [b[i] - mb for i in range(n)]
	return sum([max(a[i], b[i]) for i in range(n)])
for _ in tests():
	n = int_in()
	a = arr_in()
	b = arr_in()
	out(solve(n, 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()))
	p = min(a)
	q = min(b)
	sumf = 0
	for j in range(n):
		a[j] = abs(a[j] - p)
		b[j] = abs(b[j] - q)
		if a[j] >= b[j]:
			sumf = sumf + a[j]
		else:
			sumf = sumf + b[j]
	print(sumf)


t = int(input())
for hh in range(0, t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	mna = min(a)
	mnb = min(b)
	ans = 0
	for i in range(0, n):
		diff1 = a[i] - mna
		diff2 = b[i] - mnb
		mnn = min(diff1, diff2)
		ans += mnn
		diff1 -= mnn
		diff2 -= mnn
		ans += diff1
		ans += diff2
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		da = a[i] - mina
		db = b[i] - minb
		k = min(da, db)
		ans += da + db - k
	print(ans)


import sys
q = int(input())
for i in range(q):
	n = int(sys.stdin.readline())
	a = [int(j) for j in sys.stdin.readline().split()]
	b = [int(j) for j in sys.stdin.readline().split()]
	ta = min(a)
	tb = min(b)
	kolvo = 0
	for j in range(n):
		kolvo += max(a[j] - ta, b[j] - tb)
	print(kolvo)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	ans = 0
	for elem in range(n):
		a[elem] -= am
		b[elem] -= bm
	for elem in range(n):
		ans += max(a[elem], b[elem])
	print(ans)


for j in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	count = 0
	for i in range(n):
		count = count + min(a[i] - ma, b[i] - mb)
		l = a[i]
		r = b[i]
		a[i] = a[i] - min(l - ma, r - mb)
		b[i] = b[i] - min(l - ma, r - mb)
		count = count + a[i] - ma
		count = count + b[i] - mb
	print(count)


import math
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)
from collections import defaultdict
mod = 10 ** 9 + 7
from bisect import bisect_left as bl, bisect_right as br, bisect as bis, insort_left as il, insort_right as ir, insort as isrt

def solve(arr, brr):
	amin = min(arr)
	bmin = min(brr)
	ans = 0
	for i in range(len(arr)):
		astep = arr[i] - amin
		bstep = brr[i] - bmin
		ans += max(astep, bstep)
	return ans
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	print(solve(arr, brr))


import sys

def parse_array(array_str, n):
	array_str = array_str.split(sep=' ')
	arr = [int] * n
	min_num = sys.maxsize
	for i in range(0, n):
		num = int(array_str[i])
		if num < min_num:
			min_num = num
		arr[i] = num
	return (min_num, arr)

def fix_gifts(candy, orange, candy_min, orange_min, n):
	moves = 0
	for i in range(0, n):
		moves = moves + max(candy[i] - candy_min, orange[i] - orange_min)
	return moves
test_cases = int(input(''))
for a in range(0, test_cases):
	n = int(input(''))
	candy_str = input('')
	orange_str = input('')
	(candy_min, candy) = parse_array(candy_str, n)
	(orange_min, orange) = parse_array(orange_str, n)
	moves = fix_gifts(candy, orange, candy_min, orange_min, n)
	print(moves)


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	x = min(arr1)
	y = min(arr2)
	moves = 0
	for i in range(n):
		(a, b) = (arr1[i], arr2[i])
		moves += max(a - x, b - y)
	print(moves)


t = int(input())
for i in range(t):
	ans = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m_a = min(a)
	m_b = min(b)
	for j in range(n):
		k1 = a[j] - m_a
		k2 = b[j] - m_b
		ans += max(k1, k2)
	print(ans)


t = int(input())
for x in range(t):
	n = int(input())
	candy = list(map(int, input().split(' ')))
	orange = list(map(int, input().split(' ')))
	z = 0
	ca = candy[0]
	ora = orange[0]
	while z < n:
		if candy[z] < ca:
			ca = candy[z]
		if orange[z] < ora:
			ora = orange[z]
		z = z + 1
	y = 0
	sum = 0
	while y < n:
		t1 = candy[y] - ca
		t2 = orange[y] - ora
		t3 = max(t1, t2) - min(t1, t2)
		t4 = min(t1, t2) + t3
		sum = sum + t4
		y = y + 1
	print(sum)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(item) for item in input().split()]
	brr = [int(item) for item in input().split()]
	min1 = 10 ** 9 + 1
	min2 = 10 ** 9 + 1
	for i in range(n):
		if arr[i] < min1:
			min1 = arr[i]
		if brr[i] < min2:
			min2 = brr[i]
	for i in range(n):
		arr[i] = arr[i] - min1
		brr[i] = brr[i] - min2
	count = 0
	for i in range(n):
		count = count + max(arr[i], brr[i])
	print(count)


for i in range(int(input())):
	n = int(input())
	a = []
	b = []
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		a[i] = a[i] - mina
		b[i] = b[i] - minb
		if a[i] > b[i]:
			ans = ans + a[i]
		else:
			ans = ans + b[i]
	print(ans)


import time, math as mt, bisect, sys
from sys import stdin, stdout
from collections import defaultdict
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

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

def IO():
	return stdin.readline()

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

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return
mod = 10 ** 9 + 7

def solve():
	n = II()
	a = L()
	b = L()
	mov = 0
	(m1, m2) = (min(a), min(b))
	for i in range(n):
		(d1, d2) = (max(a[i] - m1, 0), max(b[i] - m2, 0))
		mov += max(d1, d2)
	P(mov)
	return
t = II()
for i in range(t):
	solve()


from __future__ import division, print_function
import os
import 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 main():
	pass
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 j in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	m = min(arr1)
	l = min(arr2)
	ans = 0
	for i in range(n):
		res = max(arr1[i] - m, arr2[i] - l)
		ans = ans + res
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	minc = min(a)
	mino = min(b)
	for i in range(n):
		ans += max(a[i] - minc, b[i] - mino)
	print(ans)


from sys import stdin
N = int(stdin.readline())
for case in range(N):
	length = int(stdin.readline())
	candies = list(map(int, stdin.readline().split()))
	oranges = list(map(int, stdin.readline().split()))
	moves = 0
	mincand = min(candies)
	minorange = min(oranges)
	for i in range(length):
		moves += max(candies[i] - mincand, oranges[i] - minorange)
	print(moves)


t = int(input())
while t > 0:
	gift = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	c_min = min(candy)
	o_min = min(orange)
	count = 0
	for i in range(gift):
		count += max(abs(candy[i] - c_min), abs(orange[i] - o_min))
	print(count)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	min1 = min(arr1)
	min2 = min(arr2)
	ct = 0
	for i in range(0, n):
		a = arr1[i] - min1
		b = arr2[i] - min2
		ct += max([a, b])
	print(ct)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	mn1 = min(l1)
	mn2 = min(l2)
	ans = 0
	for i in range(n):
		ans += l1[i] - mn1
		ans += l2[i] - mn2
		ans -= min(l2[i] - mn2, l1[i] - mn1)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	mc = min(candies)
	mo = min(oranges)
	ans = 0
	for i in range(n):
		candies[i] -= mc
		oranges[i] -= mo
		ans += min(candies[i], oranges[i]) + abs(candies[i] - oranges[i])
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	moves = 0
	candies_min = min(candies)
	oranges_min = min(oranges)
	for i in range(n):
		if candies[i] == candies_min and oranges[i] != oranges_min:
			moves += abs(oranges[i] - oranges_min)
		elif candies[i] != candies_min and oranges_min == oranges[i]:
			moves += abs(candies_min - candies[i])
		elif candies[i] != candies_min and oranges[i] != oranges_min:
			temp1 = candies[i] - candies_min
			temp2 = oranges[i] - oranges_min
			moves += min(temp1, temp2)
			y = min(temp1, temp2)
			candies[i] -= y
			oranges[i] -= y
			if candies[i] == candies_min and oranges[i] != oranges_min:
				moves += abs(oranges[i] - oranges_min)
			elif candies[i] != candies_min and oranges_min == oranges[i]:
				moves += abs(candies_min - candies[i])
	print(moves)


T = int(input())
for _ in range(T):
	n = int(input())
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	l1 = min(a1)
	l2 = min(a2)
	moves = 0
	for (i, j) in zip(a1, a2):
		m1 = i - l1
		m2 = j - l2
		moves += max(m1, m2)
	print(moves)


def solve(a, b, n):
	(min_a, min_b) = (min(a), min(b))
	res = 0
	for i in range(n):
		res += max(a[i] - min_a, b[i] - min_b)
	return res
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(a, b, n))


n = int(input())
for _ in range(n):
	ans = 0
	nn = int(input())
	ls1 = list(map(int, input().split()))
	ls2 = list(map(int, input().split()))
	a = min(ls1)
	b = min(ls2)
	for i in range(nn):
		ans += max(ls1[i] - a, ls2[i] - b)
	print(ans)


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()]
	s = 0
	(x, y) = (min(a), min(b))
	for j in range(n):
		s += max(a[j] - x, b[j] - y)
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(ma, mb) = (min(a), min(b))
	steps = 0
	for i in range(n):
		(y, u) = (a[i] - ma, b[i] - mb)
		o = min(y, u)
		a[i] -= o
		b[i] -= o
		steps += o
		steps += y + u - o - o
	print(steps)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = [int(i) for i in input().split()]
	l2 = [int(i) for i in input().split()]
	(x, y) = (min(l1), min(l2))
	c = 0
	for i in range(n):
		a = abs(l1[i] - x)
		b = abs(l2[i] - y)
		c += max(a, b)
	print(c)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	m1 = min(c)
	m2 = min(o)
	coun = 0
	for i in range(0, n):
		coun += max(c[i] - m1, o[i] - m2)
	print(coun)


T = int(input())
for t in range(T):
	l = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	steps = 0
	for i in range(l):
		steps += max(a[i] - min_a, b[i] - min_b)
	print(steps)


t = int(input())
for i in range(t):
	ans = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mnA = min(a)
	mnB = min(b)
	for i in range(n):
		ans += max(a[i] - mnA, b[i] - mnB)
	print(ans)


t = int(input())
for i in range(t):
	q = 0
	n = int(input())
	a = input()
	b = input()
	a = a.split(' ')
	b = b.split(' ')
	a = list(map(int, a))
	b = list(map(int, b))
	m = min(a)
	p = min(b)
	for j in range(n):
		d = min(a[j] - m, b[j] - p)
		q += d
		a[j] -= d
		b[j] -= d
		if a[j] > m:
			q = q + a[j] - m
		if b[j] > p:
			q = q + b[j] - p
	print(q)


import sys
from math import sqrt, gcd, ceil, log
from collections import defaultdict, Counter, deque
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))

def main():
	ans_ = []
	for _ in range(int(input())):
		n = int(input())
		arr = read()
		arr2 = read()
		(m1, m2) = (min(arr), min(arr2))
		ans = 0
		for i in range(n):
			ans += max(arr[i] - m1, arr2[i] - m2)
		ans_.append(str(ans))
	print('\n'.join(ans_))
main()


a = int(input())
for i in range(a):
	s = int(input())
	z = list(map(int, input().split()))
	m = list(map(int, input().split()))
	p = min(z)
	q = min(m)
	total = 0
	for i in range(len(z)):
		a = z[i] - p
		b = m[i] - q
		if a == 0 or b == 0:
			total += a + b
		else:
			total += a + b - min(a, b)
	print(total)


def main(n, a, b):
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		temp_a = 0
		temp_b = 0
		if min_a < a[i]:
			temp_a = a[i] - min_a
		if min_b < b[i]:
			temp_b = b[i] - min_b
		ans += max(temp_a, temp_b)
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(main(n, a, b))


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 foo():
	n = inp()
	lst1 = inlt()
	lst2 = inlt()
	m1 = min(lst1)
	m2 = min(lst2)
	ans = 0
	for (item1, item2) in zip(lst1, lst2):
		ans += max(item1 - m1, item2 - m2)
	print(ans)
t = inp()
for i in range(t):
	foo()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	can = min(a)
	ora = min(b)
	ans = 0
	for i in range(n):
		diffc = a[i] - can
		diffo = b[i] - ora
		diffc = max(0, diffc)
		diffo = max(0, diffo)
		x = min(diffc, diffo)
		ans += x
		diffc -= x
		diffo -= x
		ans += diffc
		ans += diffo
	print(ans)


from sys import stdin, stdout
q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	minia = 10000000000
	minib = 10000000000
	for i in range(n):
		if a[i] < minia:
			minia = a[i]
		if b[i] < minib:
			minib = b[i]
	da = [0 for i in range(n)]
	db = [0 for i in range(n)]
	sum1 = 0
	for i in range(n):
		da[i] = a[i] - minia
		db[i] = b[i] - minib
		sum1 += max(da[i], db[i])
	print(sum1)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	ml1 = min(l1)
	ml2 = min(l2)
	c = 0
	for i in range(n):
		x = 0
		y = 0
		if l1[i] != ml1:
			x = l1[i] - ml1
		if l2[i] != ml2:
			y = l2[i] - ml2
		c += max(x, y)
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	ma = min(ai)
	mb = min(bi)
	ans = 0
	for i in range(n):
		num = ai[i] - ma
		num2 = bi[i] - mb
		ans += num + num2 - min(num, num2)
	print(ans)


import sys
for _ in range(int(input())):
	n = int(input())
	o_list = list(map(int, sys.stdin.readline().split()))
	c_list = list(map(int, sys.stdin.readline().split()))
	o_e_l = [0 for i in range(n)]
	c_e_l = [0 for i in range(n)]
	o_min = min(o_list)
	c_min = min(c_list)
	for i in range(n):
		o_e_l[i] = o_list[i] - o_min
		c_e_l[i] = c_list[i] - c_min
	ans = 0
	for j in range(n):
		ans += max(o_e_l[j], c_e_l[j])
	print(ans)


t = int(input())
count = 0
tru = 0
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ax = min(a)
	bx = min(b)
	tru = 0
	count = 0
	for j in range(n):
		if a[j] > ax and b[j] > bx:
			tru += min(a[j] - ax, b[j] - bx)
	for k in range(0, len(a)):
		if ax < a[k]:
			count += a[k] - ax
	for l in range(0, len(b)):
		if bx < b[l]:
			count += b[l] - bx
	print(count - tru)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	su = 0
	for i in range(n):
		if a[i] != amin:
			if b[i] != bmin:
				d = min(a[i] - amin, b[i] - bmin)
				su = su + d + (a[i] - amin - d) + (b[i] - bmin - d)
			else:
				su += a[i] - amin
		elif b[i] != bmin:
			su += b[i] - bmin
	print(su)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		diffa = a[i] - mina
		diffb = b[i] - minb
		ans += max(diffa, diffb)
	print(ans)


from sys import stdin

def solve(arr1, arr2, n):
	ans = 0
	min_a = min(arr1)
	min_b = min(arr2)
	for i in range(n):
		if arr1[i] > min_a and arr2[i] > min_b:
			diff = min(arr1[i] - min_a, arr2[i] - min_b)
			ans += diff
			arr1[i] -= diff
			arr2[i] -= diff
		if arr1[i] > min_a:
			ans += arr1[i] - min_a
			arr1[i] = arr1[i] - min_a
		if arr2[i] > min_b:
			ans += arr2[i] - min_b
			arr2[i] = arr2[i] - min_b
	return ans
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	arr1 = [int(x) for x in stdin.readline().split()]
	arr2 = [int(x) for x in stdin.readline().split()]
	print(solve(arr1, arr2, n))


kol = int(input())
for i in range(kol):
	n = int(input())
	oranges = [int(i) for i in input().split()]
	sweets = [int(i) for i in input().split()]
	(mino, mins) = (min(oranges), min(sweets))
	kol = 0
	for i in range(n):
		if oranges[i] > mino and sweets[i] > mins:
			k = min(oranges[i] - mino, sweets[i] - mins)
			(oranges[i], sweets[i], kol) = (oranges[i] - k, sweets[i] - k, kol + k)
		if oranges[i] > mino:
			kol += oranges[i] - mino
		if sweets[i] > mins:
			kol += sweets[i] - mins
	print(kol)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	total_moves = []
	for i in range(n):
		d1 = a[i] - min_a
		d2 = b[i] - min_b
		total_moves.append(max(d1, d2))
	print(sum(total_moves))


import math
import sys
import itertools
import random
import bisect
import heapq
import collections

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

def hcf(x, y):
	return math.gcd(x, y)

def primes(n):
	prime = [True for _ in range(0, n + 1)]
	res = []
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[p] = False
		p += 1
	for i in range(0, n + 1):
		if prime[i] == True:
			res.append(i)
	return res

def primeFactors(n):
	res = []
	while n % 2 == 0:
		res.append(2)
		n //= 2
	for i in range(3, math.sqrt(n) + 1, 2):
		while n % i == 0:
			res.append(i)
			n //= i
	if n > 2:
		res.append(n)
	return res
for _ in range(0, int(input())):
	n = int(input())
	c = list(map(int, input().strip().split()))
	o = list(map(int, input().strip().split()))
	min_c = min(c)
	min_o = min(o)
	res = 0
	for i in range(0, n):
		excess_from_candy_min = c[i] - min_c
		excess_from_orange_min = o[i] - min_o
		tem = min(excess_from_candy_min, excess_from_orange_min)
		res += tem
		excess_from_orange_min -= tem
		excess_from_candy_min -= tem
		res += max(excess_from_candy_min, excess_from_orange_min)
	print(res)


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ct = 0
	tempa = 0
	tempb = 0
	for i in range(0, n):
		tempa = 0
		tempb = 0
		if a[i] == mina:
			pass
		else:
			tempa = a[i] - mina
		if b[i] == minb:
			pass
		else:
			tempb = b[i] - minb
		if tempa == tempb:
			ct += tempa
		else:
			ct += max(tempa, tempb)
	print(ct)


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 = min(A)
	b = min(B)
	f = 0
	k = 0
	for i in range(n):
		f = f + (A[i] - a) + (B[i] - b)
		c = A[i] - a
		d = B[i] - b
		k = k + min(c, d)
	print(f - k)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k1 = min(a)
	k2 = min(b)
	count = 0
	for i in range(n):
		c1 = a[i] - k1
		c2 = b[i] - k2
		count += max(c1, c2)
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	mina = min(a)
	minb = min(b)
	opa = [0] * n
	opb = [0] * n
	res = 0
	for i in range(n):
		opa[i] = a[i] - mina
		opb[i] = b[i] - minb
		res += max(opa[i], opb[i])
	print(res)


t = int(input())
while t > 0:
	n = int(input())
	arr1 = list(map(int, input().strip().split()))
	arr2 = list(map(int, input().strip().split()))
	min1 = min(arr1)
	min2 = min(arr2)
	c = 0
	for i in range(n):
		c += max(arr1[i] - min1, arr2[i] - min2)
	print(c)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	t = min(a)
	s = min(b)
	p = 0
	for i in range(n):
		u = a[i] - t
		v = b[i] - s
		p += max(u, v)
	print(p)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	sum = 0
	for j in range(len(a)):
		sum = sum + max(abs(ma - a[j]), abs(mb - b[j]))
	print(sum)


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()]
	mina = min(a)
	minb = min(b)
	count = 0
	for i in range(n):
		count += max((a[i] - mina, b[i] - minb))
	print(count)


for t in range(int(input())):
	n = int(input())
	a = list(map(lambda x: int(x), input().split(' ')))
	b = list(map(lambda x: int(x), input().split(' ')))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - amin, b[i] - bmin)
	print(ans)


t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	m = 0
	for i in range(n):
		while a[i] != mina or b[i] != minb:
			if a[i] > mina and b[i] > minb:
				d1 = a[i] - mina
				d2 = b[i] - minb
				if d1 < d2:
					m = m + d1
					a[i] = mina
					b[i] = b[i] - d1
				else:
					m = m + d2
					b[i] = minb
					a[i] = a[i] - d2
			elif a[i] > mina:
				m = m + (a[i] - mina)
				a[i] = mina
			elif b[i] > minb:
				m = m + (b[i] - minb)
				b[i] = minb
	print(m)


T = int(input())
r = []
for k in range(T):
	count = 0
	s = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	a = sorted(l)[0]
	b = sorted(m)[0]
	for i in l:
		count = count + i - a
	for u in m:
		count = count + u - b
	for j in range(s):
		if l[j] - a > m[j] - b:
			count = count - m[j] + b
		else:
			count = count - l[j] + a
	r.append(count)
for i in r:
	print(i)


cases = int(input())
answers = [0] * cases
for i in range(cases):
	amount = int(input())
	candiesR = input().split()
	orangesR = input().split()
	candies = [0] * amount
	oranges = [0] * amount
	for j in range(amount):
		candies[j] = int(candiesR[j])
		oranges[j] = int(orangesR[j])
	for j in range(amount):
		answers[i] += max(candies[j] - min(candies), oranges[j] - min(oranges))
for i in range(cases):
	print(answers[i])


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sa = sum(a)
	sb = sum(b)
	sa1 = min(a)
	sb1 = min(b)
	s = 0
	for i in range(n):
		if a[i] > sa1 and b[i] > sb1:
			p = min(a[i] - sa1, b[i] - sb1)
			s += p
			s += max(a[i] - sa1 - p, b[i] - sb1 - p)
		elif a[i] > sa1:
			s += a[i] - sa1
		elif b[i] > sb1:
			s += b[i] - sb1
	print(s)
	t -= 1


t = int(input())
for step in range(t):
	n = int(input())
	a = [int(data) for data in input().split()]
	b = [int(data) for data in input().split()]
	min_a = a[0]
	min_b = b[0]
	for i in range(n):
		if a[i] < min_a:
			min_a = a[i]
		if b[i] < min_b:
			min_b = b[i]
	ans = 0
	for i in range(n):
		eat_a = a[i] - min_a
		eat_b = b[i] - min_b
		ans += max(eat_a, eat_b)
	print(ans)


t = input()
t = int(t)
while t != 0:
	n = input()
	n = int(n)
	a = map(int, input().split())
	a = list(a)
	b = map(int, input().split())
	b = list(b)
	minimuma = min(a)
	minimumb = min(b)
	count = 0
	for i in range(0, n):
		if a[i] > minimuma and b[i] > minimumb:
			x = min(a[i] - minimuma, b[i] - minimumb)
			a[i] -= x
			b[i] -= x
			count += x
		if a[i] > minimuma and b[i] == minimumb:
			x = a[i] - minimuma
			a[i] -= x
			count += x
		if a[i] == minimuma and b[i] > minimumb:
			x = b[i] - minimumb
			b[i] -= x
			count += x
	print(count)
	t -= 1


t = int(input())
i = 1
while i <= t:
	n = int(input())
	lst1 = list(map(int, input().strip().split()))
	lst2 = list(map(int, input().strip().split()))
	l1 = len(set(list(lst1)))
	l2 = len(set(list(lst2)))
	count = 0
	if l1 == 1 and l2 == 1:
		print(count)
	else:
		s1 = min(lst1)
		s2 = min(lst2)
		if l1 == 1 and l2 != 1:
			for j in range(0, n):
				count += lst2[j] - s2
		elif l1 != 1 and l2 == 1:
			for j in range(0, n):
				count += lst1[j] - s1
		else:
			for j in range(0, n):
				if lst1[j] != s1 and lst2[j] == s2:
					count += lst1[j] - s1
				elif lst1[j] == s1 and lst2[j] != s2:
					count += lst2[j] - s2
				else:
					a = lst1[j] - s1
					b = lst2[j] - s2
					count += max(a, b)
		print(count)
	i += 1


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def Golomb(n):
	dp = [0] * (n + 1)
	dp[1] = 1
	for i in range(2, n + 1):
		dp[i] = 1 + dp[i - dp[dp[i - 1]]]
	return dp[1:]

def solve(leftAllowed, leftLast, ix, movesLeft, dp, a):
	if dp[leftAllowed][leftLast][ix] != -1:
		return dp[leftAllowed][leftLast][ix]
	if movesLeft == 0:
		return 0
	res = 0
	if leftLast == 0 and ix > 0 and (leftAllowed > 0):
		res = max(res, solve(leftAllowed - 1, 1, ix - 1, movesLeft - 1, dp, a) + a[ix - 1])
	res = max(res, solve(leftAllowed, 0, ix + 1, movesLeft - 1, dp, a) + a[ix + 1])
	dp[leftAllowed][leftLast][ix] = res
	return dp[leftAllowed][leftLast][ix]
MOD = 1000000007
PMOD = 998244353
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	b = list(map(int, stdin.readline().rstrip().split()))
	if len(set(a)) == 1 and len(set(b)) == 1:
		print(0)
		continue
	A = a.copy()
	B = b.copy()
	ma = min(a)
	mb = min(b)
	for i in range(n):
		a[i] -= ma
		b[i] -= mb
	ans = 0
	for i in range(n):
		ans += min(A[i] - ma, B[i] - mb)
		ans += abs(A[i] - ma - B[i] + mb)
	print(min(ans, sum(a) + sum(b)))


t = int(input())
for i in range(0, t):
	a = int(input())
	ls1 = list(map(int, input().rstrip().split()))
	ls2 = list(map(int, input().rstrip().split()))
	aa = ls1[0]
	bb = ls2[0]
	j = 0
	m = 0
	while j < a:
		if ls1[j] < aa:
			aa = ls1[j]
		if ls2[j] < bb:
			bb = ls2[j]
		j += 1
	j = 0
	while j < a:
		while ls1[j] != aa or ls2[j] != bb:
			if ls1[j] != aa and ls2[j] != bb:
				cc = ls1[j] - aa
				dd = ls2[j] - bb
				d = min(cc, dd)
				ls1[j] = ls1[j] - d
				ls2[j] = ls2[j] - d
				m += d
			elif ls1[j] != aa:
				d = ls1[j] - aa
				ls1[j] = ls1[j] - d
				m += d
			elif ls2[j] != bb:
				d = ls2[j] - bb
				ls2[j] = ls2[j] - d
				m += d
		j += 1
	print(m)


t = int(input())
for _ in range(t):
	k = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	i = 0
	m1 = min(x)
	m2 = min(y)
	count = 0
	while i < k:
		if x[i] == m1 and y[i] == m2:
			i += 1
		elif x[i] == m1:
			count += y[i] - m2
			i += 1
		elif y[i] == m2:
			count += x[i] - m1
			i += 1
		else:
			g = -m1 + x[i]
			q = -m2 + y[i]
			if q >= g:
				x[i] -= g
				y[i] -= g
				count += g
			else:
				x[i] -= q
				y[i] -= q
				count += q
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(s) for s in input().split(' ')]
	b = [int(s) for s in input().split(' ')]
	min_a = min(a)
	min_b = min(b)
	moves = 0
	for i in range(n):
		diff_a = a[i] - min_a
		diff_b = b[i] - min_b
		moves += max(diff_a, diff_b)
	print(moves)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l = [0] * n
	mina = min(l1)
	minb = min(l2)
	for i in range(n):
		a = l1[i] - mina
		b = l2[i] - minb
		l[i] = max(a, b)
	print(sum(l))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	c = 0
	for (i, j) in zip(a, b):
		if i == min_a and j == min_b:
			continue
		elif i == min_a and j > min_b:
			c += j - min_b
		elif j == min_b and i > min_a:
			c += i - min_a
		elif j > min_b and i > min_a:
			dif1 = j - min_b
			dif2 = i - min_a
			if dif1 > dif2:
				if i - dif1 >= min_a:
					c += dif1
					i -= dif1
					c += i - min_a
				else:
					c += dif2
					j -= dif2
					c += j - min_b
			elif j - dif2 >= min_b:
				c += dif2
				j -= dif2
				c += j - min_b
			else:
				c += dif1
				i -= dif1
				c += i - min_a
	print(c)


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(l, r) = (min(a), min(b))
	tot = 0
	for i in range(n):
		tot += max(a[i] - l, b[i] - r)
	print(tot)


t = int(input())
S = []
count = 0
counta = 0
countb = 0
for i in range(t):
	count = 0
	counta = 0
	countb = 0
	n = int(input())
	a = input()
	A = list(map(int, a.strip().split()))
	b = input()
	B = list(map(int, b.strip().split()))
	mia = min(A)
	mib = min(B)
	for j in range(n):
		counta = A[j] - mia
		countb = B[j] - mib
		count += max(counta, countb)
	S.append(count)
for i in range(t):
	print(S[i])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - m1, b[i] - m2)
	print(ans)


def sortGifts(x, candies, oranges):
	list1 = []
	list2 = []
	for c in range(x):
		list1.append(int(candies[c]))
		list2.append(int(oranges[c]))
	return (list1, list2)

def findMin(x, y):
	x.sort()
	y.sort()
	return (x[0], y[0])

def equalize(x, list1, list2, m, n):
	counter = 0
	counter1 = 0
	counter2 = 0
	for c in range(x):
		if list1[c] > m:
			counter1 += list1[c] - m
		if list2[c] > n:
			counter2 += list2[c] - n
		if counter1 >= counter2:
			counter += counter1
		else:
			counter += counter2
		counter1 = counter2 = 0
	return counter
cases = int(input(''))
output = []
list1 = []
list2 = []
for cases in range(cases):
	x = int(input(''))
	candies = input('').split()
	oranges = input('').split()
	(list1, list2) = sortGifts(x, candies, oranges)
	(m, n) = findMin(list1, list2)
	(list1, list2) = sortGifts(x, candies, oranges)
	output.append(equalize(x, list1, list2, m, n))
print(*output, sep='\n')


from subprocess import CalledProcessError

def main():
	testcases = int(input())
	for i in range(testcases):
		lang = int(input())
		a = input()
		aa = []
		aa = a.split()
		aa[:] = list(map(int, aa))
		b = input()
		bb = []
		bb = b.split()
		bb[:] = list(map(int, bb))
		gifts(aa, bb, lang)

def gifts(a, b, lang):
	counter = 0
	mina = min(a)
	minb = min(b)
	for i in range(lang):
		if a[i] > mina or b[i] > minb:
			counter += max(a[i] - mina, b[i] - minb)
	print(counter)
main()


tests = int(input())
for test in range(tests):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	(targetA, targetB) = (min(a), min(b))
	ans = 0
	for i in range(n):
		ans += max(a[i] - targetA, b[i] - targetB)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	c = 0
	for i in range(n):
		if a[i] == am and b[i] == bm:
			continue
		elif a[i] == am:
			c += b[i] - bm
		elif b[i] == bm:
			c += a[i] - am
		else:
			c += max(a[i] - am, b[i] - bm)
	print(c)


for i in range(int(input())):
	n = int(input())
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	li1min = min(li1)
	li2min = min(li2)
	ans = 0
	for i in range(n):
		ans += max(li1[i] - li1min, li2[i] - li2min)
	print(ans)


rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : [int(x) for x in rr().split()]
from sys import stdin, stdout, setrecursionlimit

def sol():
	n = rri()
	lis = rrm()
	nums = rrm()
	x = min(lis)
	y = min(nums)
	res = 0
	for i in range(n):
		a = lis[i] - x
		b = nums[i] - y
		res += max(a, b)
	print(res)
	return

def main():
	T = rri()
	for t in range(1, T + 1):
		ans = sol()
main()


def counting():
	howManyPresent = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	minumumCandy = min(candy)
	minOrange = min(orange)
	move = 0
	for i in range(0, howManyPresent):
		if orange[i] > minOrange and candy[i] > minumumCandy:
			maxiumumOgrange = orange[i] - minOrange
			maxiumumCandy = candy[i] - minumumCandy
			if maxiumumCandy > maxiumumOgrange:
				move = move + (maxiumumCandy - maxiumumOgrange)
				candy[i] = candy[i] - (maxiumumCandy - maxiumumOgrange)
				orange[i] = minOrange
			else:
				move = move + maxiumumCandy
				candy[i] = minumumCandy
				orange[i] = orange[i] - maxiumumCandy
		if candy[i] > minumumCandy:
			move = move + (candy[i] - minumumCandy)
			candy[i] = minumumCandy
	for j in range(0, howManyPresent):
		if orange[j] > minOrange:
			move = move + (orange[j] - minOrange)
			orange[j] = minOrange
	return move
howManyTest = int(input())
for i in range(0, howManyTest):
	print(counting())


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(aa, bb) = (min(a), min(b))
	s = 0
	for i in range(n):
		if a[i] > aa and b[i] > bb:
			s += max(a[i] - aa, b[i] - bb)
		else:
			s += a[i] - aa
			s += b[i] - bb
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	c = 0
	for i in range(n):
		if a[i] > am and b[i] > bm:
			temp = min(a[i], b[i]) - min(am, bm)
			a[i] -= temp
			b[i] -= temp
			c += temp
		if a[i] > am:
			c += a[i] - am
		if b[i] > bm:
			c += b[i] - bm
	print(c)


from collections import Counter
cases = int(input())
for _ in range(cases):
	n = int(input())
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	tot = 0
	l1 = min(c)
	l2 = min(d)
	for i in range(n):
		tot += max(c[i] - l1, d[i] - l2)
	print(tot)


for i in range(int(input())):
	z = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	mx = min(l)
	mx1 = min(l1)
	ans = 0
	for j in range(z):
		ans += max(l[j] - mx, l1[j] - mx1)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	l = []
	c = 0
	b = [int(y) for y in input().split()]
	for i in range(len(a)):
		if a[i] > min(a) and b[i] > min(b):
			c += min(a[i] - min(a), b[i] - min(b))
		c += max(a[i] - min(a), b[i] - min(b))
		c -= min(a[i] - min(a), b[i] - min(b))
	print(c)


for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	m = 0
	for i in range(a):
		m = m + max(abs(b[i] - min(b)), abs(c[i] - min(c)))
	print(m)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = 0
	for (x, y) in zip(a, b):
		if x > ma and y > mb:
			z = min(x - ma, y - mb)
			c += z
			x -= z
			y -= z
		c += x - ma + (y - mb)
	print(c)


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

def insr():
	s = input()
	return s

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

def solve(l1, l2):
	m1 = min(l1)
	m2 = min(l2)
	s = 0
	for i in range(len(l1)):
		to_red1 = l1[i] - m1
		to_red2 = l2[i] - m2
		s += max(to_red1, to_red2)
	return s
r = inp()
for i in range(r):
	a = inp()
	l2 = inlt()
	l3 = inlt()
	s = solve(l2, l3)
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	m1 = min(a)
	m2 = min(b)
	for i in range(n):
		if a[i] != m1 and b[i] != m2:
			c = c + max(b[i] - m2, a[i] - m1) - min(b[i] - m2, a[i] - m1) + min(b[i] - m2, a[i] - m1)
		elif a[i] == m1 and b[i] != m2:
			c = c + b[i] - m2
		elif a[i] != m1 and b[i] == m2:
			c = c + a[i] - m1
		else:
			c = c + 0
	print(c)


from collections import defaultdict as dd
import math
import sys
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

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

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

def solve():
	n = nn()
	o = lm()
	c = lm()
	min_o = min(o)
	min_c = min(c)
	moves = 0
	for i in range(n):
		moves += max(o[i] - min_o, c[i] - min_c)
	print(moves)
q = nn()
for _ in range(q):
	solve()


import sys
t = int(input().strip())
for a0 in range(t):
	n = int(input())
	l1 = [int(i) for i in input().split()]
	l2 = [int(i) for i in input().split()]
	m1 = l1[0]
	m2 = l2[0]
	a = 0
	b = 0
	for i in range(len(l1)):
		if l1[i] < m1:
			m1 = l1[i]
			a = i
	for i in range(len(l2)):
		if l2[i] < m2:
			m2 = l2[i]
			b = i
	c = 0
	if a != b:
		c = c + abs(l2[a] - l2[b]) + abs(l1[b] - l1[a])
	for i in range(n):
		if i == a or i == b:
			pass
		else:
			c += max(l1[i] - l1[a], l2[i] - l2[b])
	print(c)


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()]
	a1 = min(a)
	b1 = min(b)
	c = 0
	for i in range(n):
		if a[i] == a1 and b[i] > b1:
			c += b[i] - b1
		elif a[i] > a1 and b[i] == b1:
			c += a[i] - a1
		elif a[i] > a1 and b[i] > b1:
			c += min(b[i] - b1, a[i] - a1)
			d = min(b[i] - b1, a[i] - a1)
			m = max(b[i] - b1, a[i] - a1)
			c += m - d
	print(c)


T = int(input())
for i in range(T):
	N = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	x1 = []
	x2 = []
	for i in range(N):
		x1.append(lst1[i])
		x2.append(lst2[i])
	x1.sort()
	x2.sort()
	mna = x1[0]
	mnb = x2[0]
	ans = 0
	for j in range(N):
		ans += max(lst1[j] - mna, lst2[j] - mnb)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	a1Min = min(a1)
	b1Min = min(b1)
	count = i = 0
	while i < n:
		if a1[i] > a1Min and b1[i] > b1Min:
			tmp = min(a1[i] - a1Min, b1[i] - b1Min)
			count += tmp
			a1[i] -= tmp
			b1[i] -= tmp
		if a1[i] > a1Min:
			count += a1[i] - a1Min
		if b1[i] > b1Min:
			count += b1[i] - b1Min
		i += 1
	print(count)


t = int(input())
for cases in range(t):
	n = int(input())
	g1 = [int(num) for num in input().split(' ')]
	g2 = [int(num) for num in input().split(' ')]
	a = min(g1)
	b = min(g2)
	count = 0
	for i in range(n):
		if g1[i] == a and g2[i] == b:
			count = count
		elif g1[i] == a or g2[i] == b:
			if g1[i] == a:
				count = count + g2[i] - b
				g2[i] = b
			elif g2[i] == b:
				count = count + g1[i] - a
				g1[i] = a
		elif g1[i] != a and g2[i] != b:
			x = min(g1[i] - a, g2[i] - b)
			count = count + x
			if g1[i] - a == x:
				g1[i] = a
				g2[i] = g2[i] - x
				count = count + g2[i] - b
			elif g2[i] - b == x:
				g2[i] = b
				g1[i] = g1[i] - x
				count = count + g1[i] - a
	print(count)


test = int(input())
while test > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mini = min(a)
	maxi = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - mini, b[i] - maxi)
	print(ans)
	test -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	total = 0
	for i in range(n):
		x = a[i] - ma
		y = b[i] - mb
		total += max(x, y)
	print(total)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - min_a, b[i] - min_b)
	print(ans)


output = []
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	count = 0
	min_a = min(a)
	min_b = min(b)
	if a.count(a[0]) == len(a) and b.count(b[0]) == len(b):
		output.append(count)
	else:
		for i in range(n):
			temp = min(abs(a[i] - min_a), abs(b[i] - min_b))
			a[i] -= temp
			b[i] -= temp
			count += temp
		for i in range(n):
			count += abs(min_a - a[i])
			count += abs(min_b - b[i])
		output.append(count)
for _ in output:
	print(_)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	a = min(l1)
	b = min(l2)
	ans = 0
	for j in range(n):
		ans += max(l1[j] - a, l2[j] - b)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	apple = min(a)
	orange = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - apple, b[i] - orange)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		aa = a[i] - ma
		ab = b[i] - mb
		if aa == 0 or ab > aa:
			c += ab
		elif ab == 0 or aa > ab:
			c += aa
		else:
			c += aa
	print(c)


x = int(input())
for i in range(x):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s1 = min(a)
	s2 = min(b)
	ans = 0
	for j in range(n):
		ans += max(a[j] - s1, b[j] - s2)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a_line = list(map(int, input().split()))
	b_line = list(map(int, input().split()))
	min_a = min(a_line)
	min_b = min(b_line)
	moves = 0
	for i in range(len(a_line)):
		moves_needed = max(a_line[i] - min_a, b_line[i] - min_b)
		moves += moves_needed
	print(moves)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	a_min = min(a)
	b_min = min(b)
	cnt = 0
	for j in range(n):
		cnt += max(a[j] - a_min, b[j] - b_min)
	print(cnt)


from sys import stdin
for _ in range(int(stdin.readline().rstrip())):
	n = int(stdin.readline().rstrip())
	a = list(map(int, stdin.readline().rstrip().split(' ')))
	b = list(map(int, stdin.readline().rstrip().split(' ')))
	min_a = min(a)
	min_b = min(b)
	t = 0
	for i in range(n):
		t += max(a[i] - min_a, b[i] - min_b)
	print(t)


for t in range(int(input())):
	n = int(input())
	a = []
	b = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	i = 0
	moves = 0
	for i in range(n):
		atemp = 0
		btemp = 0
		if a[i] > amin:
			atemp = a[i] - amin
		if b[i] > bmin:
			btemp = b[i] - bmin
		if atemp > btemp:
			moves = moves + atemp
		elif btemp > atemp:
			moves = moves + btemp
		elif atemp == btemp:
			moves = moves + atemp
	print(moves)


t = int(input())

def process(min_sweet, sweet, min_orange, orange):
	sweet_steps = 0
	orange_steps = 0
	if sweet > min_sweet:
		sweet_steps = sweet - min_sweet
	if orange > min_orange:
		orange_steps = orange - min_orange
	total_steps = min(sweet_steps, orange_steps)
	total_steps += abs(sweet_steps - orange_steps)
	return total_steps
results = list()
for _ in range(t):
	n = int(input())
	sweets = [int(i) for i in input().split()]
	oranges = [int(i) for i in input().split()]
	min_sweet = min(sweets)
	min_orange = min(oranges)
	count = 0
	for j in range(len(sweets)):
		count += process(min_sweet, sweets[j], min_orange, oranges[j])
	results.append(str(count))
print('\n'.join(results))


test = int(input())
for _ in range(test):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	min1 = min(candy)
	min2 = min(orange)
	a = []
	b = []
	for i in range(n):
		result1 = candy[i] - min1
		result2 = orange[i] - min2
		a.append(result1)
		b.append(result2)
	final = sum(a) + sum(b)
	for i in range(n):
		final -= min(a[i], b[i])
	print(final)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	if n == 1:
		print(0)
		continue
	count = 0
	for j in range(n):
		count += max(a[j] - a_min, b[j] - b_min)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		if a[i] == min_a and b[i] > min_b:
			ans += b[i] - min_b
		elif a[i] > min_a and b[i] == min_b:
			ans += a[i] - min_a
		elif a[i] > min_a and b[i] > min_b:
			x = a[i] - min_a
			y = b[i] - min_b
			ans += x + y - min(x, y)
	print(ans)


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	x = 0
	c = min(a)
	e = min(b)
	f = min(c, e)
	d = 0
	while len(set(b)) != 1 or len(set(a)) != 1:
		if a[x] > c and b[x] > e:
			if a[x] - c <= b[x] - e:
				d += a[x] - c
				b[x] = b[x] - (a[x] - c)
				a[x] = c
			else:
				d += b[x] - e
				a[x] -= b[x] - e
				b[x] = e
		if a[x] != c:
			d += a[x] - c
			a[x] = c
		if b[x] != e:
			d += b[x] - e
			b[x] = e
		x += 1
	print(d)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	mina = min(l1)
	minb = min(l2)
	ans = 0
	for i in range(n):
		diffa = l1[i] - mina
		diffb = l2[i] - minb
		res = min(diffb, diffa)
		ans += res
		l1[i] -= res
		l2[i] -= res
	for i in range(n):
		ans += l1[i] - mina
		ans += l2[i] - minb
	print(ans)


num_cases = int(input())
for case_index in range(num_cases):
	num_gifts = int(input())
	candy = input()
	a = candy.split(' ')
	orange = input()
	b = orange.split(' ')
	a = list(map(int, a))
	b = list(map(int, b))
	min_candy = min(a)
	min_orange = min(b)
	num_moves = 0
	for i in range(num_gifts):
		c_moves = a[i] - min_candy
		o_moves = b[i] - min_orange
		moves = c_moves if c_moves > o_moves else o_moves
		num_moves += moves
	print(num_moves)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	counta = []
	answer = 0
	for i in range(n):
		tmp = abs(mina - a[i])
		counta.append(tmp)
	minb = min(b)
	for i in range(n):
		be = abs(minb - b[i])
		tmp = min(be, counta[i])
		answer += tmp
		answer += max(be, counta[i]) - tmp
	print(answer)


def equalize(n, sweets, oranges):
	sweet_base = min(sweets)
	orange_base = min(oranges)
	ans = 0
	for i in range(n):
		diff_sweet = sweets[i] - sweet_base
		diff_orange = oranges[i] - orange_base
		ans += max(diff_sweet, diff_orange)
	return ans
t = int(input())
for k in range(t):
	n = int(input())
	sweets = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	print(equalize(n, sweets, oranges))


import sys
input = sys.stdin.readline
t = int(input())
for ti in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mia = min(a)
	mib = min(b)
	ans = 0
	for i in range(n):
		da = a[i] - mia
		db = b[i] - mib
		both = min(da, db)
		ans += da - both + (db - both) + both
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	count = 0
	for i in range(n):
		difa = a[i] - x
		difb = b[i] - y
		count += max(difa, difb)
	print(count)


t = int(input())
for p in range(t):
	n = int(input())
	flag = 0
	a1 = [int(i) for i in input().split()]
	a2 = [int(i) for i in input().split()]
	min1 = min(a1)
	for i in range(n):
		a1[i] -= min1
	min2 = min(a2)
	for i in range(n):
		a2[i] -= min2
	res = 0
	for i in range(n):
		res += max(a1[i], a2[i])
	print(res)


import sys
lines = []
for line in sys.stdin:
	if 'exit' == line.rstrip():
		break
	lines.append(line)
t = int(lines[0])

def zero_col(i, a, b):
	if a[i] == 0 or b[i] == 0:
		return True
	else:
		return False
for case in range(1, 3 * t + 1, 3):
	n = int(lines[case])
	a = [int(x) for x in lines[case + 1].split(' ')]
	b = [int(x) for x in lines[case + 2].split(' ')]
	min_a = min(a)
	min_b = min(b)
	for i in range(n):
		a[i] -= min_a
		b[i] -= min_b
	steps = 0
	for i in range(n):
		if not zero_col(i, a, b):
			if a[i] > b[i]:
				steps += min(a[i], b[i])
				a[i] -= b[i]
				b[i] = 0
			elif b[i] > a[i]:
				steps += min(b[i], a[i])
				b[i] -= a[i]
				a[i] = 0
			else:
				steps += a[i]
				(a[i], b[i]) = (0, 0)
	steps += sum(a)
	steps += sum(b)
	print(steps)


from sys import stdin, stdout

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

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(x, y) = (min(a), min(b))
	c = 0
	for i in range(n):
		s1 = a[i] - x
		s2 = b[i] - y
		c += max(s1, s2)
	print(c)
for t in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	(a, b) = [list(map(int, input().split())) for i in range(2)]
	(x, y) = (min(a), min(b))
	ans = 0
	for i in range(n):
		temp = min(a[i] - x, b[i] - y)
		ans += temp + a[i] + b[i] - (x + y + 2 * temp)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a_list = [int(x) for x in input().split()]
	b_list = [int(x) for x in input().split()]
	count = 0
	min_a = min(a_list)
	min_b = min(b_list)
	for i in range(n):
		d_a = a_list[i] - min_a
		d_b = b_list[i] - min_b
		count += min(d_a, d_b) + abs(d_a - d_b)
	print(count)


n = int(input())
for i in range(0, n):
	count = 0
	a = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	m1 = min(l1)
	m2 = min(l2)
	for j in range(0, a):
		count += max(l1[j] - m1, l2[j] - m2)
	print(count)


t = int(input())
for tt in range(t):
	n = int(input())
	c = [*map(int, input().split())]
	o = [*map(int, input().split())]
	flagc = False
	flago = False
	for i in c:
		if i != c[0]:
			break
	else:
		flagc = True
	for i in o:
		if i != o[0]:
			break
	else:
		flago = True
	if flagc and flago:
		print(0)
		continue
	a = min(c)
	b = min(o)
	if a == b:
		move = 0
		for i in range(n):
			if c[i] == a and o[i] == a:
				continue
			elif c[i] == a:
				move += o[i] - a
			elif o[i] == a:
				move += c[i] - a
			elif o[i] != a and c[i] != a:
				if o[i] >= c[i]:
					move += o[i] - a
				else:
					move += c[i] - a
	else:
		move = 0
		for i in range(n):
			if c[i] == a and o[i] > b:
				move += o[i] - b
			elif c[i] > a and o[i] == b:
				move += c[i] - a
			if c[i] > a and o[i] > b:
				j = c[i] - a
				k = o[i] - b
				move += max(j, k)
	print(move)


def solve():
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	minCand = min(candies)
	minOran = min(oranges)
	sol = 0
	li = []
	for i in range(0, n):
		li.append([candies[i], oranges[i]])
	for l in li:
		if l[0] == minCand and l[1] == minOran:
			continue
		elif l[0] != minCand and l[1] != minOran:
			ldiff = l[0] - minCand
			rdiff = l[1] - minOran
			diff = min(ldiff, rdiff)
			sol += diff
			sol += l[0] - diff - minCand
			sol += l[1] - diff - minOran
		elif l[0] != minCand and l[1] == minOran:
			diff = l[0] - minCand
			sol += diff
		elif l[0] == minCand and l[1] != minOran:
			diff = l[1] - minOran
			sol += diff
	print(sol)
tc = int(input())
for i in range(tc):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for (_a, _b) in zip(a, b):
		count_a = 0 if _a == min_a else _a - min_a
		count_b = 0 if _b == min_b else _b - min_b
		ans += max(count_a, count_b)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	A = min(a)
	B = min(b)
	a = [x - A for x in a]
	b = [y - B for y in b]
	ans = 0
	for i in range(n):
		ans += min(a[i], b[i]) + abs(a[i] - b[i])
	print(ans)


from __future__ import division, print_function
import os, sys
import math
import collections
from itertools import permutations
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

class my_dictionary(dict):

	def __init__(self):
		self = dict()

	def add(self, key, value):
		self[key] = value

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(n - r))

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -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 padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(my_list):
	freq = {}
	for item in my_list:
		if item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
	return freq

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

def primeFactors(n):
	j = []
	while n % 2 == 0:
		j.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			j.append(int(n))
			n = n / i
	if n > 2:
		j.append(int(n))
	return j

def sumdigit(n):
	n = str(n)
	k = 0
	for i in range(len(n)):
		k += int(n[i])
	return k

def question(a, n):
	j = a
	for i in range(n):
		if a[i] == '1':
			j[i] = '0'
		else:
			j[i] = '1'
	j[0, n - 1].reverse()
	return j

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		b = li()
		kl = min(a)
		jk = min(b)
		res = 0
		for i in range(n):
			j = abs(kl - a[i])
			k = abs(jk - b[i])
			res += min(j, k)
			res += max(j, k) - min(j, k)
		print(res)
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 z in range(t):
	n = int(input())
	arrc = list(map(int, input().split()))
	arro = list(map(int, input().split()))
	ansf = 0
	minc = min(arrc)
	mino = min(arro)
	for i in range(n):
		diffc = abs(minc - arrc[i])
		diffo = abs(mino - arro[i])
		ansf = ansf + max(diffc, diffo)
	print(ansf)


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	mc = min(c)
	mo = min(o)
	ans = 0
	for i in range(n):
		if c[i] != mc and o[i] != mo:
			amount = min(c[i] - mc, o[i] - mo)
			ans += amount
			c[i] -= amount
			o[i] -= amount
		if c[i] != mc:
			amount = c[i] - mc
			ans += amount
			c[i] -= amount
		if o[i] != mo:
			amount = o[i] - mo
			ans += amount
			o[i] -= amount
	print(ans)


from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
tc = ii1()
for _ in range(tc):
	n = ii1()
	cand = iia()
	oran = iia()
	a = min(cand)
	b = min(oran)
	res = 0
	for (i, j) in zip(cand, oran):
		t1 = i - a
		t2 = j - b
		res += min(t1, t2)
		res += max(t1, t2) - min(t1, t2)
	print(res)


t = int(input())
for case in range(t):
	n = int(input())
	List_1 = [int(j) for j in input().split(' ')]
	List_2 = [int(j) for j in input().split(' ')]
	d = min(List_1)
	g = min(List_2)
	count = 0
	for i in range(n):
		if List_1[i] > d and List_2[i] > g:
			count += min(List_1[i] - d, List_2[i] - g) + abs(List_1[i] - d - (List_2[i] - g))
		else:
			count += abs(List_1[i] - d - (List_2[i] - g))
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 0
	candy = min(a)
	orange = min(b)
	for i in range(n):
		s += max(a[i] - candy, b[i] - orange)
	print(s)


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	(min1, min2) = (min(arr1), min(arr2))
	ans = 0
	for i in range(n):
		t1 = arr1[i] - min1
		t2 = arr2[i] - min2
		ans += max(t1, t2)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))[:n]
	b = list(map(int, input().split()))[:n]
	m1 = min(a)
	m2 = min(b)
	c = 0
	for i in range(n):
		x = a[i] - m1
		y = b[i] - m2
		d = max(x, y)
		c = c + d
	print(c)


test_case = int(input())
for itt in range(test_case):
	nonsense = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	lowest_candy = min(candy)
	lowest_orange = min(orange)
	for i in range(len(candy)):
		candy[i] -= lowest_candy
	for i in range(len(orange)):
		orange[i] -= lowest_orange
	counter = 0
	for i in range(len(candy)):
		counter += max(candy[i], orange[i])
	print(counter)


import sys

def equalize(apples, oranges):
	a = min(apples)
	b = min(oranges)
	eat = 0
	for i in range(len(apples)):
		eat += max(apples[i] - a, oranges[i] - b)
	return eat
t = int(sys.stdin.readline())
for i in range(t):
	n = int(sys.stdin.readline())
	apples = list(map(int, sys.stdin.readline().split()))
	oranges = list(map(int, sys.stdin.readline().split()))
	print(equalize(apples, oranges))


x = int(input())
for y in range(x):
	z = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	e1 = min(arr1)
	e2 = min(arr2)
	d = 0
	for (b1, b2) in zip(arr1, arr2):
		if b1 - e1 > b2 - e2:
			d += b1 - e1
		else:
			d += b2 - e2
	print(d)


def ipa():
	return int(input())

def sip():
	return input()

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

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst
t = ipa()
while t:
	t -= 1
	n = ipa()
	arr = lip()
	lst = lip()
	a = min(arr)
	b = min(lst)
	count = 0
	for i in range(n):
		count += max(arr[i] - a, lst[i] - b)
	print(count)


t = input()
t = int(t)
while t > 0:
	n = input()
	n = int(n)
	a = input()
	b = input()
	a = [int(i) for i in a.split()]
	b = [int(i) for i in b.split()]
	ans = 0
	min_a = min(a)
	min_b = min(b)
	for i in range(len(a)):
		if a[i] > min_a and b[i] > min_b:
			tot = a[i] - min_a + b[i] - min_b
			mx = max(a[i] - min_a, b[i] - min_b)
			ans += mx
		elif a[i] > min_a:
			ans += a[i] - min_a
		elif b[i] > min_b:
			ans += b[i] - min_b
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	y = min(a)
	z = min(b)
	total = 0
	for i in range(n):
		total += max(a[i] - y, b[i] - z)
	print(total)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	o = [int(i) for i in input().split()]
	ans = 0
	am = min(a)
	om = min(o)
	for i in range(n):
		if a[i] > am and o[i] > om:
			count = min(abs(a[i] - am), abs(o[i] - om))
			a[i] = a[i] - count
			o[i] = o[i] - count
			ans += count
		if a[i] > am and o[i] <= om:
			count = a[i] - am
			a[i] = a[i] - count
			ans += count
		if o[i] > om and a[i] <= am:
			count = o[i] - om
			o[i] = o[i] - count
			ans += count
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	list2 = list(map(int, input().strip().split()))
	x = min(list1)
	y = min(list2)
	count = 0
	for i in range(n):
		if list1[i] == x and list2[i] == y:
			count += 0
		elif list1[i] == x:
			count += list2[i] - y
		elif list2[i] == y:
			count += list1[i] - x
		else:
			count += max(list1[i] - x, list2[i] - y)
	print(count)


def func(n, arr, brr):
	target = (min(arr), min(brr))
	ops = 0
	for i in range(n):
		ops += max(arr[i] - target[0], brr[i] - target[1])
	return ops
for t in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	brr = [int(x) for x in input().split()]
	print(func(n, arr, brr))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diff_a = [i - min(a) for i in a]
	diff_b = [i - min(b) for i in b]
	temp = list(zip(diff_a, diff_b))
	res = sum((max(i[0], i[1]) for i in temp))
	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()]
	m1 = min(a)
	m2 = min(b)
	a1 = [x - m1 for x in a]
	b1 = [x - m2 for x in b]
	ans = 0
	for i in range(n):
		ans += min(a1[i], b1[i]) + abs(a1[i] - b1[i])
	print(ans)


for tst in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	mina = min(a)
	minb = min(b)
	s = 0
	for i in range(n):
		x = a[i] - mina
		y = b[i] - minb
		s += max(x, y)
	print(s)


from sys import stdin
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	minA = min(a)
	minB = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - minA, b[i] - minB)
	print(ans)


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	arr1 = list(map(int, sys.stdin.readline().split()))
	arr2 = list(map(int, sys.stdin.readline().split()))
	ans = 0
	min1 = min(arr1)
	min2 = min(arr2)
	for i in range(n):
		diff1 = arr1[i] - min1
		diff2 = arr2[i] - min2
		val = min(diff1, diff2)
		ans += val
		diff1 -= val
		diff2 -= val
		ans += diff1 + diff2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	(minCan, minOrg) = (min(candy), min(orange))
	ans = 0
	for i in range(n):
		ans += max(candy[i] - minCan, orange[i] - minOrg)
	print(ans)


def function(c, o, n):
	min_c = min(c)
	min_o = min(o)
	count = 0
	for i in range(n):
		if c[i] > min_c:
			if o[i] > min_o:
				x = min(c[i] - min_c, o[i] - min_o)
				count += x
				c[i] -= x
				o[i] -= x
			count += c[i] - min_c
	for j in range(n):
		if o[j] > min_o:
			count += o[j] - min_o
	print(count)
t = int(input())
while t:
	n = int(input())
	c = list(map(int, input().rstrip().split()))
	o = list(map(int, input().rstrip().split()))
	function(c, o, n)
	t -= 1


a = int(input())
for k in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	e = min(c)
	f = min(d)
	sum = 0
	for j in range(b):
		sum += max(c[j] - e, d[j] - f)
	print(sum)


nbtest = int(input())
x = 0
for i in range(nbtest):
	nbgifts = int(input())
	(list1, list2) = (list(map(int, input().split())), list(map(int, input().split())))
	minval1 = min(list1)
	minval2 = min(list2)
	for j in range(len(list1)):
		val1 = list1[j] - minval1
		val2 = list2[j] - minval2
		if val1 > val2:
			x = x + val1
		else:
			x = x + val2
	print(x)
	x = 0


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	moves = 0
	minA = min(a)
	minB = min(b)
	for i in range(n):
		diff1 = a[i] - minA
		diff2 = b[i] - minB
		moves += max(diff1, diff2)
	print(moves)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	a_min = min(a)
	b_min = min(b)
	ans = 0
	for i in range(n):
		t = 0
		t1 = 0
		if a[i] > a_min:
			t = a[i] - a_min
		if b[i] > b_min:
			t1 = b[i] - b_min
		ans += max(t, t1)
	print(ans)


input_length = int(input())
while input_length != 0:
	arraylength = int(input())
	inp_string_a = str(input())
	inp_string_b = str(input())
	input_length -= 1
	candies = tuple(inp_string_a.split())
	orange = tuple(inp_string_b.split())
	candies = [int(i) for i in candies]
	orange = [int(i) for i in orange]
	min_candy = min(candies)
	min_orange = min(orange)
	moves = 0
	for i in range(0, arraylength):
		candydiff = candies[i] - min_candy
		orangediff = orange[i] - min_orange
		maxdiff = max(orangediff, candydiff)
		moves += maxdiff
	print(moves)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	s = 0
	for i in range(len(a)):
		k = a[i] - m1
		s += k
		b[i] = b[i] - k if b[i] - k >= m2 else m2
	for i in range(len(a)):
		k = b[i] - m2
		s += k
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	s1 = 0
	s2 = 0
	c = 0
	for i in range(n):
		s1 = a[i] - m1
		s2 = b[i] - m2
		if s1 < s2:
			c += s1 + (s2 - s1)
		else:
			c += s2 + (s1 - s2)
	print(c)


for _ in range(int(input())):
	n = int(input())
	arr_o = [int(x) for x in input().split()]
	arr_c = [int(x) for x in input().split()]
	mino = min(arr_o)
	minc = min(arr_c)
	moves = 0
	for i in range(n):
		diffo = arr_o[i] - mino
		diffc = arr_c[i] - minc
		minn = min(diffo, diffc)
		moves += minn
		arr_o[i] -= minn
		arr_c[i] -= minn
		moves += arr_o[i] - mino
		moves += arr_c[i] - minc
	print(moves)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	counter = 0
	for i in range(n):
		c = a[i] - amin
		d = b[i] - bmin
		counter = counter + abs(c - d) + min(c, d)
	print(counter)


MOD = 1000000007
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())
from collections import *
for _ in range(ii()):
	n = ii()
	a = il()
	b = il()
	u = min(a)
	v = min(b)
	c = 0
	for i in range(0, n):
		c = c + max(abs(u - a[i]), abs(v - b[i]))
	print(c)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	amin = min(A)
	bmin = min(B)
	ans = 0
	for i in range(N):
		asub = A[i] - amin
		bsub = B[i] - bmin
		ans += asub + bsub - min(asub, bsub)
	print(ans)


t = int(input())
for each in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	for i in range(n):
		a[i] = a[i] - mina
		b[i] = b[i] - minb
	c = 0
	for i in range(n):
		if a[i] > b[i]:
			c += a[i]
		elif b[i] > a[i]:
			c += b[i]
		else:
			c += a[i]
	print(c)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	f = min(l)
	g = min(m)
	t = []
	v = []
	count = 0
	for i in l:
		t.append(i - f)
	for j in m:
		v.append(j - g)
	for q in range(n):
		count += max(t[q], v[q])
	print(count)


def read_nums():
	return [int(x) for x in input().split()]

def solve():
	_ = read_nums()
	candies = read_nums()
	oranges = read_nums()
	min_candies = min(candies)
	min_oranges = min(oranges)
	candies_to_eat = [x - min_candies for x in candies]
	oranges_to_eat = [x - min_oranges for x in oranges]
	res = sum([max(c, o) for (c, o) in zip(candies_to_eat, oranges_to_eat)])
	print(res)

def main():
	(t,) = read_nums()
	for _ in range(t):
		solve()
main()


t = int(input())
for _ in range(t):
	(n, l, m) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
	(a, b, s) = (min(l), min(m), 0)
	for i in range(n):
		s += max(l[i] - a, m[i] - b)
	print(s)


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heapreplace, heappushpop
from bisect import bisect_right, bisect_left

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 si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
mod = 1000000007
res = ['NO', 'YES']
(test, test_case) = (0, 1)
test_case = ii()
while test < test_case:
	test += 1
	n = ii()
	a = li()
	b = li()
	(x, y) = (min(a), min(b))
	ans = 0
	for i in range(n):
		p = a[i] - x
		q = b[i] - y
		ans += max(p, q)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	i = 0
	move = 0
	while i < n:
		if a[i] == ma:
			if b[i] != mb:
				move += b[i] - mb
		elif b[i] == mb:
			move += a[i] - ma
		else:
			move += max(a[i] - ma, b[i] - mb)
		i += 1
	print(move)


t = int(input())
for T in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	A = min(a)
	B = min(b)
	sol = 0
	for i in range(n):
		x = max(a[i] - A, b[i] - B)
		sol += x
	print(sol)


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	brr = [int(x) for x in input().split()]
	minia = min(arr)
	minib = min(brr)
	for i in range(n):
		arr[i] = arr[i] - minia
		brr[i] = brr[i] - minib
	count = 0
	for i in range(n):
		if brr[i] == 0 and arr[i] == 0:
			continue
		elif arr[i] == 0 and brr[i] != 0:
			count += brr[i]
		elif brr[i] == 0 and arr[i] != 0:
			count += arr[i]
		else:
			temp = min(arr[i], brr[i])
			count += temp
			arr[i] = arr[i] - temp
			brr[i] = brr[i] - temp
			count += brr[i] + arr[i]
	print(count)


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	n = inp()
	x = ip()
	y = ip()
	a = min(x)
	b = min(y)
	ans = 0
	for i in range(n):
		ans += max(x[i] - a, y[i] - b)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	lsta = list(map(int, input().split()))
	lstb = list(map(int, input().split()))
	a = min(lsta)
	b = min(lstb)
	m = min(a, b)
	count = 0
	i = 0
	while i < n:
		if (lsta[i] != a and lstb[i] != b) and lsta[i] > a and (lstb[i] > b):
			diff1 = lsta[i] - a
			diff2 = lstb[i] - b
			count += min(diff1, diff2)
			lsta[i] = lsta[i] - min(diff1, diff2)
			lstb[i] = lstb[i] - min(diff1, diff2)
		i += 1
	for i in range(n):
		if lsta[i] > a:
			diff = lsta[i] - a
			count += diff
			lsta[i] = a
		if lstb[i] > b:
			diff = lstb[i] - b
			count += diff
			lstb[i] = b
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	t1 = min(a)
	t2 = min(b)
	for i in range(n):
		a[i] -= t1
		b[i] -= t2
	total = 0
	for i in range(n):
		total = total + a[i] + b[i] - min(a[i], b[i])
	print(total)


for z in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = 1100000000
	min_b = 1100000000
	(fin, sum_a, sum_b) = (0, 0, 0)
	for i in range(n):
		if a[i] <= min_a:
			min_a = a[i]
		if b[i] <= min_b:
			min_b = b[i]
		sum_a += a[i]
		sum_b += b[i]
	for i in range(n):
		if a[i] > min_a and b[i] > min_b:
			k = min(a[i] - min_a, b[i] - min_b)
			fin = fin + k
			a[i] -= k
			b[i] -= k
			sum_a -= k
			sum_b -= k
	fin += sum_a - min_a * n + sum_b - min_b * n
	print(fin)


t = int(input())
a = [[]] * t
b = [[]] * t
for i in range(t):
	input()
	a[i] = list(map(int, input().split()))
	b[i] = list(map(int, input().split()))
for (a, b) in zip(a, b):
	amin = min(a)
	bmin = min(b)
	count = 0
	for (a, b) in zip(a, b):
		a1 = a - amin
		b1 = b - bmin
		count += max(a1, b1)
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	aa = a.split()
	b = input()
	bb = b.split()
	sum1 = 0
	sum2 = 0
	for i in range(n):
		aa[i] = int(aa[i])
		sum1 += aa[i]
		bb[i] = int(bb[i])
		sum2 += bb[i]
	min1 = aa[0]
	min2 = bb[0]
	for j in range(1, n):
		if aa[j] < min1:
			min1 = aa[j]
		if bb[j] < min2:
			min2 = bb[j]
	m3 = 0
	for k in range(n):
		m3 += min(aa[k] - min1, bb[k] - min2)
	m1 = sum1 - n * min1
	m2 = sum2 - n * min2
	ans = m1 + m2 - m3
	print(ans)


t = int(input())
while t != 0:
	count = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	choco = min(a)
	orange = min(b)
	for i in range(n):
		chocodif = 0
		orangedif = 0
		if a[i] > choco:
			chocodif = a[i] - choco
		if b[i] > orange:
			orangedif = b[i] - orange
		count += max(chocodif, orangedif)
	print(count)
	t -= 1


I = input
for _ in range(int(I())):
	n = int(I())
	q = list(map(int, input().split()))
	w = list(map(int, input().split()))
	a = min(q)
	b = min(w)
	d = 0
	for i in range(n):
		d += max(q[i] - a, w[i] - b)
	print(d)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ma = min(a)
	mb = min(b)
	res = 0
	for i in range(n):
		res += max(a[i] - ma, b[i] - mb)
	print(res)


import sys
input = sys.stdin.readline
t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(mina, minb) = (min(a), min(b))
	ans = 0
	for i in range(n):
		ans += max(a[i] - mina, b[i] - minb)
	print(ans)


n = int(input())
for i in range(n):
	final = 0
	total = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	min1 = min(arr1)
	min2 = min(arr2)
	for j in range(total):
		final += max(arr1[j] - min1, arr2[j] - min2)
	print(final)


n = int(input())
for _ in range(n):
	kk = int(input())
	k1 = list(map(int, input().split()))
	k2 = list(map(int, input().split()))
	p1 = min(k1)
	p2 = min(k2)
	for i in range(kk):
		if k1[i] >= p1:
			k1[i] = k1[i] - p1
	for j in range(kk):
		if k2[j] >= p2:
			k2[j] = k2[j] - p2
	sum1 = 0
	for i in range(kk):
		sum1 = sum1 + max(k1[i], k2[i])
	print(sum1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr1 = list(map(int, input().split()))
	sm = min(arr)
	sm1 = min(arr1)
	sum = 0
	for i in range(n):
		sum = sum + max(arr[i] - sm, arr1[i] - sm1)
	print(sum)


for _ in range(int(input())):
	total_gifts = int(input())
	candies = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	min_can = min(candies)
	min_orange = min(orange)
	result = []
	moves = 0
	for i in range(total_gifts):
		c = candies[i] - min_can
		o = orange[i] - min_orange
		q = (c, o)
		result.append(q)
	for (i, j) in result:
		minimum = min(i, j)
		moves += minimum
		i -= minimum
		j -= minimum
		moves += i
		moves += j
	print(moves)


for _ in range(int(input())):
	n = int(input())
	lsta = list(map(int, input().split()))
	lstb = list(map(int, input().split()))
	mna = min(lsta)
	mnb = min(lstb)
	ct = 0
	for i in range(n):
		if lsta[i] > mna and lstb[i] > mnb:
			mn = min(lstb[i] - mnb, lsta[i] - mna)
			ct += mn
			ct += max(lsta[i] - mna, lstb[i] - mnb) - mn
		elif lstb[i] == mnb:
			ct += lsta[i] - mna
		elif lsta[i] == mna:
			ct += lstb[i] - mnb
	print(ct)


try:
	for _ in range(int(input())):
		n = int(input())
		a = [int(i) for i in input().split()]
		b = [int(i) for i in input().split()]
		a1 = min(a)
		b1 = min(b)
		m = 0
		for i in range(n):
			d1 = a[i] - a1
			d2 = b[i] - b1
			m += max(d1, d2)
		print(m)
except:
	pass


p = int(input())
for y in range(p):
	x = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	a1 = min(arr1)
	a2 = min(arr2)
	c = 0
	for (b1, b2) in zip(arr1, arr2):
		if b1 - a1 > b2 - a2:
			c += b1 - a1
		else:
			c += b2 - a2
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	li_a = list(map(int, input().split()))
	li_b = list(map(int, input().split()))
	min_a = min(li_a)
	min_b = min(li_b)
	diff_a = 0
	diff_b = 0
	res = 0
	for i in range(n):
		diff_a = li_a[i] - min_a
		diff_b = li_b[i] - min_b
		temp = max(diff_b, diff_a)
		res += temp
	print(res)


import math as mt

def tran(arr, brr, n):
	am = min(arr)
	bm = min(brr)
	c = 0
	for i in range(n):
		if brr[i] == bm and arr[i] == am:
			pass
		elif brr[i] > bm and arr[i] == am:
			c = c + brr[i] - bm
		elif brr[i] == bm and arr[i] > am:
			c = c + arr[i] - am
		elif brr[i] > bm and arr[i] > am:
			p = max(brr[i] - bm, arr[i] - am)
			c = c + p
	return c
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	arr = list(map(int, input().rstrip().split()))
	brr = list(map(int, input().rstrip().split()))
	r = tran(arr, brr, n)
	ans.append(r)
for i in ans:
	print(i)


t_count = int(input().strip())
while t_count > 0:
	n = int(input().strip())
	candies = list(map(int, input().strip().split(' ')))
	oranges = list(map(int, input().strip().split(' ')))
	moves = 0
	min_can = min(candies)
	min_orn = min(oranges)
	for (i, j) in zip(candies, oranges):
		a = i - min_can
		b = j - min_orn
		x = min(a, b)
		y = max(a, b)
		moves += x
		moves += y - x
	print(moves)
	t_count -= 1


from sys import stdin
fi = stdin
n_test = int(fi.readline())

def solve():
	n = int(fi.readline())
	a = [int(v) for v in fi.readline().split()]
	b = [int(v) for v in fi.readline().split()]
	aa = min(a)
	bb = min(b)
	res = 0
	for (ai, bi) in zip(a, b):
		res += max(ai - aa, bi - bb)
	print(res)
for i_test in range(n_test):
	solve()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	k = list(map(int, input().split()))
	mini = min(a)
	mini1 = min(k)
	h = 0
	for j in range(n):
		r1 = a[j] - mini
		r2 = k[j] - mini1
		while r1 != 0 or r2 != 0:
			if r1 >= 1 and r2 >= 1:
				if r1 > r2:
					r3 = r2
				else:
					r3 = r1
				h += r3
				r1 -= r3
				r2 -= r3
			elif r1 == 0:
				h += r2
				r2 = 0
			elif r2 == 0:
				h += r1
				r1 = 0
	print(h)


for i in range(int(input())):
	x = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	k1 = min(l1)
	k2 = min(l2)
	sum = 0
	for i in range(x):
		l1[i] -= k1
		l2[i] -= k2
		sum += max(l1[i], l2[i])
	print(sum)


t = int(input())
for _ in range(t):
	count = 0
	n = int(input())
	arr = list(map(int, input().split()))
	arr1 = list(map(int, input().split()))
	x = min(arr)
	y = min(arr1)
	for i in range(n):
		if arr[i] != x and arr1[i] != y:
			p = min(arr[i] - x, arr1[i] - y)
			count += p + (max(arr[i] - x, arr1[i] - y) - p)
		elif arr[i] == x and arr1[i] != y:
			count += arr1[i] - y
		elif arr[i] != x and arr1[i] == y:
			count += arr[i] - x
		else:
			pass
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	p = min(a)
	q = min(b)
	for i in range(n):
		x = max(a[i] - p, b[i] - q)
		c += x
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	ans = 0
	for i in range(n):
		if a[i] > am and b[i] > bm:
			c = a[i] - am
			d = b[i] - bm
			ans += min(c, d) + abs(c - d)
		elif a[i] > am:
			ans += a[i] - am
		else:
			ans += b[i] - bm
	print(ans)


for _ in ' ' * int(input()):
	a = int(input())
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	bav = min(b)
	cav = min(c)
	s = 0
	for i in range(a):
		z = b[i] - bav
		z1 = c[i] - cav
		k = min(z, z1)
		s += k
		z -= k
		z1 -= k
		s += z + z1
	print(s)


from sys import stdin, stdout

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

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	araz = 0
	braz = 0
	otv = 0
	for i in range(n):
		araz = a[i] - amin
		braz = b[i] - bmin
		otv += max([araz, braz])
	print(otv)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	s = 0
	min_c = min(candies)
	min_o = min(oranges)
	for i in range(n):
		s += max(abs(min_c - candies[i]), abs(min_o - oranges[i]))
	print(s)


for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ma = min(a)
	mb = min(b)
	count = 0
	for i in range(n):
		count = count + (a[i] - ma) + (b[i] - mb)
	for i in range(n):
		if a[i] != ma and b[i] != mb:
			m = min(a[i] - ma, b[i] - mb)
			count = count - m
	print(count)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	(a, b) = (min(candy), min(orange))
	ans = 0
	for w in range(n):
		(c, d) = (candy[w] - a, orange[w] - b)
		(c, d) = (min(c, d), max(c, d))
		ans += c
		d -= c
		ans += d
	print(ans)


a = int(input())
for i in range(a):
	t = int(input())
	ar = list(map(int, input().split()))
	ar1 = list(map(int, input().split()))
	m1 = min(ar)
	m2 = min(ar1)
	c = 0
	for i in range(t):
		c = c + max(ar[i] - m1, ar1[i] - m2)
	print(c)


from sys import stdin

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

def r_t(tp):
	return map(tp, r().strip().split())

def r_l(tp):
	return list(r_t(tp))

def solve(A, B, n):
	(tar_a, tar_b, ans) = (min(A), min(B), 0)
	for i in range(n):
		a = A[i] - tar_a
		b = B[i] - tar_b
		ans += min(a, b)
		ans += max(a, b) - min(a, b)
	return ans

def main():
	c = int(r())
	for _ in range(c):
		n = int(r())
		A = r_l(int)
		B = r_l(int)
		print(solve(A, B, n))
main()


import sys
input = sys.stdin.readline
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	ma = min(a)
	mb = min(b)
	for i in range(n):
		da = a[i] - ma
		db = b[i] - mb
		if da and db:
			c += max(da, db)
		else:
			c += da + db
	print(c)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(b)
	m = min(a)
	ans = 0
	for i in range(n):
		w = b[i] - m1
		w1 = a[i] - m
		ans += w + w1 - min(w, w1)
	print(ans)


t = int(input())
sol = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	steps = 0
	for j in range(n):
		steps += max(a[j] - min_a, b[j] - min_b)
	sol.append(steps)
for x in sol:
	print(x)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	kolvo = 0
	amin = min(a)
	bmin = min(b)
	for i in range(n):
		if a[i] > amin and b[i] > bmin:
			kolvo += min(a[i] - amin, b[i] - bmin)
			if min(a[i] - amin, b[i] - bmin) == a[i] - amin:
				b[i] -= a[i] - amin
				kolvo += b[i] - bmin
			else:
				a[i] -= b[i] - bmin
				kolvo += a[i] - amin
		else:
			if a[i] > amin:
				kolvo += a[i] - amin
			if b[i] > bmin:
				kolvo += b[i] - bmin
	print(kolvo)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(n):
		temp_a = a[i] - min_a
		temp_b = b[i] - min_b
		count += max(temp_a, temp_b)
	print(count)


t = int(input())
for g in range(t):
	n = int(input())
	cand = list(map(int, input().split()))
	org = list(map(int, input().split()))
	min_c = min(cand)
	min_o = min(org)
	ans = 0
	for i in range(n):
		a = cand[i] - min_c
		b = org[i] - min_o
		ans += max(a, b)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(am, bm) = (min(a), min(b))
	ans = 0
	for (ai, bi) in zip(a, b):
		x = min(ai - am, bi - bm)
		ans += x
		ans += max(ai - am, bi - bm) - x
	print(ans)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	ans = 0
	for i in range(n):
		l = a[i] - x
		m = b[i] - y
		ans += min(l, m)
		ans += abs(l - m)
	print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().rstrip().split(' ')))
	B = list(map(int, input().rstrip().split(' ')))
	count = 0
	MinA = min(A)
	MinB = min(B)
	i = 0
	while i < n:
		if len(set(A)) == 1 and len(set(B)) == 1:
			print(count)
			break
		if A[i] == MinA and B[i] == MinB:
			i += 1
		elif A[i] > MinA and B[i] > MinB:
			x = min(A[i] - MinA, B[i] - MinB)
			A[i] -= x
			B[i] -= x
			count += x
		elif A[i] > MinA:
			count += A[i] - MinA
			A[i] -= A[i] - MinA
		elif B[i] > MinB:
			count += B[i] - MinB
			B[i] -= B[i] - MinB


def count_steps(a, b):
	min_a = min(a)
	min_b = min(b)
	return sum([max(cur_a - min_a, cur_b - min_b) for (cur_a, cur_b) in zip(a, b)])

def main():
	t = int(input())
	for _ in range(t):
		input()
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		print(count_steps(a, b))
main()


t = int(input())
for te in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	ct = 0
	for i in range(n):
		ct += max(a[i] - amin, b[i] - bmin)
	print(ct)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	aa = [i - am for i in a]
	bb = [i - bm for i in b]
	p = []
	for i in range(n):
		p.append(max(aa[i], bb[i]))
	print(sum(p))


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
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')
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	ans = 0
	ma = min(a)
	mb = min(b)
	for j in range(n):
		x = 0
		y = 0
		if a[j] > ma:
			x = a[j] - ma
		if b[j] > mb:
			y = b[j] - mb
		ans += max(x, y)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	ans = 0
	for (x, y) in zip(a, b):
		ans += max(x - ma, y - mb)
	print(ans)


import copy
import math
r = int(input())
for l in range(r):
	n = int(input())
	arr1 = [int(d) for d in input().split()]
	arr2 = [int(d) for d in input().split()]
	(m1, m2) = (min(arr1), min(arr2))
	s = 0
	for i in range(n):
		s += min(arr1[i] - m1, arr2[i] - m2) + math.fabs(arr1[i] - m1 - arr2[i] + m2)
	print(int(s))


t = int(input())
for T in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	x = min(a)
	y = min(b)
	m = 0
	s = min(x, y)
	for i in range(n):
		(p, q, r) = (0, 0, 0)
		if a[i] - x == b[i] - y:
			m += a[i] - x
		else:
			m += max(a[i] - x, b[i] - y)
	print(m)


for t in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	(ma, mb) = (min(a), min(b))
	op = 0
	for (ea, eb) in zip(a, b):
		(da, db) = (ea - ma, eb - mb)
		op += max(da, db)
	print(op)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = min(a)
	e = min(b)
	count = 0
	for i in range(n):
		if a[i] == d and b[i] == e:
			count += 0
		elif a[i] == d and b[i] != e:
			count += b[i] - e
		elif a[i] != d and b[i] == e:
			count += a[i] - d
		else:
			q = max(a[i] - d, b[i] - e)
			count += q
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	ans = [0] * n
	for i in range(n):
		ans[i] = min(a[i] - x, b[i] - y) + abs(a[i] - x - b[i] + y)
	print(sum(ans))


t = int(input())
for i in range(t):
	n = int(input())
	cand = input()
	cand = cand.split(' ')
	cand = [int(x) for x in cand]
	orang = input()
	orang = orang.split(' ')
	orang = [int(x) for x in orang]
	mCand = min(cand)
	mOrang = min(orang)
	newCand = []
	newOrang = []
	for j in range(n):
		newCand.append(cand[j] - mCand)
	for j in range(n):
		newOrang.append(orang[j] - mOrang)
	ans = 0
	for i in range(n):
		ans += max(newCand[i], newOrang[i])
	print(ans)


import sys
from functools import lru_cache
from collections import defaultdict

def solve(arr1, arr2):
	min_c = min(arr1)
	min_o = min(arr2)
	moves = 0
	for (c, o) in zip(arr1, arr2):
		if c == min_c and o == min_o:
			continue
		elif c == min_c:
			moves += o - min_o
		elif o == min_o:
			moves += c - min_c
		else:
			d1 = o - min_o
			d2 = c - min_c
			if d1 == d2:
				moves += d1
			elif d1 > d2:
				moves += d1
			else:
				moves += d2
	return moves

def main(mat):
	for (a1, a2) in mat:
		print(solve(a1, a2))
mat = []
parse = 2
curr = []
for (e, line) in enumerate(sys.stdin.readlines()):
	if e == 0:
		continue
	elif e == 1:
		continue
	if parse > 0:
		curr.append(list(map(int, line.strip().split())))
		parse -= 1
	else:
		mat.append(curr)
		curr = []
		parse = 2
if curr:
	mat.append(curr)
main(mat)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	if n == 1:
		print('0')
		continue
	mina = min(a)
	minb = min(b)
	minval = mina + minb
	for j in range(n):
		if a[j] == mina and b[j] == minb and (a[j] + b[j] == minval):
			count += 0
		elif a[j] != mina or b[j] != minb:
			count += max(a[j] - mina, b[j] - minb)
	print(count)


t = int(input())
a = []
b = []
for i in range(t):
	count = 0
	n = int(input())
	a = list(map(int, input().split(' ')[:n]))
	b = list(map(int, input().split(' ')[:n]))
	aMin = min(a)
	bMin = min(b)
	for i in range(n):
		aDiff = a[i] - aMin
		bDiff = b[i] - bMin
		c = min(aDiff, bDiff)
		count += c + (aDiff - c) + (bDiff - c)
	print(count)


def main():
	for _ in range(int(input())):
		input()
		(aa, bb) = (list(map(int, input().split())) for _ in 'ab')
		(am, bm, r) = (min(aa), min(bb), 0)
		print(sum((max(a - am, b - bm) for (a, b) in zip(aa, bb))))
	print()
main()


t = int(input())
for i in range(t):
	cm = 0
	am = 0
	bm = 0
	ans = 0
	n = int(input())
	a = list(map(int, input().split(' ', n)))
	b = list(map(int, input().split(' ', n)))
	amin = int(min(a))
	bmin = int(min(b))
	for j in range(n):
		cm = 0
		am = 0
		bm = 0
		if a[j] > amin and b[j] > bmin:
			cm += min(a[j] - amin, b[j] - bmin)
		if a[j] > amin:
			am += a[j] - amin
		if b[j] > bmin:
			bm += b[j] - bmin
		ans += cm + abs(bm - am)
	print(ans)


from collections import Counter, defaultdict as dft

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

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

def solve():
	n = int(input())
	a = ml()
	b = ml()
	cost = 0
	mn1 = min(a)
	mn2 = min(b)
	for i in range(n):
		if a[i] == mn1 and b[i] == mn2:
			continue
		else:
			x = a[i] - mn1
			y = b[i] - mn2
			cost += min(x, y)
			cost += x + y - 2 * min(x, y)
	print(cost)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = map(int, input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(len(a)):
		if a[i] == min_a or b[i] == min_b:
			continue
		if a[i] - min_a > b[i] - min_b:
			a[i] -= b[i] - min_b
			count += b[i] - min_b
			b[i] -= b[i] - min_b
		else:
			b[i] -= a[i] - min_a
			count += a[i] - min_a
			a[i] -= a[i] - min_a
	for i in range(len(a)):
		count += a[i] - min_a
		count += b[i] - min_b
	print(count)


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

	def gift(a, b, n):
		k = min(a)
		m = min(b)
		sum = 0
		for i in range(n):
			sum += max(a[i] - k, b[i] - m)
		return sum
	print(gift(a, b, n))


t = int(input())
for i in range(0, t):
	n = int(input())
	c = [] * n
	o = [] * n
	c = [int(j) for j in input().split()]
	sort_c = sorted(c)
	x = sort_c[0]
	o = [int(j) for j in input().split()]
	sort_o = sorted(o)
	y = sort_o[0]
	s = 0
	for j in range(0, n):
		r = c[j] - x
		q = o[j] - y
		if r < q:
			s = s + q
		else:
			s = s + r
	print(s)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

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 [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	c = l()
	o = l()
	(mc, mo) = (min(c), min(o))
	answer = 0
	for i in range(n):
		(a, b) = (c[i] - mc, o[i] - mo)
		answer += max(a, b)
	out(answer)


inp = int(input())
for num in range(inp):
	counter = 0
	inp0 = int(input())
	inp1 = list(map(int, input().split()))
	inp2 = list(map(int, input().split()))
	min_inp1 = min(inp1)
	min_inp2 = min(inp2)
	index1 = inp1.index(min_inp1)
	index2 = inp2.index(min_inp2)
	counter += abs(inp1[index2] - min_inp1)
	counter += abs(inp2[index1] - min_inp2)
	for x in range(inp0):
		if x == index2 or x == index1:
			continue
		elif inp1[x] - min_inp1 > inp2[x] - min_inp2:
			counter += inp1[x] - min_inp1
		else:
			counter += inp2[x] - min_inp2
	print(counter)


def giftsFixing(arr1, arr2):
	c = 0
	for i in range(len(arr1)):
		minarr1 = min(arr1)
		minarr2 = min(arr2)
		c += max(arr1[i] - minarr1, arr2[i] - minarr2)
	return c
t = int(input())
for i in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	print(giftsFixing(arr1, arr2))


from sys import stdin, stdout
import math
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))

def chars():
	s = cin()
	return list(s[:len(s) - 1])

def pl(a):
	for val in a:
		cout(str(val) + ' ')
	cout('\n')
(t,) = mp()
for _ in range(t):
	(n,) = mp()
	a = mp()
	b = mp()
	candy = min(a)
	orange = min(b)
	l1 = []
	l2 = []
	for val in a:
		l1 += [val - candy]
	for val in b:
		l2 += [val - orange]
	ans = 0
	for i in range(n):
		ans += max(l1[i], l2[i])
	cout(str(ans) + '\n')


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()
	mna = min(a)
	mnb = min(b)
	(da, db) = ([], [])
	for i in range(n):
		da.append(a[i] - mna)
		db.append(b[i] - mnb)
	ans = 0
	for i in range(n):
		ans += max(da[i], db[i])
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = 0
	for j in range(n):
		x = a[j] - mina
		y = b[j] - minb
		if x < y:
			ans += y
		else:
			ans += x
	print(ans)


for _ in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	d = min(b)
	t = 0
	for i in range(0, n):
		if a[i] > c and b[i] > d:
			k = min(a[i] - c, b[i] - d)
			t += k
			if k == a[i] - c:
				a[i] = c
				b[i] -= k
			elif k == b[i] - d:
				b[i] = d
				a[i] -= k
		if a[i] > c and b[i] == d:
			t += a[i] - c
		if a[i] == c and b[i] > d:
			t += b[i] - d
	print(t)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	ans = 0
	for p in zip(a, b):
		ans += max(p[0] - ma, p[1] - mb)
	print(ans)


t = int(input())
for i in range(t):
	(n, z) = (int(input()), 0)
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(q, w) = (min(a), min(b))
	for i in range(n):
		e = min(a[i] - q, b[i] - w)
		z += a[i] - e + b[i] - q - w
	print(z)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = min(a)
	s = min(b)
	m = 0
	i = 0
	for i in range(0, n):
		d = abs(a[i] - k)
		e = abs(b[i] - s)
		q = max(d, e)
		m += q
		i += 1
	print(m)


for _ in range(int(input())):
	x = int(input())
	a = [int(t) for t in input().split()]
	b = [int(t) for t in input().split()]
	min_a = min(a)
	min_b = min(b)
	total = 0
	for (a_i, b_i) in zip(a, b):
		diff_a = a_i - min_a
		diff_b = b_i - min_b
		total += max(diff_a, diff_b)
	print(total)


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_min = min(a)
		b_min = min(b)
		count = 0
		for i in range(n):
			count += max(a[i] - a_min, b[i] - b_min)
		print(count)
main()


import sys, os
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
I = lambda : int(input())

def cal(l):
	if len(set(l)) > 1:
		m = min(l)
		s = 0
		for i in l:
			s += i - m
		return s
	else:
		return 0
for _ in range(I()):
	n = I()
	a = li()
	b = li()
	ma = min(a)
	mb = min(b)
	m = min(ma, mb)
	moves = 0
	for i in range(n):
		temp = min(a[i] - ma, b[i] - mb)
		a[i] -= temp
		b[i] -= temp
		moves += temp
	print(moves + cal(a) + cal(b))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	ans = 0
	for (i, j) in zip(a, b):
		if i > ma and j > mb:
			x = min(i - ma, j - mb)
			i -= x
			j -= x
			ans += x + (i - ma) + (j - mb)
		elif i > ma:
			ans += i - ma
		elif j > mb:
			ans += j - mb
	print(ans)


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	a1 = min(a)
	b1 = min(b)
	res = 0
	for i in range(0, n, 1):
		if a[i] != a1 and b[i] != b1:
			x1 = a[i] - a1
			x2 = b[i] - b1
			r = min(x1, x2)
			a[i] = a[i] - r
			b[i] = b[i] - r
			res += r
	for i in range(0, n, 1):
		if a[i] != a1:
			res += a[i] - a1
		if b[i] != b1:
			res += b[i] - b1
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	x = min(a)
	y = min(b)
	ans = 0
	for i in range(n):
		p = a[i] - x
		q = b[i] - y
		ans += p + q - min(p, q)
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	candies = list(map(int, input().strip().split()))
	oranges = list(map(int, input().strip().split()))
	cmin = min(candies)
	omin = min(oranges)
	count = 0
	for i in range(n):
		cdiff = candies[i] - cmin
		odiff = oranges[i] - omin
		mini = min(cdiff, odiff)
		if mini == cdiff:
			count += cdiff
			count += odiff - cdiff
		else:
			count += odiff
			count += cdiff - odiff
	print(count)


for i in range(int(input())):
	n = int(input())
	c = 0
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m = min(l1)
	mn = min(l2)
	for i in range(n):
		if l1[i] - m > l2[i] - mn:
			c += l1[i] - m
		else:
			c += l2[i] - mn
	print(c)


t = int(input())
for q in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		t1 = 0
		t2 = 0
		if a[i] > ma:
			t1 = a[i] - ma
		if b[i] > mb:
			t2 = b[i] - mb
		c += max(t1, t2)
	print(c)


import sys
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()]
	(x, y, ans) = (min(A), min(B), 0)
	for i in range(0, n):
		(a, b) = (A[i] - x, B[i] - y)
		ans += max(a, b)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	ans = 0
	min1 = min(l1)
	min2 = min(l2)
	for j in range(n):
		l1[j] = l1[j] - min1
		l2[j] = l2[j] - min2
	for j in range(n):
		ans = ans + max(l1[j], l2[j])
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = min(l1)
	m2 = min(l2)
	s = 0
	for i in range(n):
		s += max(l1[i] - m1, l2[i] - m2)
	print(s)


def ans(A, B):
	ma = min(A)
	mb = min(B)
	ret = 0
	for (a, b) in zip(A, B):
		ret += max(a - ma, b - mb)
	return ret
T = int(input())
for t in range(T):
	input()
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	print(ans(A, B))


import sys

def main():
	t = int(sys.stdin.readline().strip())
	for tc in range(t):
		n = int(sys.stdin.readline().strip())
		A = [int(a) for a in sys.stdin.readline().strip().split()]
		B = [int(b) for b in sys.stdin.readline().strip().split()]
		minA = min(A)
		minB = min(B)
		res = 0
		for i in range(n):
			dA = A[i] - minA
			dB = B[i] - minB
			res += min(dA, dB) + abs(dA - dB)
		sys.stdout.write(str(res) + '\n')
main()


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

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

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 mod():
	return 10 ** 9 + 7
for i in range(INT()):
	n = INT()
	a1 = LIST()
	a2 = LIST()
	m1 = 10 ** 10
	m2 = 10 ** 10
	for i in a1:
		m1 = min(m1, i)
	for i in a2:
		m2 = min(m2, i)
	ans = 0
	for i in range(n):
		if a1[i] > m1 and a2[i] > m2:
			ans += max(a1[i] - m1, a2[i] - m2)
		elif a1[i] > m1:
			ans += a1[i] - m1
		elif a2[i] > m2:
			ans += a2[i] - m2
	print(ans)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	c = 0
	for i in range(0, n):
		c += max(abs(am - a[i]), abs(bm - b[i]))
	print(c)


def findMin(listX):
	minimum = listX[0]
	for x in range(1, len(listX)):
		minimum = min(minimum, listX[x])
	return minimum
cases = int(input())
for x in range(cases):
	input()
	aStr = input().split(' ')
	bStr = input().split(' ')
	a = list((int(x) for x in aStr))
	b = list((int(x) for x in bStr))
	aMin = findMin(a)
	bMin = findMin(b)
	moves = 0
	for x in range(len(a)):
		a[x] = a[x] - aMin
		b[x] = b[x] - bMin
		moves += max(a[x], b[x])
	print(moves)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = 0
	i = 0
	while i < n:
		if a[i] == ma and b[i] != mb:
			c += b[i] - mb
		elif a[i] != ma and b[i] == mb:
			c += a[i] - ma
		elif a[i] != ma and b[i] != mb:
			c += max(a[i] - ma, b[i] - mb)
		i += 1
	print(c)
	t -= 1


try:
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		min_can = min(a)
		min_or = min(b)
		moves = 0
		for i in range(len(a)):
			l = a[i] - min_can
			r = b[i] - min_or
			if l == r:
				moves += l
				continue
			else:
				moves += max(l, r)
		print(moves)
except:
	pass


from sys import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	da = [0] * n
	b = list(map(int, input().split()))
	db = [0] * n
	mna = min(a)
	mnb = min(b)
	for i in range(n):
		da[i] = a[i] - mna
		db[i] = b[i] - mnb
	sn = 0
	for i in range(n):
		sn += max(da[i], db[i])
	stdout.write(str(sn) + '\n')


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	x = min(arr)
	y = min(brr)
	ans = 0
	for i in range(n):
		a = arr[i] - x
		b = brr[i] - y
		ans += max(a, b)
	print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

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

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

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

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

def sep():
	return map(int, inp().split())

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

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def solve():
	n = int(inp())
	a = lis()
	b = lis()
	am = min(a)
	bm = min(b)
	s = 0
	for i in range(n):
		k1 = a[i] - am
		k2 = b[i] - bm
		s += max(k1, k2)
	print(s)
testcase(int(inp()))


t = int(input())
for r in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	p = min(a)
	x = a.index(p)
	q = min(b)
	y = b.index(q)
	for i in range(n):
		if a[i] > p and b[i] > q:
			c += max(a[i] - p, b[i] - q)
		elif a[i] > p:
			c += a[i] - p
		elif b[i] > q:
			c += b[i] - q
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		op_a = a[i] - min_a
		op_b = b[i] - min_b
		ans += max(op_a, op_b)
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	b = list(map(int, input().strip().split(' ')))
	ma = max(a)
	mia = min(a)
	mb = max(b)
	mib = min(b)
	cnt = 0
	for i in range(0, n):
		if a[i] > mia and b[i] > mib:
			p = a[i] - mia
			q = b[i] - mib
			if p > q:
				cnt += p
			else:
				cnt += q
		else:
			if a[i] > mia:
				cnt += a[i] - mia
			if b[i] > mib:
				cnt += b[i] - mib
	print(cnt)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	a_min = min(a)
	b_min = min(b)
	a_moves = [a[i] - a_min for i in range(n)]
	b_moves = [b[i] - b_min for i in range(n)]
	res = 0
	for j in range(n):
		res += max(a_moves[j], b_moves[j])
	print(res)


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	min_candy = min(arr1)
	min_orange = min(arr2)
	op = 0
	for (a, b) in zip(arr1, arr2):
		change_candy = a - min_candy
		change_orange = b - min_orange
		op += max(change_candy, change_orange)
	print(op)


test_case = int(input())
for i in range(test_case):
	count = 0
	length = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	for i in range(length):
		if min(a) == a[i] and min(b) == b[i]:
			continue
		elif abs(a[i] - min(a)) < abs(b[i] - min(b)):
			count += abs(b[i] - min(b))
		else:
			count += abs(a[i] - min(a))
	print(count)


for t in range(int(input())):
	n = int(input())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	ma = min(la)
	mb = min(lb)
	count = 0
	for i in range(n):
		if la[i] != ma and lb[i] != mb:
			a1 = la[i] - ma
			b1 = lb[i] - mb
			la[i] -= min(a1, b1)
			lb[i] -= min(a1, b1)
			count += min(a1, b1)
		if la[i] == ma and lb[i] != mb:
			count += lb[i] - mb
			lb[i] = mb
		elif la[i] != ma and lb[i] == mb:
			count += la[i] - ma
			la[i] = ma
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dp = [[0 for i in range(n)] for j in range(2)]
	for i in range(2):
		for j in range(n):
			if i == 0:
				x = min(a)
				if j == 0:
					dp[i][j] = abs(x - a[j])
				else:
					dp[i][j] = abs(x - a[j])
			else:
				y = min(b)
				if j == 0:
					dp[i][j] = max(dp[i - 1][j], abs(y - b[j]))
				else:
					dp[i][j] = dp[i][j - 1] + max(dp[i - 1][j], abs(y - b[j]))
	print(dp[-1][-1])


for i in range(int(input())):
	input()
	s1 = [int(i) for i in input().split()]
	s2 = [int(i) for i in input().split()]
	a = min(s1)
	b = min(s2)
	s1a = [i - a for i in s1]
	s2a = [i - b for i in s2]
	print(sum([max(s1a[x], s2a[x]) for x in range(len(s1))]))


t = int(input())
for i in range(t):
	n = int(input())
	c = [int(i) for i in input().split()]
	o = [int(i) for i in input().split()]
	minc = min(c)
	mino = min(o)
	count = 0
	for i in range(n):
		if c[i] > minc or o[i] > mino:
			cc = c[i] - minc
			co = o[i] - mino
			if cc > co:
				count += cc
			else:
				count += co
	print(count)


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(' ')]
	print(sum([max(c - min(a), d - min(b)) for (c, d) in zip(a, b)]))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ai = min(a)
	bi = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - ai, b[i] - bi)
	print(ans)


def hod():
	n = int(input())
	konfet = [int(a) for a in input().split()]
	apelsin = [int(a) for a in input().split()]
	mink = min(konfet)
	mina = min(apelsin)
	h = 0
	for i in range(n):
		k1 = konfet[i]
		a1 = apelsin[i]
		h += max(k1 - mink, a1 - mina)
	print(h)
for i in range(int(input())):
	hod()


n = int(input())
for _ in range(n):
	t = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	min1 = min(arr)
	min2 = min(brr)
	ans = 0
	for i in range(t):
		a = arr[i] - min1
		b = brr[i] - min2
		m = min(a, b)
		ans += m + a - m + b - m
	print(ans)


t = int(input())
for T in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	count = 0
	for i in range(n):
		count += max(a[i] - amin, b[i] - bmin)
	print(count)


import sys
input = sys.stdin.readline
t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	ans = 0
	for i in range(n):
		mn = min(a[i] - ma, b[i] - mb)
		a[i] = a[i] - mn
		b[i] = b[i] - mn
		ans += mn + (a[i] - ma) + (b[i] - mb)
	print(ans)


def get_answer(a, b, n):
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(n):
		if a[i] == min_a and b[i] == min_b:
			continue
		elif a[i] > min_a and b[i] == min_b:
			count += a[i] - min_a
		elif a[i] == min_a and b[i] > min_b:
			count += b[i] - min_b
		else:
			count += max(a[i] - min_a, b[i] - min_b)
	return count
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(get_answer(a, b, n))


t = int(input())
for case in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	amin = min(a)
	bmin = min(b)
	adiff = [i - amin for i in a]
	bdiff = [i - bmin for i in b]
	moves = sum([max(i, j) for (i, j) in zip(adiff, bdiff)])
	print(moves)


for i in range(int(input())):
	n = int(input())
	louda = list(map(int, input().split()))
	maad = list(map(int, input().split()))
	minl = min(louda)
	minm = min(maad)
	c = 0
	for (i, j) in zip(range(n), range(n)):
		c += max(louda[i] - minl, maad[j] - minm)
	print(c)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		opa = a[i] - amin
		opb = b[i] - bmin
		ans += max(opa, opb)
	print(ans)


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

def solve():
	n = I()
	a = li()
	b = li()
	p = min(a)
	q = min(b)
	s = 0
	for i in range(n):
		temp = max(a[i] - p, b[i] - q)
		s += temp
	print(s)
for _ in range(I()):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	Aminimum = min(a)
	Bminimum = min(b)
	ans = 0
	for i in range(0, n):
		difA = a[i] - Aminimum
		difB = b[i] - Bminimum
		ans += difA if difA > difB else difB
	print(ans)


def sol(c, o):
	mc = min(c)
	ec = [0] * len(c)
	for i in range(len(c)):
		ec[i] = c[i] - mc
	mo = min(o)
	eo = [0] * len(o)
	for i in range(len(o)):
		eo[i] = o[i] - mo
	moves = 0
	for i in range(len(ec)):
		moves += max(ec[i], eo[i])
	return moves
cases = input()
for i in range(int(cases)):
	input()
	c = [int(x) for x in input().split()]
	o = [int(x) for x in input().split()]
	print(sol(c, o))


import re
t = int(input())
for i in range(t):
	n = input()
	a = list(map(int, input('').strip().split()))
	b = list(map(int, input('').strip().split()))
	x = min(a)
	y = min(b)
	count = 0
	for j in range(len(a)):
		if a[j] > x and b[j] > y:
			if a[j] - x >= b[j] - y:
				count += b[j] - y + a[j] - b[j] - x + y
			elif b[j] - y > a[j] - x:
				count += a[j] - x + b[j] - a[j] + x - y
		elif a[j] > x:
			count += a[j] - x
		elif b[j] > y:
			count += b[j] - y
	print(count)


import sys
reader = (s.rstrip() for s 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()))
	mnA = min(A)
	mnB = min(B)
	ans = 0
	for i in range(n):
		eatA = A[i] - mnA
		eatB = B[i] - mnB
		ans += max(eatA, eatB)
	print(ans)


test_case = int(input())
output = []
for i in range(test_case):
	gifts = int(input())
	candies = [int(i) for i in input().split(' ')]
	oranges = [int(i) for i in input().split(' ')]
	output_moves = [0] * gifts
	excludeindex_cn = candies.index(min(candies))
	for i in range(len(candies)):
		if i == excludeindex_cn:
			pass
		else:
			output_moves[i] = candies[i] - candies[excludeindex_cn]
	excludeindex_og = oranges.index(min(oranges))
	for i in range(len(oranges)):
		if i == excludeindex_og:
			pass
		elif output_moves[i] < oranges[i] - oranges[excludeindex_og]:
			output_moves[i] = oranges[i] - oranges[excludeindex_og]
	output.append(sum(output_moves))
for i in output:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	A = input().split()
	a = list(map(int, A))
	B = input().split()
	b = list(map(int, B))
	c = []
	for i in range(n):
		k = a[i] - min(a)
		l = b[i] - min(b)
		s = {k, l}
		j = max(s)
		c.append(j)
	r = sum(c)
	print(r)


import math
T = int(input())
for i in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = False
	am = min(a)
	bm = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - am, b[i] - bm)
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	min1 = min(l1)
	min2 = min(l2)
	ans = 0
	for i in range(n):
		k = abs(min1 - l1[i])
		j = abs(min2 - l2[i])
		if k != 0 and j != 0:
			if k == j:
				ans += k
			elif k < j:
				ans += j
			else:
				ans += k
		elif k == 0:
			ans += j
		else:
			ans += k
	print(ans)


t = int(input())
num = [0, 1, 3, 6, 10]
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	r = 0
	for i in range(n):
		r += max(a[i] - mina, b[i] - minb)
	print(r)
	t -= 1


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	c = min(candy)
	o = min(orange)
	a1 = []
	for i in range(n):
		a1.append(candy[i] - c)
	a2 = []
	for i in range(n):
		a2.append(orange[i] - o)
	res = []
	for i in range(n):
		res.append(max(a1[i], a2[i]))
	print(sum(res))


def devi(a, b, n):
	a_last = min(a)
	b_last = min(b)
	a = [i - a_last for i in a]
	b = [i - b_last for i in b]
	count = 0
	for i in range(n):
		if a[i] == b[i]:
			count += a[i]
		else:
			count = count + min(a[i], b[i]) + abs(a[i] - b[i])
	return count
t = int(input())
ans_list = []
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans_list.append(devi(a, b, n))
[print(i) for i in ans_list]


from sys import stdin
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
from collections import deque
(t,) = gil()
for _ in range(t):
	(n,) = gil()
	a = gil()
	b = gil()
	(A, B) = (min(a), min(b))
	moves = 0
	for i in range(n):
		moves += max(a[i] - A, b[i] - B)
	print(moves)


t = int(input())
for tests in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	a_min = min(arr)
	b_min = min(brr)
	result = 0
	for i in range(n):
		result += max(arr[i] - a_min, brr[i] - b_min)
	print(result)


for i in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	(m, p) = (min(arr1), min(arr2))
	count = 0
	for j in range(n):
		(c, d) = (arr1[j] - m, arr2[j] - p)
		count += min(c, d) + abs(c - d)
	print(count)


t = int(input())
while t:
	t -= 1
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_c = min(candies)
	min_o = min(oranges)
	count = 0
	for i in range(n):
		if candies[i] - min_c > oranges[i] - min_o:
			count += candies[i] - min_c
		else:
			count += oranges[i] - min_o
	print(count)


import sys
read = sys.stdin.readline
for _ in range(int(read())):
	length = int(read())
	candies = list(map(int, read().split()))
	oranges = list(map(int, read().split()))
	min_c = min(candies)
	min_o = min(oranges)
	steps = 0
	for i in range(length):
		a = candies[i] - min_c
		b = oranges[i] - min_o
		d = min(a, b)
		steps += a + b - d
	print(steps)


t = int(input())
while t > 0:
	n = int(input())
	arr1 = input().split()
	arr2 = input().split()
	arr1 = [int(i) for i in arr1]
	arr2 = [int(i) for i in arr2]
	c = 0
	for i in range(n):
		c += max(arr1[i] - min(arr1), arr2[i] - min(arr2))
	print(c)
	t -= 1


t = int(input())
while t:
	t += -1
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = min(l1)
	m2 = min(l2)
	t1 = [0] * n
	t2 = [0] * n
	ans = 0
	for i in range(n):
		t1[i] = l1[i] - m1
		t2[i] = l2[i] - m2
		tmp1 = min(t1[i], t2[i])
		tmp2 = max(t1[i], t2[i])
		tmp2 -= tmp1
		ans += tmp1 + tmp2
	print(ans)


(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, dgraphs, mod) = (lambda : sorted(zz()), {}, 10 ** 9 + 7)
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	n = int(z())
	l1 = zz()
	l2 = zz()
	p1 = min(l1)
	p2 = min(l2)
	ans = 0
	for (i, j) in zip(l1, l2):
		mx = max(i - p1, j - p2)
		mi = min(i - p1, j - p2)
		ans += mi
		ans += mx - mi
	print(ans)


def main():
	for _ in range(int(input())):
		en = int(input())
		aa = list((int(ex) for ex in input().split()))
		bb = list((int(ex) for ex in input().split()))
		am = min(aa)
		bm = min(bb)
		sea = 0
		for ai in range(en):
			sea += max(aa[ai] - am, bb[ai] - bm)
		print(sea)
main()


ls = []
t = int(input())
for z in range(t):
	temp = int(input())
	count = 0
	als = list(map(int, input().rstrip().split()))
	bls = list(map(int, input().rstrip().split()))
	a = min(als)
	b = min(bls)
	for i in range(temp):
		if als[i] > a and bls[i] > b:
			pl = min(als[i] - a, bls[i] - b)
			als[i] = als[i] - pl
			bls[i] = bls[i] - pl
			count += pl
		if als[i] > a:
			count += als[i] - a
		if bls[i] > b:
			count += bls[i] - b
	ls.append(count)
for i in ls:
	print(i)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = min(a)
	for i in range(len(a)):
		a[i] -= m
	m = min(b)
	for i in range(len(b)):
		b[i] -= m
	o = 0
	for i in range(n):
		o += max(a[i], b[i])
	print(o)


from sys import stdin, stdout
intn = lambda : int(stdin.readline())
strs = lambda : stdin.readline()[:-1]
lstr = lambda : list(stdin.readline()[:-1])
mint = lambda : map(int, stdin.readline().split())
lint = lambda : list(map(int, stdin.readline().split()))
out = lambda x: stdout.write(str(x) + '\n')
out_ = lambda x: stdout.write(str(x) + ' ')

def main():
	for _ in range(intn()):
		n = intn()
		a = lint()
		b = lint()
		(ma, mb) = (min(a), min(b))
		c = 0
		for i in range(n):
			if a[i] > ma:
				if b[i] > mb:
					c += max(a[i] - ma, b[i] - mb)
				else:
					c += a[i] - ma
			else:
				c += b[i] - mb
		out(c)
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	c = 0
	for i in range(n):
		if a[i] == x and b[i] == y:
			continue
		elif a[i] == x:
			c += b[i] - y
		elif b[i] == y:
			c += a[i] - x
		else:
			c += min(a[i] - x, b[i] - y) + abs(a[i] - x - b[i] + y)
	print(c)


t = int(input())

def li():
	return list(map(int, input().split()))
for i in range(t):
	n = int(input())
	ans = 0
	a = li()
	b = li()
	y = min(a)
	z = min(b)
	for i in range(n):
		ans += max(a[i] - y, b[i] - z)
	print(ans)


l = int(input())
for _ in range(l):
	_ = input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	moves = 0
	for i in range(len(a)):
		if a[i] > x and b[i] > y:
			if a[i] <= b[i]:
				z = a[i] - x
				moves += z
				a[i] -= z
				b[i] -= z
			elif b[i] < a[i]:
				z = b[i] - y
				moves += z
				b[i] -= z
				a[i] -= z
		if a[i] > x:
			moves += a[i] - x
		elif b[i] > y:
			moves += b[i] - y
	print(moves)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min1 = min(a)
	min2 = min(b)
	count = 0
	for i in range(n):
		count += max(a[i] - min1, b[i] - min2)
	print(count)


for _a in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(la, lb) = (min(a), min(b))
	count = 0
	for i in range(n):
		(tempa, tempb) = (a[i], b[i])
		if tempa > la and tempb > lb:
			d = min(tempa - la, tempb - lb)
			count += d
			tempa = tempa - d
			tempb = tempb - d
		if tempa > la:
			count += tempa - la
			tempa = la
		if tempb > lb:
			count += tempb - lb
			tempb = lb
	print(count)


t = int(input())
for _ in range(t):
	c = 0
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	amin = a.index(min(a))
	bmin = b.index(min(b))
	mina = min(a)
	minb = min(b)
	s = 0
	for i in range(n):
		c = a[i] - mina
		d = b[i] - minb
		if c > 0 and d > 0:
			s = s + min(c, d)
			if c - d > 0:
				s = s + (c - d)
			else:
				s = s + (d - c)
		elif c == 0 and d > 0:
			s = s + d
		elif c > 0 and d == 0:
			s = s + c
	print(s)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		amin = min(a)
		bmin = min(b)
		cnt = 0
		for i in range(n):
			d = min([a[i] - amin, b[i] - bmin])
			cnt += a[i] - amin + b[i] - bmin - d
		print(cnt)
main()


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	s = 0
	for i in range(n):
		p = a[i] - x
		q = b[i] - y
		s = s + max(p, q)
	print(s)
	t = t - 1


t = int(input())
while t > 0:
	gift_num = int(input())
	a = map(int, input().split())
	a = list(a)
	b = map(int, input().split())
	b = list(b)
	min_a = min(a)
	min_b = min(b)
	cont = 0
	for i in range(gift_num):
		if a[i] > min_a and b[i] > min_b:
			temp_a = a[i] - min_a
			temp_b = b[i] - min_b
			if temp_a == temp_b:
				a[i] -= temp_a
				b[i] -= temp_b
				cont += temp_b
			elif temp_a > temp_b:
				a[i] -= temp_b
				b[i] -= temp_b
				cont += temp_b
			elif temp_a < temp_b:
				a[i] -= temp_a
				b[i] -= temp_a
				cont += temp_a
		while a[i] > min_a or b[i] > min_b:
			if a[i] > min_a:
				temp = a[i] - min_a
				a[i] -= temp
				cont += temp
			elif b[i] > min_b:
				temp = b[i] - min_b
				b[i] -= temp
				cont += temp
	print(cont)
	t -= 1


def count(ca, ora, n):
	i = 0
	j = 0
	c = 0
	mc = min(ca)
	mo = min(ora)
	while i != n and j != n:
		if ca[i] != mc and ora[j] != mo:
			k = min(ca[i] - mc, ora[j] - mo)
			ca[i] -= k
			ora[j] -= k
			c += k
		elif ca[i] == mc and ora[j] != mo:
			k = ora[j] - mo
			ora[j] -= k
			c += k
		elif ca[i] != mc and ora[j] == mo:
			k = ca[i] - mc
			ca[i] -= k
			c += k
		elif ca[i] == mc and ora[j] == mo:
			i += 1
			j += 1
	return c
for _ in range(int(input())):
	n = int(input())
	ca = list(map(int, input().split()[:n]))
	ora = list(map(int, input().split()[:n]))
	print(count(ca, ora, n))


import sys
tests = int(sys.stdin.readline().split()[0])
for test in range(tests):
	n = int(sys.stdin.readline().split()[0])
	a = [int(i) for i in sys.stdin.readline().split()]
	b = [int(i) for i in sys.stdin.readline().split()]
	min_a = min(a)
	min_b = min(b)
	steps_a = 0
	steps_b = 0
	steps = 0
	i = 0
	while i < n:
		steps_a = a[i] - min_a
		steps_b = b[i] - min_b
		steps += max(steps_a, steps_b)
		i += 1
	print(steps)


for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	m = [int(i) for i in input().split()]
	a = min(l)
	b = min(m)
	c = 0
	while True:
		if sum(l) == a * n and sum(m) == b * n:
			break
		else:
			for i in range(n):
				x = l[i] - a
				y = m[i] - b
				if x == 0 or y == 0:
					if x > 0:
						z = x
						l[i] = l[i] - z
						c += z
					else:
						z = y
						m[i] = m[i] - z
						c += z
				else:
					z = min(x, y)
					l[i] = l[i] - z
					m[i] = m[i] - z
					c += z
	print(c)


t = int(input())
lst = []
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count2 = 0
	for i in range(n):
		count = 0
		x = a[i] - min(a)
		y = b[i] - min(b)
		count += min(x, y) + abs(x - y)
		count2 += count
	lst.append(count2)
for i in lst:
	print(i)


ll = lambda : list(map(int, input().split()))
st = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
from collections import *
from math import *
from datetime import datetime
from sys import stdin, stdout

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(ii()):
	s = ii()
	y = ll()
	l = ll()
	ded = len(set(y) & set(l))
	c = min(y)
	c1 = min(l)
	ans = 0
	for i in range(s):
		ans += max(abs(y[i] - c), abs(l[i] - c1))
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	min1 = min(a)
	min2 = min(b)
	moves = 0
	for i in range(n):
		x = a[i] - min1
		y = b[i] - min2
		moves = moves + min(x, y) + abs(x - y)
	print(moves)


count = int(input())
for i in range(count):
	с = input()
	arrA = list(map(int, input().split()))
	arrB = list(map(int, input().split()))
	arrADiff = [item - min(arrA) for item in arrA]
	arrBDiff = [item - min(arrB) for item in arrB]
	countFinal = 0
	for j in range(len(arrA)):
		countFinal += max(arrADiff[j], arrBDiff[j])
	print(countFinal)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	ans = 0
	for i in range(len(a)):
		if a[i] > m1 and b[i] > m2:
			c = min(a[i] - m1, b[i] - m2)
			ans += c
			a[i] -= c
			b[i] -= c
			ans += a[i] - m1
			ans += b[i] - m2
		elif a[i] > m1:
			ans += a[i] - m1
		elif b[i] > m2:
			ans += b[i] - m2
	print(ans)


from sys import stdin

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

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

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

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

def get_array2d(row):
	return [list(map(int, stdin.readline().strip().split())) for _ in range(row)]
T = get_int()
for _ in range(T):
	N = get_int()
	A = get_array()
	B = get_array()
	(minA, minB) = (min(A), min(B))
	minimunMoves = 0
	for i in range(N):
		minimunMoves += max(A[i] - minA, B[i] - minB)
	print(minimunMoves)


from sys import stdin, stdout
import math
from collections import defaultdict

def arrinp():
	return [*map(int, stdin.readline().split(' '))]

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

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

def inp():
	return stdin.readline()

def solution():
	n = intinp()
	a = arrinp()
	b = arrinp()
	aval = min(a)
	bval = min(b)
	i = 0
	moves = 0
	while i < n:
		if a[i] > aval and b[i] > bval:
			val = min(a[i] - aval, b[i] - bval)
			moves += val
			if a[i] == aval + val and b[i] == bval + val:
				i += 1
			elif a[i] == aval + val:
				moves += b[i] - bval - val
				i += 1
			elif b[i] == bval + val:
				moves += a[i] - aval - val
				i += 1
		elif a[i] > aval:
			moves += a[i] - aval
			i += 1
		elif b[i] > bval:
			moves += b[i] - bval
			i += 1
		else:
			i += 1
	return moves
testcases = 1
testcases = intinp()
for _ in range(testcases):
	print(solution())


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	a_min = min(a)
	b_min = min(b)
	a = [x - a_min for x in a]
	b = [y - b_min for y in b]
	moves = 0
	for i in range(n):
		moves += max(a[i], b[i])
	print(moves)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	for i in range(n):
		if a[i] > min(a) and b[i] > min(b):
			c += min(a[i] - min(a), b[i] - min(b))
			x = a[i] - min(a)
			y = b[i] - min(b)
			c += abs(x - y)
		if a[i] > min(a) and b[i] == min(b):
			c += a[i] - min(a)
			a[i] = min(a)
		if b[i] > min(b) and a[i] == min(a):
			c += b[i] - min(b)
			b[i] = min(b)
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	can = min(l1)
	org = min(l2)
	s1 = 0
	s2 = 0
	res = 0
	for i in range(n):
		s1 = l1[i] - can
		s2 = l2[i] - org
		res += min(s1, s2)
		l1[i] -= min(s1, s2)
		l2[i] -= min(s1, s2)
		res += l1[i] - can
		res += l2[i] - org
	print(res)


T = int(input())
for case in range(T):
	N = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	a_min = min(a)
	b_min = min(b)
	moves = 0
	for index in range(len(a)):
		a_index = a[index] - a_min
		b_index = b[index] - b_min
		combined_moves = min(a_index, b_index)
		individual_moves = max(a_index - combined_moves, b_index - combined_moves)
		moves += combined_moves + individual_moves
	print(moves)


try:
	t = int(input())
	for i in range(t):
		n = int(input())
		l = list(map(int, input().split()))
		l1 = list(map(int, input().split()))
		a = min(l)
		b = min(l1)
		ans = 0
		for i in range(n):
			a1 = l[i] - a
			b1 = l1[i] - b
			ans += max(a1, b1)
		print(ans)
except:
	pass


def calc(n, a, b):
	ans = 0
	min_a = min(a)
	min_b = min(b)
	for i in range(n):
		if a[i] > min_a or b[i] > min_b:
			(diff_a, diff_b) = (max(a[i] - min_a, 0), max(b[i] - min_b, 0))
			ans += diff_a + diff_b - min(diff_b, diff_a)
	return ans
for i in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	print(calc(n, a, b))


from sys import stdin, stdout

def input():
	return stdin.readline()

def prin(x):
	return stdout.write(str(x) + '\n')
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(k) for k in input().split()]
	b = [int(k) for k in input().split()]
	(x, y) = (min(a), min(b))
	ans = 0
	for i in range(n):
		(p, q) = (0, 0)
		if a[i] > x:
			p = a[i] - x
		if b[i] > y:
			q = b[i] - y
		ans += max(p, q)
	print(ans)


n = int(input())
s = 0
for i in range(n):
	m = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	(s1, s2) = (min(a), min(b))
	for i in range(m):
		s += max(a[i] - s1, b[i] - s2)
	print(s)
	s = 0


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	b = input().split()
	a = list(map(int, a))
	b = list(map(int, b))
	cnt = 0
	min_a = min(a)
	min_b = min(b)
	min_list = min(min_a, min_b)
	for i in range(n):
		if a[i] > min_a and b[i] > min_b:
			diff_a = a[i] - min_a
			diff_b = b[i] - min_b
			mini = min(diff_a, diff_b)
			cnt += mini
			cnt += abs(a[i] - mini - min_a)
			cnt += abs(b[i] - mini - min_b)
		elif a[i] > min_a:
			cnt += abs(a[i] - min_a)
		elif b[i] > min_b:
			cnt += abs(b[i] - min_b)
		else:
			continue
	print(cnt)


def gifts(A, B):
	n = len(A)
	count = 0
	a = min(A)
	b = min(B)
	for i in range(n):
		(excessA, excessB) = (0, 0)
		if A[i] != a:
			excessA = A[i] - a
		if B[i] != b:
			excessB = B[i] - b
		count += max(excessB, excessA)
	print(count)
t = int(input())
for i in range(t):
	n = int(input())
	A = [int(i) for i in input().split()][:n]
	B = [int(i) for i in input().split()][:n]
	gifts(A, B)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	x = min(a)
	y = min(b)
	z = 0
	for i in range(n):
		z += max(abs(x - a[i]), abs(y - b[i]))
	print(z)


l = []
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	minc = c[0]
	ic = 0
	mino = o[0]
	io = 0
	for i in range(n):
		if mino > o[i]:
			io = i
			mino = o[i]
		if minc > c[i]:
			ic = i
			minc = c[i]
	for i in range(n):
		c[i] = c[i] - minc
		o[i] = o[i] - mino
	sum = 0
	for i in range(n):
		sum = sum + max(o[i], c[i])
	l.append(sum)
for i in l:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m_a = min(a)
	m_b = min(b)
	min_ab = min(m_a, m_b)
	ans = 0
	for i in range(n):
		if a[i] > m_a and b[i] > m_b:
			m_pary = min(a[i], b[i])
			ans += m_pary - min_ab
			a[i] -= m_pary - min_ab
			b[i] -= m_pary - min_ab
		if a[i] > m_a:
			ans += a[i] - m_a
		if b[i] > m_b:
			ans += b[i] - m_b
	print(ans)


for i in [0] * int(input()):
	total = 0
	a = int(input())
	l = list(map(int, input().split()))
	lmin = min(l)
	l1 = list(map(int, input().split()))
	l1min = min(l1)
	for x in range(a):
		l[x] -= lmin
		l1[x] -= l1min
	for x in range(a):
		if l[x] == 0:
			p = x
		if l1[x] == 0:
			az = x
	for x in range(a):
		if x != p and x != az:
			if l[x] > l1[x]:
				total += l[x]
			else:
				total += l1[x]
		else:
			total += l1[x]
			total += l[x]
	print(total)


def solve():
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	a = min(A)
	b = min(B)
	m = 0
	for i in range(n):
		if A[i] > a and B[i] > b:
			m = m + min(A[i] - a, B[i] - b)
			m = m + max(A[i] - a, B[i] - b) - min(A[i] - a, B[i] - b)
		elif A[i] > a:
			m = m + A[i] - a
		elif B[i] > b:
			m = m + B[i] - b
	return m
t = int(input())
for l in range(t):
	print(solve())


t = int(input())
for i in range(t):
	n = int(input())
	ch1 = input()
	ch2 = input()
	L1 = [int(j) for j in ch1.split()]
	L2 = [int(j) for j in ch2.split()]
	ma = min(L1)
	mb = min(L2)
	move = -(ma + mb) * n
	for k in range(n):
		move += L1[k] + L2[k] - min(L1[k] - ma, L2[k] - mb)
	print(move)


def process(n):
	mina = 1000000000.0 + 7
	minb = 1000000000.0 + 7
	sum = 0
	for i in range(0, n):
		mina = min(mina, a[i])
		minb = min(minb, b[i])
	for i in range(0, n):
		if a[i] == mina and b[i] != minb:
			sum += b[i] - minb
		elif a[i] != mina and b[i] == minb:
			sum += a[i] - mina
		elif a[i] != mina and b[i] != minb:
			if a[i] - mina >= b[i] - minb:
				sum += a[i] - mina
			else:
				sum += b[i] - minb
	print(sum)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	process(n)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	s = 0
	for (i, j) in zip(a, b):
		s += max(abs(min_a - i), abs(min_b - j))
	print(s)
	t -= 1


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(item) for item in input().split()]
	b = [int(item) for item in input().split()]
	ga = min(a)
	gb = min(b)
	ret = 0
	for (aa, bb) in zip(a, b):
		ra = aa - ga
		rb = bb - gb
		rc = min(ra, rb)
		ret += rc + (ra + rb - rc * 2)
	print(ret)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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

	def In():
		return map(int, input().split())
else:

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

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		a = list(In())
		b = list(In())
		ans = 0
		(A, B) = (min(a), min(b))
		ma = max(A, B)
		for i in range(n):
			if a[i] >= A and b[i] >= B:
				temp = min(a[i] - A, b[i] - B)
				ans += temp
				a[i] -= temp
				b[i] -= temp
			ans += a[i] - A
			ans += b[i] - B
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


from sys import stdout, stdin
from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	li = list(map(int, input().split()))
	a = min(l)
	b = min(li)
	k = 0
	for i in range(n):
		if l[i] - a > li[i] - b:
			k += l[i] - a
		else:
			k += li[i] - b
	print(k)


for _ in range(int(input())):
	r = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	x = min(a)
	y = min(b)
	c = 0
	for (i, j) in zip(a, b):
		m = i - x
		n = j - y
		if m > 0 and n > 0:
			c += min(m, n)
			c += abs(m - n)
		elif m > 0:
			c += m
		elif n > 0:
			c += n
	print(c)


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
con = 10 ** 9 + 7
INF = float('inf')

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

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		A = getlist()
		B = getlist()
		Amin = min(A)
		Bmin = min(B)
		ans = 0
		for i in range(N):
			x = A[i] - Amin
			y = B[i] - Bmin
			ans += max(x, y)
		print(ans)
main()


import sys
input = sys.stdin.readline
inf = int(10000000000.0)
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - mina, b[i] - minb)
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	k1 = min(a)
	k2 = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - k1, b[i] - k2)
	print(ans)


test = int(input())
for t in range(test):
	n = int(input())
	a = [] * n
	b = [] * n
	a = input().split()
	a = [int(i) for i in a]
	b = input().split()
	b = [int(i) for i in b]
	amin = min(a)
	bmin = min(b)
	output = 0
	for i in range(n):
		output += max(a[i] - amin, b[i] - bmin)
	print(output)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split(' ')))
	brr = list(map(int, input().strip().split(' ')))
	ta = min(arr)
	tb = min(brr)
	ans = 0
	(i, j) = (0, 0)
	top = 0
	bot = 0
	while i < n:
		top = arr[i] - ta
		bot = brr[i] - tb
		x = min(top, bot)
		ans += x
		ans += top - x + (bot - x)
		i += 1
	print(ans)


for i1 in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	c1 = min(a)
	c2 = min(b)
	for i in range(n):
		ans += max(a[i] - c1, b[i] - c2)
	print(ans)


import io, os
R = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(R())
	b = list(R())
	mv = []
	t = min(a)
	for i in range(n):
		mv.append(a[i] - t)
	mi = min(b)
	for i in range(n):
		tp = b[i] - mi
		if tp > mv[i]:
			mv[i] = tp
	print(sum(mv))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	res = 0
	for i in range(n):
		diff_a = a[i] - x
		diff_b = b[i] - y
		res += max(diff_a, diff_b)
	print(res)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	for i in range(n):
		a[i] = abs(a[i] - ma)
		b[i] = abs(b[i] - mb)
		a[i] = max(a[i], b[i])
	print(sum(a))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()][:n]
	b = [int(i) for i in input().split()][:n]
	cnt = 0
	(min1, min2) = (min(a), min(b))
	for i in range(n):
		diff1 = a[i] - min1
		diff2 = b[i] - min2
		cnt += min(diff1, diff2) + abs(diff1 - diff2)
	print(cnt)


def d4c(n, can, oran):
	cnt = 0
	for i in range(n):
		cnt += max(abs(can[i] - min(can)), abs(oran[i] - min(oran)))
	return cnt
for _ in range(int(input())):
	n = int(input())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	print(d4c(n, la, lb))


import math

def facts(n):
	ans = []
	for i in range(2, int(math.sqrt(n) + 1)):
		if n % i == 0:
			ans.append(i)
			ans.append(n // i)
	ans = sorted(ans)
	return ans
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	mc = min(c)
	mo = min(o)
	ans = 0
	for i in range(n):
		if c[i] > mc and o[i] > mo:
			dif = min(c[i] - mc, o[i] - mo)
			c[i] -= dif
			o[i] -= dif
			ans += dif
		if c[i] > mc:
			dif = c[i] - mc
			ans += dif
			c[i] -= dif
		if o[i] > mo:
			dif = o[i] - mo
			ans += dif
			o[i] -= dif
	print(ans)


def fun(l1, l2):
	l = len(l1)
	m1 = min(l1)
	m2 = min(l2)
	for k in range(len(l1)):
		l1[k] = l1[k] - m1
	for k in range(len(l2)):
		l2[k] = l2[k] - m2
	t = 0
	for i in range(l):
		if l1[i] == 0 and l2[i] == 0:
			continue
		if l1[i] == 0 and l2[i] != 0:
			t = t + l2[i]
		if l1[i] != 0 and l2[i] == 0:
			t = t + l1[i]
		if l1[i] != 0 and l2[i] != 0:
			k = max(l1[i], l2[i])
			t = t + k
	return t
n1 = int(input())
for _ in range(n1):
	n2 = int(input())
	(l1, l2) = ([], [])
	n3 = input()
	n4 = input()
	for j in range(n2):
		l1.append(int(n3.split()[j]))
		l2.append(int(n4.split()[j]))
	print(fun(l1, l2))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(x, y) = (min(a), min(b))
	op = 0
	for i in range(n):
		op += max(a[i] - x, b[i] - y)
	print(op)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min1 = min(a)
	min2 = min(b)
	t1 = 0
	for i in range(n):
		if a[i] == min1:
			if b[i] == min2:
				pass
			else:
				t1 += b[i] - min2
		elif b[i] == min2:
			t1 += a[i] - min1
		elif b[i] - min2 == a[i] - min1:
			t1 += b[i] - min2
		elif b[i] - min2 > a[i] - min1:
			t1 += b[i] - min2
		else:
			t1 += a[i] - min1
	print(t1)


for i in range(int(input())):
	l = int(input())
	k1 = list(map(int, input().split()))
	k2 = list(map(int, input().split()))
	m1 = min(k1)
	m2 = min(k2)
	c = 0
	for i in range(l):
		if k1[i] != m1 and k2[i] != m2:
			o1 = k1[i] - m1
			o2 = k2[i] - m2
			x = min(o1, o2)
			k1[i] -= x
			k2[i] -= x
			c += x
		if k1[i] != m1:
			j = k1[i] - m1
			c += j
		if k2[i] != m2:
			z = k2[i] - m2
			c += z
	print(c)


testcases = int(input())
for i in range(testcases):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_or = min(oranges)
	min_ca = min(candies)
	extra_candies = []
	extra_oranges = []
	for j in range(n):
		extra_candies.append(candies[j] - min_ca)
		extra_oranges.append(oranges[j] - min_or)
	moves = 0
	for j in range(n):
		moves += max(extra_oranges[j], extra_candies[j])
	print(moves)


t = int(input())
while t:
	t -= 1
	n = int(input())
	ls1 = list(map(int, input().split()))
	ls2 = list(map(int, input().split()))
	ans = 0
	(m1, m2) = (min(ls1), min(ls2))
	for i in range(n):
		ans += max(ls1[i] - m1, ls2[i] - m2)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	mc = min(c)
	mo = min(o)
	r = 0
	for i in range(n):
		r += max(c[i] - mc, o[i] - mo)
	print(r)


for i in range(int(input())):
	l = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	t = 0
	for j in range(l):
		t += max([a[j] - a1, b[j] - b1])
	print(t)


R = lambda : [*map(int, input().split())]
(t,) = R()
for _ in [0] * t:
	R()
	a = R()
	b = R()
	l = min(a)
	m = min(b)
	print(sum((min(x - l, y - m) + abs(x - l - y + m) for (x, y) in zip(a, b))))


t = int(input())
for _ in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	c = min(candies)
	ora = min(oranges)
	ans = 0
	for i in range(n):
		if candies[i] == c:
			ans += abs(oranges[i] - ora)
		elif oranges[i] == ora:
			ans += abs(candies[i] - c)
		else:
			a = abs(oranges[i] - ora)
			b = abs(candies[i] - c)
			ans += abs(a - b)
			ans += min(a, b)
	print(ans)


t = input()
t = int(t)
l = [input() for i in range(3 * t)]
for i in range(0, 3 * t, 3):
	l[i] = int(l[i])
	l[i + 1] = l[i + 1].split()
	l[i + 2] = l[i + 2].split()
	for j in range(l[i]):
		l[i + 1][j] = int(l[i + 1][j])
		l[i + 2][j] = int(l[i + 2][j])
for i in range(0, 3 * t, 3):
	x = min(l[i + 1])
	y = min(l[i + 2])
	a = 0
	j = 0
	while j < l[i]:
		a += max(l[i + 1][j] - x, l[i + 2][j] - y)
		j += 1
	print(a)


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	e_orange = min(a)
	e_candies = min(b)
	moves = 0
	for i in range(n):
		if a[i] == e_orange and b[i] > e_candies:
			moves += b[i] - e_candies
		elif b[i] == e_candies and a[i] > e_orange:
			moves += a[i] - e_orange
		elif a[i] > e_orange and b[i] > e_candies:
			a_diff = a[i] - e_orange
			b_diff = b[i] - e_candies
			moves += max(a_diff, b_diff)
	print(moves)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):
	n = II()
	aa = LI()
	bb = LI()
	am = min(aa)
	bm = min(bb)
	ans = 0
	for (a, b) in zip(aa, bb):
		ans += max(a - am, b - bm)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	cost = 0
	mincandie = min(candies)
	minorange = min(oranges)
	for k in range(n):
		cost += max(candies[k] - mincandie, oranges[k] - minorange)
	print(cost)


cases = int(input())
for i in range(cases):
	size = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = min(a)
	q = min(b)
	ans = 0
	for j in range(size):
		ans += max(a[j] - p, b[j] - q)
	print(ans)


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	ans = 0
	for i in range(n):
		if a[i] == ma:
			if b[i] == mb:
				continue
			else:
				ans += b[i] - mb
		elif b[i] == mb:
			if a[i] == ma:
				continue
			else:
				ans += a[i] - ma
		else:
			c = min(a[i] - ma, b[i] - mb)
			ans += c
			a[i] -= c
			b[i] -= c
			ans += a[i] - ma
			ans += b[i] - mb
	print(ans)


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
input = stdin.readline
letters = ascii_letters[:26]
for _ in range(int(input())):
	n = int(input())
	first = list(map(int, input().split()))
	second = list(map(int, input().split()))
	nf = min(first)
	ns = min(second)
	res = 0
	for i in range(n):
		diff = first[i] - nf
		difs = second[i] - ns
		bf = min(diff, difs)
		diff -= bf
		difs -= bf
		res += bf + diff + difs
	print(res)


for _ in range(int(input())):
	n = int(input())
	candies = [int(x) for x in input().split()]
	oranges = [int(x) for x in input().split()]
	ans = 0
	mc = min(candies)
	mo = min(oranges)
	for i in range(n):
		if candies[i] == mc:
			if oranges[i] == mo:
				continue
			else:
				ans += oranges[i] - mo
		elif oranges[i] == mo:
			ans += candies[i] - mc
		else:
			candies[i] -= mc
			oranges[i] -= mo
			if candies[i] < oranges[i]:
				ans += candies[i] + (oranges[i] - candies[i])
			elif candies[i] > oranges[i]:
				ans += oranges[i] + (candies[i] - oranges[i])
			else:
				ans += candies[i]
	print(ans)


tests = int(input())
for test in range(tests):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	min_a = min(A)
	min_b = min(B)
	ans = 0
	for i in range(n):
		ans += max(abs(min_a - A[i]), abs(min_b - B[i]))
	print(ans)


def fcnt():
	result = ''
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		min_a = min(a)
		min_b = min(b)
		sum_a = sum(a)
		sum_b = sum(b)
		r = 0
		for i in range(n):
			if a[i] > min_a or b[i] > min_b:
				if a[i] > min_a and b[i] > min_b:
					min_r = min(a[i] - min_a, b[i] - min_b)
					max_r = max(a[i] - min_a, b[i] - min_b)
					r += min_r + max_r - min_r
				elif a[i] > min_a:
					r += a[i] - min_a
				else:
					r += b[i] - min_b
		result += f'{r}\n'
	print(result)
fcnt()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = 0
	mna = min(a)
	mnb = min(b)
	for i in range(n):
		cnt += max(a[i] - min(a), b[i] - min(b))
	print(cnt)


t = int(input())
for T in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	minA = min(a)
	minB = min(b)
	moves = 0
	for g in range(n):
		moves += max(a[g] - minA, b[g] - minB)
	print(moves)


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	Min1 = min(arr1)
	Min2 = min(arr2)
	ans = 0
	for i in range(len(arr1)):
		ans += max(arr1[i] - Min1, arr2[i] - Min2)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	c = [int(i) for i in input().split()]
	o = [int(i) for i in input().split()]
	mc = min(c)
	oc = min(o)
	r = []
	x = y = 0
	a = b = 0
	for i in range(n):
		if c[i] != mc:
			x = c[i] - mc
		if o[i] != oc:
			y = o[i] - oc
		if x > y:
			r.append(x)
		else:
			r.append(y)
		x = 0
		y = 0
	print(sum(r))


for t in range(int(input())):
	n = int(input())
	c = [int(x) for x in input().split(' ')]
	o = [int(x) for x in input().split(' ')]
	minc = min(c)
	mino = min(o)
	ans = 0
	for i in range(n):
		a = c[i] - minc
		b = o[i] - mino
		ans += min([a, b]) + abs(a - b)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	(*a,) = map(int, input().split())
	(*b,) = map(int, input().split())
	ma = min(a)
	mb = min(b)
	a = [ai - ma for ai in a]
	b = [bi - mb for bi in b]
	ans = 0
	for i in range(n):
		ans += max(a[i], b[i])
	print(ans)


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = min(a)
	m = min(b)
	ans = 0
	for i in range(n):
		s1 = a[i] - k
		s2 = b[i] - m
		s = max(s1, s2)
		ans = ans + s
	print(ans)


def function(c, o):
	i = 0
	total = 0
	m_c = min(c)
	m_o = min(o)
	while i < len(c):
		total1 = 0
		total2 = 0
		if c[i] == m_c:
			total1 += 0
		if c[i] > m_c:
			total1 += c[i] - m_c
		if o[i] == m_o:
			total2 += 0
		if o[i] > m_o:
			total2 += o[i] - m_o
		total += max(total1, total2)
		i += 1
	print(total)
t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().rstrip().split()))
	o = list(map(int, input().rstrip().split()))
	function(c, o)


t = int(input())
while t:
	n = int(input())
	a = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	z = min(a)
	y = min(b)
	c = 0
	for i in range(len(a)):
		if z == a[i] or y == b[i]:
			if z == a[i]:
				c += b[i] - y
			else:
				c += a[i] - z
		elif abs(a[i] - z) < abs(b[i] - y):
			c += abs(a[i] - z)
			b[i] -= abs(a[i] - z)
			c += b[i] - y
		else:
			c += abs(b[i] - y)
			a[i] -= abs(b[i] - y)
			c += a[i] - z
	print(c)
	t -= 1


nb_testcases = int(input())
for _ in range(nb_testcases):
	nb_operations = 0
	nb_gifts = int(input())
	a = list(map(int, input().split(' ')))
	o = list(map(int, input().split(' ')))
	a_min = min(a)
	o_min = min(o)
	for i in range(nb_gifts):
		nb_operations = nb_operations + min(a[i] - a_min, o[i] - o_min) + (a[i] - a_min - min(a[i] - a_min, o[i] - o_min)) + (o[i] - o_min - min(a[i] - a_min, o[i] - o_min))
	print(nb_operations)


try:
	t = int(input())
	while t:
		counter = 0
		length = int(input())
		candies = list(map(int, input().split()))
		oranges = list(map(int, input().split()))
		min_candies = min(candies)
		min_oranges = min(oranges)
		for i in range(length):
			if candies[i] - min_candies == oranges[i] - min_oranges:
				counter += candies[i] - min_candies
			else:
				counter += max(candies[i] - min_candies, oranges[i] - min_oranges)
		print(counter)
		t -= 1
except EOFError:
	pass


def solve(n, a, b):
	minA = min(a)
	minB = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - minA, b[i] - minB)
	return ans
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(n, a, b))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ss = 0
	x = min(a)
	y = min(b)
	for i in range(n):
		p = a[i] - x
		q = b[i] - y
		if p < q:
			ss += p + (q - p)
		else:
			ss += q + (p - q)
	print(ss)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	total = 0
	for i in range(n):
		a_diff = a[i] - a_min
		b_diff = b[i] - b_min
		total += max(a_diff, b_diff)
	print(total)


n = int(input())
for i in range(n):
	a = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	count1 = 0
	for j in range(len(l1)):
		count1 += max(l1[j] - min(l1), l2[j] - min(l2))
	print(count1)


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()]
	mina = min(a)
	minb = min(b)
	mov = 0
	for i in range(0, n):
		x = a[i] - mina
		y = b[i] - minb
		equal = min(x, y)
		x = x - equal
		y = y - equal
		mov += equal + x + y
	print(mov)


t = int(input())
for z in range(t):
	n = int(input())
	arr1 = list(map(int, input().rstrip().split()))
	arr2 = list(map(int, input().rstrip().split()))
	min1 = min(arr1)
	min2 = min(arr2)
	count = 0
	for i in range(0, len(arr1)):
		if arr1[i] == min1 and arr2[i] != min2:
			d = arr2[i] - min2
			count += d
			arr2[i] -= d
		elif arr1[i] != min1 and arr2[i] == min2:
			d = arr1[i] - min1
			count += d
			arr1[i] -= d
		elif arr1[i] != min1 and arr2[i] != min2:
			d1 = arr1[i] - min1
			d2 = arr2[i] - min2
			if d1 > d2:
				count += d2
				arr1[i] -= d2
				arr2[i] -= d2
				x = arr1[i] - min1
				count += x
				arr1[i] -= x
			elif d2 > d1:
				count += d1
				arr1[i] -= d1
				arr2[i] -= d1
				x = arr2[i] - min2
				count += x
				arr2[i] -= x
			elif d1 == d2:
				count += d1
				arr1[i] -= d1
				arr2[i] -= d1
	print(count)


def tc():
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	(minc, mino) = (min(candies), min(oranges))
	moves = 0
	for (c, o) in zip(candies, oranges):
		(cdiff, odiff) = (c - minc, o - mino)
		moves += max(cdiff, odiff)
	print(moves)
T = int(input())
for _ in range(T):
	tc()


import sys
input = sys.stdin.readline
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	counter = 0
	for j in range(n):
		z = max(a[j] - a1, b[j] - b1)
		counter += z
	print(counter)


for _ in range(int(input())):
	n = int(input())
	A = [int(_) for _ in input().split()]
	B = [int(_) for _ in input().split()]
	a = min(A)
	b = min(B)
	S = 0
	for _ in range(n):
		S += max(A[_] - a, B[_] - b)
	print(S)


times = int(input())
for t in range(times):
	gift_num = int(input())
	res = input()
	res = res.split(' ')
	a = list(map(int, res))
	res = input()
	res = res.split(' ')
	b = list(map(int, res))
	min_a = min(a)
	min_b = min(b)
	count = 0
	arr = []
	for i in range(len(a)):
		arr.append([a[i], b[i]])
	for each in arr:
		count += max(each[0] - min_a, each[1] - min_b)
	print(count)


for i in range(int(input())):
	count = 0
	t = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(zip(a, b))
	res = (min(a), min(b))
	for k in c:
		if k[0] > min(a):
			count = count + (k[0] - min(a))
		if k[1] > min(b):
			count = count + (k[1] - min(b))
		count = count - min([k[0] - min(a), k[1] - min(b)])
	print(count)


def gifts(l1, l2):
	min_l1 = min(l1)
	l1_tries = [x - min_l1 for x in l1]
	min_l2 = min(l2)
	l2_tries = [x - min_l2 for x in l2]
	l1_l2 = [max(x1, x2) for (x1, x2) in zip(l1_tries, l2_tries)]
	return sum(l1_l2)
T = int(input())
for i in range(T):
	N = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	print(gifts(l1, l2))


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()]
	x = min(a)
	y = min(b)
	sum1 = 0
	for i in range(n):
		reqa = a[i] - x
		reqb = b[i] - y
		sum1 += max(reqa, reqb)
	print(sum1)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	l = list(map(int, input().split()))
	a = min(s)
	b = min(l)
	c = 0
	for i in range(n):
		x = s[i] - a
		y = l[i] - b
		c += max(x, y)
	print(c)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	mina = a[0]
	minb = b[0]
	for i in range(n):
		if a[i] < mina:
			mina = a[i]
		if b[i] < minb:
			minb = b[i]
	ans = 0
	for j in range(n):
		if a[j] - mina >= b[j] - minb:
			ans += b[j] - minb
			temp = a[j] - (b[j] - minb)
			ans += temp - mina
		elif a[j] - mina < b[j] - minb:
			ans += a[j] - mina
			temp = b[j] - (a[j] - mina)
			ans += temp - minb
	print(ans)


t = int(input())
for tc in range(t):
	n = int(input())
	l1 = list(map(int, input().split(' ')))
	l2 = list(map(int, input().split(' ')))
	m1 = min(l1)
	m2 = min(l2)
	s = 0
	for i in range(n):
		k1 = l1[i] - m1
		k2 = l2[i] - m2
		s = s + max(k1, k2)
	print(s)


test_case = int(input())
answers = []
for _ in range(test_case):
	count = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	for i in range(n):
		a_num = a[i] - a_min
		b_num = b[i] - b_min
		count = count + min(a_num, b_num) + abs(a_num - b_num)
	answers.append(count)
for i in answers:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	c = 0
	for i in range(n):
		if a[i] > x and b[i] > y:
			p = a[i] - x
			q = b[i] - y
			c += min(p, q)
			if p > q:
				c += p - q
			else:
				c += q - p
		elif a[i] > x:
			c += a[i] - x
		elif b[i] > y:
			c += b[i] - y
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	a = min(arr)
	b = min(brr)
	count = 0
	for i in range(n):
		j = min(arr[i] - a, brr[i] - b)
		count += j
		arr[i] -= j
		brr[i] -= j
		if arr[i] != a:
			count += arr[i] - a
		elif brr[i] != b:
			count += brr[i] - b
	print(count)


number_test_cases = int(input())
for _ in range(number_test_cases):
	number_gifts = int(input())
	candies = [int(n) for n in input().split()]
	oranges = [int(n) for n in input().split()]
	min_candies = min(candies)
	min_oranges = min(oranges)
	moves = 0
	for n in range(number_gifts):
		moves += max(candies[n] - min_candies, oranges[n] - min_oranges)
	print(moves)


t = int(input())
for i in range(t):
	n = int(input())
	can = list(map(int, input().split()))
	ora = list(map(int, input().split()))
	mincan = min(can)
	minora = min(ora)
	moves = 0
	for i in range(n):
		if can[i] == mincan and ora[i] == minora:
			continue
		elif can[i] == mincan and ora[i] != minora:
			moves += ora[i] - minora
		elif can[i] != mincan and ora[i] == minora:
			moves += can[i] - mincan
		else:
			a = can[i] - mincan
			b = ora[i] - minora
			x = min(a, b)
			y = max(a, b)
			moves += x + (y - x)
	print(moves)


t = int(input())
for _ in range(t):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	c_min = min(candy)
	o_min = min(orange)
	tot = 0
	for i in range(n):
		tot += max(candy[i] - c_min, orange[i] - o_min)
	print(tot)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	sum = 0
	for i in range(n):
		if a[i] > mina and b[i] > minb:
			sum += max(a[i] - mina, b[i] - minb)
		elif a[i] > mina and b[i] == minb:
			sum += a[i] - mina
		elif a[i] == mina and b[i] > minb:
			sum += b[i] - minb
	print(sum)


t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	m1 = min(a)
	m2 = min(b)
	count = 0
	for i in range(n):
		if a[i] - m1 == b[i] - m2:
			count += a[i] - m1
		else:
			count += min(a[i] - m1, b[i] - m2) + abs(a[i] - m1 - (b[i] - m2))
	print(count)


def solve(n, a, b):
	am = min(a)
	bm = min(b)
	res = 0
	for i in range(n):
		res += max(a[i] - am, b[i] - bm)
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	print(solve(n, a, b))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	c = 0
	for i in range(n):
		if a[i] > a1:
			if b[i] > b1:
				c += max(a[i] - a1, b[i] - b1)
			else:
				c += a[i] - a1
		elif b[i] > b1:
			if a[i] > a1:
				c += max(a[i] - a1, b[i] - b1)
			else:
				c += b[i] - b1
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ansA = min(a)
	ansB = min(b)
	ans = 0
	for i in range(n):
		ans += min(a[i] - ansA, b[i] - ansB) + abs(a[i] - ansA + ansB - b[i])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	cmin = min(c)
	omin = min(o)
	cnt = 0
	for i in range(n):
		if c[i] > cmin and o[i] > omin:
			su = min(c[i] - cmin, o[i] - omin)
			c[i] -= su
			o[i] -= su
			cnt += su
			if c[i] != cmin:
				cnt += c[i] - cmin
				c[i] = cmin
			elif o[i] != omin:
				cnt += o[i] - omin
				o[i] = omin
		elif c[i] > cmin:
			cnt += c[i] - cmin
			c[i] = cmin
		elif o[i] > omin:
			cnt += o[i] - omin
			o[i] = omin
	print(cnt)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	lis = []
	for i in range(n):
		lis.append((a[i] - ma, b[i] - mb))
	c = 0
	for i in lis:
		c += max(i)
	print(c)


n = int(input())
for i in range(0, n):
	m = int(input())
	A = input()
	B = input()
	A = A.split(' ')
	B = B.split(' ')
	A = list(map(int, A))
	B = list(map(int, B))
	a = min(A)
	b = min(B)
	count = 0
	for j in range(m):
		aj = A[j] - a
		bj = B[j] - b
		if aj == bj:
			count = count + aj
		elif aj < bj:
			count = count + bj
		elif aj > bj:
			count = count + aj
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	(m, ma, mb) = (0, min(a), min(b))
	for i in range(n):
		m += max(a[i] - ma, b[i] - mb)
	print(m)


from sys import stdin, stdout
from collections import Counter
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	n = int(I1())
	a = list(I())
	b = list(I())
	(a1, b1, ans) = (min(a), min(b), 0)
	for i in range(n):
		ans += max(abs(a[i] - a1), abs(b[i] - b1))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aa = min(a)
	bb = min(b)
	ans = 0
	for i in range(n):
		op = a[i] - aa
		oo = b[i] - bb
		ans += max(op, oo)
	print(ans)


def fast(A, B):
	result = 0
	(mA, mB) = (min(A), min(B))
	for (a, b) in zip(A, B):
		common = min(a, b) - max(mA, mB)
		if a - mA >= b - mB:
			left = a - mA - common
		else:
			left = b - mB - common
		result += common + left
	return result

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		result = fast(A, B)
		print(result)
main()


def candy_orange(s):
	p = min(s)
	s = list(map(lambda x: x - p, s))
	return s

def find_moves(a, b):
	moves = 0
	a = candy_orange(a)
	b = candy_orange(b)
	for i in range(len(a)):
		moves = moves + max(a[i], b[i])
	print(moves)
for _ in range(int(input())):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	find_moves(a, b)


t = int(input())
while t:
	a = []
	b = []
	n = int(input())
	inp = input().split()
	for i in range(n):
		a.append(int(inp[i]))
	inp = input().split()
	for i in range(n):
		b.append(int(inp[i]))
	k = 0
	for i in range(n):
		m = a[i] - min(a)
		n = b[i] - min(b)
		k = k + m + n - min(m, n)
	print(k, end='\n')
	t = t - 1


testcases = int(input())
for x in range(testcases):
	gifts = int(input())
	candies = [int(x) for x in input().split()]
	oranges = [int(x) for x in input().split()]
	minCand = min(candies)
	minOrang = min(oranges)
	moves = 0
	difCand = 0
	difOrang = 0
	for i in range(gifts):
		difCand = candies[i] - minCand
		difOrang = oranges[i] - minOrang
		if difCand > difOrang and difOrang != 0:
			candies[i] -= difOrang
			oranges[i] -= difOrang
			moves += difOrang
			difCand = candies[i] - minCand
			difOrang = oranges[i] - minOrang
			if difCand > 0:
				candies[i] -= difCand
				moves += difCand
		elif difOrang > difCand and difCand != 0:
			candies[i] -= difCand
			oranges[i] -= difCand
			moves += difCand
			difCand = candies[i] - minCand
			difOrang = oranges[i] - minOrang
			if difOrang > 0:
				oranges[i] -= difOrang
				moves += difOrang
		elif difOrang > 0:
			oranges[i] -= difOrang
			moves += difOrang
		elif difCand > 0:
			candies[i] -= difCand
			moves += difCand
	print(moves)


for t in range(int(input())):
	n = int(input())
	a = list((int(y) for y in input().strip().split()))
	b = list((int(y) for y in input().strip().split()))
	(ma, mb, x) = (min(a), min(b), 0)
	for i in range(n):
		x += max(a[i] - ma, b[i] - mb)
	print(x)


for _ in range(int(input())):
	n = int(input())
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	m1 = min(a1)
	m2 = min(a2)
	ans1 = [0] * n
	ans2 = [0] * n
	for i in range(n):
		ans1[i] = a1[i] - m1
		ans2[i] = a2[i] - m2
	ans = 0
	for i in range(n):
		ans += max(ans1[i], ans2[i])
	print(ans)


test_cases = int(input())
for _ in range(test_cases):
	n = int(input())
	(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
	(mina, minb) = (min(a), min(b))
	total_moves = 0
	for i in range(len(a)):
		a_to_eat = a[i] - mina
		b_to_eat = b[i] - minb
		moves = max([a_to_eat, b_to_eat])
		total_moves += moves
	print(total_moves)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	c = 0
	for i in range(n):
		while a[i] != mina or b[i] != minb:
			if a[i] > mina and b[i] > minb:
				adiff = a[i] - mina
				bdiff = b[i] - minb
				c += min(adiff, bdiff)
				a[i] -= min(adiff, bdiff)
				b[i] -= min(adiff, bdiff)
			elif a[i] > mina:
				c += a[i] - mina
				a[i] -= a[i] - mina
			elif b[i] > minb:
				c += b[i] - minb
				b[i] -= b[i] - minb
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a.count(a[0]) == b.count(b[0]) == n:
		print(0)
	else:
		a_min = min(a)
		b_min = min(b)
		count = 0
		for i in range(n):
			while a[i] > a_min and b[i] > b_min:
				x = min(a[i] - a_min, b[i] - b_min)
				a[i] -= x
				b[i] -= x
				count += x
			if a[i] > a_min:
				count += a[i] - a_min
			if b[i] > b_min:
				count += b[i] - b_min
		print(count)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = inar()
		b = inar()
		mna = 10 ** 10
		mnb = 10 ** 10
		for i in range(n):
			if mna > a[i]:
				mna = a[i]
			if mnb > b[i]:
				mnb = b[i]
		ans = 0
		for i in range(n):
			take = max(a[i] - mna, b[i] - mnb)
			ans += take
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for i in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()][:n]
	b = [int(i) for i in input().split()][:n]
	c = min(a)
	o = min(b)
	ans = 0
	for j in range(n):
		if a[j] == c:
			if b[j] == o:
				continue
			else:
				ans += b[j] - o
		elif b[j] == o:
			if a[j] == c:
				continue
			else:
				ans += a[j] - c
		else:
			w = a[j] - c
			l = b[j] - o
			f = max(w, l)
			ans += f
	print(ans)


T = int(input())
while T != 0:
	N = int(input())
	a = list(map(int, input().strip().split()))[:N]
	b = list(map(int, input().strip().split()))[:N]
	aMin = min(a)
	bMin = min(b)
	ans = 0
	for i in range(N):
		ans += max(a[i] - aMin, b[i] - bMin)
	print(ans)
	T -= 1


import math
from sys import stdin
from collections import Counter, defaultdict, deque
input = stdin.readline

def int1():
	return int(input())

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

def list1():
	return list(map(int, input().split()))
mod = pow(10, 9) + 7

def solve():
	n = int1()
	l1 = list1()
	l2 = list1()
	m1 = min(l1)
	m2 = min(l2)
	sum1 = 0
	for i in range(n):
		v = l1[i] - m1
		v1 = l2[i] - m2
		sum1 += max(v, v1)
	print(sum1)
for _ in range(int(input())):
	solve()


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(m,) = I()
while m:
	(n,) = I()
	arr1 = I()
	arr2 = I()
	x = min(arr1)
	y = min(arr2)
	sumi = 0
	for i in range(n):
		a = arr1[i] - x
		b = arr2[i] - y
		sumi += abs(a - b) + min(a, b)
	print(sumi)
	m -= 1


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	C = min(a)
	F = min(b)
	m = 0
	for i in range(0, n):
		da = a[i] - C
		db = b[i] - F
		s = min(da, db)
		m += s + abs(da - db)
	print(m)


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')

class union_find:

	def __init__(self, n):
		self.n = n
		self.rank = [0] * n
		self.parent = [int(j) for j in range(n)]

	def union(self, i, j):
		i = self.find(i)
		j = self.find(j)
		if self.rank[i] == self.rank[j]:
			self.parent[i] = j
			self.rank[j] += 1
		elif self.rank[i] > self.rank[j]:
			self.parent[j] = i
		else:
			self.parent[i] = j

	def find(self, i):
		temp = i
		if self.parent[temp] != temp:
			self.parent[temp] = self.find(self.parent[temp])
		return self.parent[temp]
from math import log2, ceil
from collections import deque

def main():
	for t in range(int(input())):
		n = int(input())
		a = [int(j) for j in input().split()]
		b = [int(j) for j in input().split()]
		mn = min(a)
		mn2 = min(b)
		ans = 0
		for i in range(n):
			ans += min(a[i] - mn, b[i] - mn2)
			ans += max(a[i] - mn, b[i] - mn2) - min(a[i] - mn, b[i] - mn2)
		print(ans)
main()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	a1 = [z - x for z in a]
	b1 = [z - y for z in b]
	ans = 0
	for i in range(n):
		ans += max(a1[i], b1[i])
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	mina = min(la)
	minb = min(lb)
	res = 0
	for i in range(n):
		ans1 = la[i] - mina
		ans2 = lb[i] - minb
		res += max(ans1, ans2)
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	(ii, ij) = (min(a), min(b))
	ans = 0
	for (i, j) in zip(a, b):
		di = i - ii
		dj = j - ij
		ans += min(di, dj)
		ans += max(di, dj) - min(di, dj)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	li1 = list(map(int, input().split()))
	min1 = min(li1)
	li2 = list(map(int, input().split()))
	min2 = min(li2)
	move = 0
	for (i, j) in zip(li1, li2):
		if i - min1 < j - min2:
			move += j - min2
		else:
			move += i - min1
	print(move)


t = int(input())
while t != 0:
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	minArr = min(arr)
	minBrr = min(brr)
	candy = 0
	for i in range(n):
		if minArr != arr[i] and minBrr != brr[i]:
			if arr[i] - minArr < brr[i] - minBrr:
				candy += arr[i] - minArr
				brr[i] -= arr[i] - minArr
				candy += brr[i] - minBrr
			else:
				candy += brr[i] - minBrr
				arr[i] -= brr[i] - minBrr
				candy += arr[i] - minArr
		elif minArr != arr[i]:
			candy += arr[i] - minArr
		elif minBrr != brr[i]:
			candy += brr[i] - minBrr
	print(candy)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	tempA = sorted(a)
	tempB = sorted(b)
	targetA = tempA[0]
	targetB = tempB[0]
	ans = 0
	for i in range(n):
		candies = a[i] - targetA
		orange = b[i] - targetB
		ans += min(candies, orange)
		ans += max(candies, orange) - min(candies, orange)
	print(ans)


tests = int(input())
for t in range(tests):
	n = int(input())
	arr_i = list(map(int, input().split()))
	arr_j = list(map(int, input().split()))
	min_arr_i = min(arr_i)
	min_arr_j = min(arr_j)
	res = 0
	for idx in range(n):
		res += max(arr_i[idx] - min_arr_i, arr_j[idx] - min_arr_j)
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mn1 = min(a)
	mn2 = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - mn1, b[i] - mn2)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	array_a = list(map(int, input().split()))
	array_b = list(map(int, input().split()))
	(min_a, min_b) = (min(array_a), min(array_b))
	moves = 0
	for i in range(n):
		array_a[i] = array_a[i] - min_a
		array_b[i] = array_b[i] - min_b
		if array_a[i] == 0 or array_b[i] == 0:
			moves += array_a[i] + array_b[i]
		else:
			(high, low) = (max(array_a[i], array_b[i]), min(array_a[i], array_b[i]))
			moves += high
	print(moves)


def q661b():
	num_cases = int(input())
	for _ in range(num_cases):
		arr_size = int(input())
		arr1 = [int(num) for num in input().split()]
		arr2 = [int(num) for num in input().split()]
		min1 = min(arr1)
		min2 = min(arr2)
		total = 0
		for i in range(arr_size):
			x = min(arr1[i] - min1, arr2[i] - min2)
			arr1_new = arr1[i] - x
			arr2_new = arr2[i] - x
			y = arr1_new - min1 + arr2_new - min2
			total = total + x + y
		print(total)
q661b()


for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(n):
		count += max(a[i] - min_a, b[i] - min_b)
	print(count)


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()))
	amin = min(a)
	bmin = min(b)
	for i in range(n):
		a[i] -= amin
		b[i] -= bmin
	re = 0
	for i in range(n):
		re += max(a[i], b[i])
	print(re)


def giftsFixing(n: int, candies: list, oranges: list) -> int:
	if min(candies) == max(candies) and min(oranges) == max(oranges):
		return 0
	else:
		moves = 0
		c = min(candies)
		o = min(oranges)
		for i in range(n):
			if candies[i] > c and oranges[i] > o:
				moves = moves + max(candies[i] - c, oranges[i] - o)
			elif oranges[i] > o:
				moves = moves + oranges[i] - o
			elif candies[i] > c:
				moves = moves + candies[i] - c
		return moves
t = int(input())
for i in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	print(giftsFixing(n, candies, oranges))


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	ma = min(ar)
	mb = min(br)
	ans = 0
	for (i, j) in zip(ar, br):
		r1 = i - ma
		r2 = j - mb
		x = min(r1, r2)
		ans += x
		r1 -= x
		r2 -= x
		ans += r1
		ans += r2
	print(ans)


t = int(input())
for ex in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	min_o = pow(10, 9) + 1
	can_min = pow(10, 9) + 1
	for i in range(n):
		min_o = min(min_o, b[i])
		can_min = min(can_min, a[i])
	ans = 0
	for i in range(n):
		both = min(a[i] - can_min, b[i] - min_o)
		ans += a[i] - can_min - both
		ans += b[i] - min_o - both
		ans += both
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	ai = list(map(int, input().split()))
	bi = list(map(int, input().split()))
	ava = min(ai)
	avb = min(bi)
	ans = 0
	for i in range(n):
		ai[i] = ava - ai[i]
		bi[i] = avb - bi[i]
		if ai[i] < 0 and bi[i] < 0:
			mi = min(-ai[i], -bi[i])
			ma = max(-ai[i], -bi[i])
			ans += ma - mi
			ans += mi
		else:
			ans += abs(ai[i]) + abs(bi[i])
	print(ans)


import sys
import os
from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

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

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

def solve():
	n = iinp()
	a = intl()
	b = intl()
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		if a[i] > amin:
			c = min(b[i] - bmin, a[i] - amin)
			b[i] -= c
			a[i] -= c
			ans += c
		if a[i] > amin:
			ans += a[i] - amin
			a[i] = amin
	for i in range(n):
		if b[i] > bmin:
			c = min(b[i] - bmin, a[i] - amin)
			a[i] -= c
			b[i] -= c
			ans += c
		if b[i] > bmin:
			ans += b[i] - bmin
			b[i] = bmin
	print(ans)
for _ in range(iinp()):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	da = []
	db = []
	ma = min(a)
	mb = min(b)
	for x in a:
		da.append(x - ma)
	for y in b:
		db.append(y - mb)
	mvs = 0
	for i in range(len(da)):
		mvs += max(da[i], db[i])
	print(mvs)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	cnt = 0
	for i in range(n):
		diffa = a[i] - amin
		diffb = b[i] - bmin
		cnt += max(diffa, diffb)
	print(cnt)


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	a1 = min(a)
	b1 = min(b)
	for i in range(n):
		q = max(a[i] - a1, b[i] - b1)
		ans = ans + q
	print(ans)


for i in range(int(input())):
	tot = 0
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	mc = min(c)
	mo = min(o)
	j = 0
	while j < n:
		cm = c[j] - mc
		om = o[j] - mo
		tot += max(cm, om)
		j += 1
	print(tot)


from sys import stdin

def input():
	return stdin.readline().rstrip()
for _ in range(int(input())):
	r = 0
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	candymin = min(candy)
	orangemin = min(orange)
	for i in range(n):
		candy[i] -= candymin
		orange[i] -= orangemin
		r += max(candy[i], orange[i])
	print(r)


t = int(input())
for i in range(t):
	giftnum = int(input())
	giftAlist = list(map(int, input().split()))
	giftBlist = list(map(int, input().split()))
	ans = 0
	for j in range(giftnum):
		ans += max(giftAlist[j] - min(giftAlist), giftBlist[j] - min(giftBlist))
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	x = min(ar)
	y = min(br)
	ans = 0
	for i in range(n):
		ans += max(ar[i] - x, br[i] - y)
	print(ans)


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

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

def sarr():
	return [int(i) for i in input()]

def inn():
	return int(input())
t = inn()
while t:
	t -= 1
	n = inn()
	a = arr()
	b = arr()
	mna = min(a)
	mnb = min(b)
	res = []
	for i in range(n):
		res += [a[i] - mna]
	for i in range(n):
		val = b[i] - mnb
		if val >= res[i]:
			res[i] = val
	print(sum(res))


n = int(input())
for i in range(0, n):
	n1 = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	count = 0
	for j in range(0, n1):
		while a[j] > m1 or b[j] > m2:
			if a[j] > m1 and b[j] > m2:
				l1 = a[j] - m1
				l2 = b[j] - m2
				k = min(l1, l2)
				a[j] -= k
				b[j] -= k
				count += k
			elif a[j] > m1 and b[j] == m2:
				l = a[j] - m1
				a[j] = m1
				count += l
			elif b[j] > m2 and a[j] == m1:
				l = b[j] - m2
				b[j] = m2
				count += l
	print(count)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	num = list(map(int, input().split()))
	su = 0
	mi1 = min(lis)
	mi2 = min(num)
	for i in range(n):
		v1 = lis[i] - mi1
		v2 = num[i] - mi2
		su += max(v1, v2)
	print(su)


t = int(input())
for i in range(t):
	n = int(input())
	C = list(map(int, input().split()))
	O = list(map(int, input().split()))
	tot = 0
	for j in range(n):
		tot = tot + max(C[j] - min(C), O[j] - min(O))
	print(tot)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(m1, m2) = (min(a), min(b))
	ans = 0
	for i in range(n):
		s1 = a[i] - m1
		s2 = b[i] - m2
		if s1 != 0 and s2 != 0:
			ans += min(s1, s2)
			t = min(s1, s2)
			s1 -= t
			s2 -= t
		ans += abs(s1 - s2)
	print(ans)


for i in range(int(input())):
	n = int(input())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	a = min(a1)
	b = min(b1)
	sum1 = 0
	for j in range(n):
		x = a1[j] - a
		y = b1[j] - b
		sum1 = sum1 + max(x, y)
	print(sum1)


t = int(input())
while t > 0:
	n = int(input())
	candy = [int(i) for i in input().split()]
	ora = [int(i) for i in input().split()]
	min_can = min(candy)
	min_ora = min(ora)
	moves = 0
	for i in range(n):
		if candy[i] > min_can and ora[i] > min_ora:
			if candy[i] - min_can < ora[i] - min_ora:
				moves += candy[i] - min_can
				ora[i] = ora[i] - (candy[i] - min_can)
				candy[i] = min_can
			else:
				moves += ora[i] - min_ora
				candy[i] = candy[i] - (ora[i] - min_ora)
				ora[i] = min_ora
		if candy[i] > min_can:
			moves += candy[i] - min_can
			candy[i] = min_can
		if ora[i] > min_ora:
			moves += ora[i] - min_ora
			ora[i] = min_ora
	print(moves)
	t -= 1


for i in range(int(input())):
	n = int(input())
	ar1 = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	m1 = min(ar1)
	m2 = min(ar2)
	ans = 0
	for i in range(n):
		temp1 = ar1[i] - m1
		temp2 = ar2[i] - m2
		ans += max(temp1, temp2)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	moves = 0
	for i in range(n):
		eata = a[i] - mina
		eatb = b[i] - minb
		moves += max(eata, eatb)
	print(moves)


a = int(input())
for i in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	cmin = min(c)
	dmin = min(d)
	for j in range(b):
		c[j] -= cmin
		d[j] -= dmin
	e = 0
	for j in range(b):
		e += max(c[j], d[j])
	print(e)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = min(a)
	m1 = min(b)
	c = 0
	for i in range(n):
		if a[i] > m and b[i] > m1:
			v = a[i] - m
			v1 = b[i] - m1
			v2 = min(v, v1)
			c = c + v2
			a[i] = a[i] - v2
			b[i] = b[i] - v2
		if a[i] > m:
			v = a[i] - m
			a[i] = a[i] - v
			c = c + v
		if b[i] > m1:
			v = b[i] - m1
			a[i] = a[i] - v
			c = c + v
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ansa = min(a)
	ansb = min(b)
	c = 0
	for i in range(n):
		if a[i] > ansa and b[i] > ansb:
			if a[i] > b[i]:
				c += b[i] - ansb
				a[i] -= b[i] - ansb
				b[i] = ansb
			elif b[i] > a[i]:
				c += a[i] - ansa
				b[i] -= a[i] - ansa
				a[i] = ansa
			elif ansa > ansb:
				c += a[i] - ansa
				b[i] -= a[i] - ansa
				a[i] = ansa
			elif ansb > ansa:
				c += b[i] - ansb
				a[i] -= b[i] - ansb
				b[i] = ansb
			else:
				c += a[i] - ansa
				a[i] = ansa
				b[i] = ansb
		if a[i] > ansa:
			c += a[i] - ansa
			a[i] = ansa
		if b[i] > ansb:
			c += b[i] - ansb
			b[i] = ansb
	print(c)


def anpassung(liste_a, liste_b):
	min_a = min(liste_a)
	min_b = min(liste_b)
	schritte_a = [liste_a[i] - min_a for i in range(len(liste_a))]
	schritte_b = [liste_b[i] - min_b for i in range(len(liste_b))]
	schritte = [max(schritte_a[i], schritte_b[i]) for i in range(len(liste_a))]
	print(sum(schritte))
tests = int(input())
for i in range(tests):
	length = int(input())
	anpassung(list(map(int, input().split(' '))), list(map(int, input().split(' '))))


import sys
t = int(sys.stdin.readline().split()[0])
for i in range(0, t):
	n = int(sys.stdin.readline().split()[0])
	a = [int(j) for j in sys.stdin.readline().split()]
	b = [int(j) for j in sys.stdin.readline().split()]
	steps = 0
	steps_a = 0
	steps_b = 0
	min_a = min(a)
	min_b = min(b)
	k = 0
	while k < n:
		steps_a = a[k] - min_a
		steps_b = b[k] - min_b
		steps += max(steps_a, steps_b)
		k += 1
	print(steps)


for i in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	p = 0
	j = 0
	minc = min(c)
	mino = min(o)
	for j in range(n):
		q = min(c[j] - minc, o[j] - mino)
		p += q
		c[j] -= q
		o[j] -= q
	for j in range(n):
		p += c[j] - minc + (o[j] - mino)
	print(p)


import math as Math
n = int(input())
for _ in range(n):
	numberOfGifts = int(input())
	aGifts = [int(x) for x in input().split(' ')]
	bGifts = [int(x) for x in input().split(' ')]
	minA = min(aGifts)
	minB = min(bGifts)
	steps = 0
	for i in range(numberOfGifts):
		steps += max(aGifts[i] - minA, bGifts[i] - minB)
	print(steps)


import sys
t = int(input())
while t > 0:
	n = int(input())
	result = 0
	sweets = [int(x) for x in input().split()]
	orange = list(map(int, input().split()))
	sweetsminin = sweets.index(min(sweets))
	orangeminin = orange.index(min(orange))
	for i in range(n):
		if sweets[i] > sweets[sweetsminin]:
			result += sweets[i] - sweets[sweetsminin]
	for i in range(n):
		if orange[i] > orange[orangeminin]:
			if orange[i] - orange[orangeminin] > sweets[i] - sweets[sweetsminin]:
				result += orange[i] - orange[orangeminin] - (sweets[i] - sweets[sweetsminin])
	print(f'{result}')
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aM = min(a)
	bM = min(b)
	c = 0
	for i in range(n):
		c += max(a[i] - aM, b[i] - bM)
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(amin, bmin) = (min(a), min(b))
	res = 0
	for i in range(n):
		(x, y) = (abs(a[i] - amin), abs(b[i] - bmin))
		res += abs(x - y) + min(x, y)
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	(ma, mb) = (min(a), min(b))
	for i in range(n):
		if a[i] - ma > 0:
			ans += a[i] - ma
		if b[i] - mb > 0:
			ans += b[i] - mb
		if b[i] - mb > 0 and a[i] - ma > 0:
			ans -= min(b[i] - mb, a[i] - ma)
	print(ans)


a = int(input())
for i in range(a):
	x = int(input())
	y = list(map(int, input().split(' ')))
	z = list(map(int, input().split(' ')))
	if len(y) == 1 and len(z) == 1:
		print(0)
	else:
		min_y = min(y)
		min_z = min(z)
		total_moves = 0
		for i in range(x):
			total_moves += max(y[i] - min_y, z[i] - min_z)
		print(total_moves)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(n):
		if a[i] > min_a or b[i] > min_b:
			c_a = a[i] - min_a
			c_b = b[i] - min_b
			count = count + max(c_a, c_b)
	print(count)


t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(mna, mnb, count) = (min(a), min(b), 0)
	for i in range(0, n):
		count += max(a[i] - mna, b[i] - mnb)
	print(count)


t = int(input())
while t:
	n = int(input())
	lista = list(map(int, input().strip().split()))[:n]
	listb = list(map(int, input().strip().split()))[:n]
	mina = min(lista)
	minb = min(listb)
	sum = int()
	for i in range(0, n):
		if lista[i] - mina >= listb[i] - minb:
			sum += lista[i] - mina
		else:
			sum += listb[i] - minb
	print(sum)
	t -= 1


n = int(input())
result = []
for i in range(n):
	num = int(input())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	mina = min(la)
	minb = min(lb)
	count = 0
	mint = min(mina, minb)
	for i in range(len(la)):
		if la[i] == mina:
			count = count + (lb[i] - minb)
		if lb[i] == minb:
			count = count + (la[i] - mina)
		if la[i] > mina and lb[i] > minb:
			if la[i] - mina > lb[i] - minb:
				count = count + (la[i] - mina - (lb[i] - minb))
				count += lb[i] - minb
			elif la[i] - mina < lb[i] - minb:
				count = count + (lb[i] - minb - (la[i] - mina))
				count += la[i] - mina
			else:
				count += la[i] - mina
	result.append(count)
for i in result:
	print(i)


import math
import datetime
import collections
import statistics
import itertools

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

def input_list():
	ll = list(map(int, input().split(' ')))
	return ll
tc = int(input())
for _ in range(tc):
	n = int(input())
	arr = input_list()
	brr = input_list()
	ma = min(arr)
	mb = min(brr)
	count = 0
	res = arr.count(arr[0]) == len(arr)
	rest = brr.count(brr[0]) == len(brr)
	i = 0
	while (not res or not rest) and i < n:
		if arr[i] > ma and brr[i] > mb:
			(xx, yy) = (arr[i], brr[i])
			arr[i] = ma
			brr[i] = mb
			count += max(xx - ma, yy - mb)
		elif arr[i] > ma:
			x = arr[i]
			arr[i] = ma
			count += x - ma
			i += 1
		elif brr[i] > mb:
			y = brr[i]
			brr[i] = mb
			count += y - mb
			i += 1
		else:
			i += 1
		res = arr.count(arr[0]) == len(arr)
		rest = brr.count(brr[0]) == len(brr)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	moves = 0
	for i in range(n):
		xa = a[i] - mina
		xb = b[i] - minb
		moves += min(xa, xb) + abs(xa - xb)
	print(moves)


for i in range(int(input())):
	n = int(input())
	(a, b) = (list(map(int, input().split(' '))), list(map(int, input().split(' '))))
	print(sum((max(a[j] - min(a), b[j] - min(b)) for j in range(n))))


import math
t = int(input())
for q in range(t):
	n = int(input())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	ma = min(A)
	mb = min(B)
	s = 0
	for i in range(n):
		s += max(A[i] - ma, B[i] - mb)
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	j = min(a)
	k = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - j, b[i] - k)
	print(ans)


for t in range(int(input())):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	mcan = min(candy)
	mor = min(orange)
	moves = 0
	for (x, y) in zip(candy, orange):
		(tempx, tempy) = (0, 0)
		if x > mcan:
			tempx = x - mcan
		if y > mor:
			tempy = y - mor
		moves += min(tempy, tempx)
		moves += max(tempy, tempx) - min(tempy, tempx)
	print(moves)


MOD = 1000000007

def i():
	return input()

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

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

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

def d2b(n):
	return bin(n).replace('0b', '')

def twod(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ispow2(x):
	return x and (not x & x - 1)

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)
t = ii()
while t:
	t -= 1
	n = ii()
	a = li()
	a1 = min(a)
	b = li()
	b1 = min(b)
	sa = 0
	for i in range(n):
		sa += max(a[i] - a1, b[i] - b1)
	print(sa)


t = int(input())
for tt in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	ma = min(a)
	mb = min(b)
	na = [x - ma for x in a]
	nb = [x - mb for x in b]
	ans = 0
	for i in range(n):
		ans += max(na[i], nb[i])
	print(ans)


inp = lambda cast=int: [cast(x) for x in input().split()]
printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)
(t,) = inp()
for _ in range(t):
	(n,) = inp()
	A = inp()
	B = inp()
	minA = min(A)
	minB = min(B)
	res = 0
	for (a, b) in zip(A, B):
		(da, db) = (a - minA, b - minB)
		res += min(da, db) + abs(da - db)
	print(res)


inp = lambda : map(int, input().split())
for _ in range(int(input())):
	N = int(input())
	a = list(inp())
	b = list(inp())
	mina = min(a)
	minb = min(b)
	total = 0
	for i in range(N):
		total += max(a[i] - mina, b[i] - minb)
	print(total)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	a2 = min(a)
	b2 = min(b)
	for i in range(n):
		ans += a[i] - a2 + (b[i] - b2) - min(a[i] - a2, b[i] - b2)
	print(ans)


t = int(input())
for t1 in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	moves = 0
	for i in range(len(a)):
		if a[i] > am and b[i] > bm:
			mn = min(a[i] - am, b[i] - bm)
			moves += mn
			a[i] -= mn
			b[i] -= mn
	for i in range(len(a)):
		if a[i] > am:
			moves += a[i] - am
			a[i] = am
	for i in range(len(b)):
		if b[i] > bm:
			moves += b[i] - bm
			b[i] = bm
	print(moves)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_small = min(a)
	b_small = min(b)
	need_A = []
	need_B = []
	for i in range(n):
		need_A.append(a[i] - a_small)
		need_B.append(b[i] - b_small)
	moves = 0
	for i in range(n):
		moves += max(need_A[i], need_B[i])
	print(moves)


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()]
	amin = min(a)
	bmin = min(b)
	count = 0
	for x in range(n):
		if a[x] > amin:
			if b[x] > bmin:
				if a[x] - amin > b[x] - bmin:
					count = count + a[x] - amin
				else:
					count = count + b[x] - bmin
			elif b[x] == bmin:
				count = count + a[x] - amin
		elif a[x] == amin:
			if b[x] > bmin:
				count = count + b[x] - bmin
	print(count)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = input()
	A = list(map(int, list(a.split())))
	b = input()
	B = list(map(int, list(b.split())))
	m1 = min(A)
	m2 = min(B)
	c = [0] * n
	d = [0] * n
	ans = 0
	for i in range(n):
		c[i] = A[i] - m1
		d[i] = B[i] - m2
		ans = ans + max(c[i], d[i])
	print(ans)


t = int(input())
for j in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - mina, b[i] - minb)
	print(ans)


u = int(input())
li = []
for i in range(u):
	i = int(input())
	x = list(map(int, list(input().split())))
	y = min(x)
	z = list(map(lambda x: x - y, x))
	a = list(map(int, list(input().split())))
	b = min(a)
	c = list(map(lambda x: x - b, a))
	d = 0
	for i in range(i):
		l = [z[i], c[i]]
		d += max(l)
	li.append(d)
for i in li:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	steps = 0
	for j in range(n):
		del_a = a[j] - a_min
		del_b = b[j] - b_min
		steps += min(del_a, del_b) + abs(del_a - del_b)
	print(steps)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(min_a, min_b) = (min(a), min(b))
	(diff_1, diff_2, res) = (0, 0, 0)
	for j in range(n):
		diff_1 = a[j] - min_a
		diff_2 = b[j] - min_b
		res += max(diff_2, diff_1)
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	m = 0
	for (i, j) in zip(a, b):
		m += max(abs(i - a_min), abs(j - b_min))
	print(m)


def giftFixing(a, b):
	ma = 1000000000000000
	mb = 1000000000000000
	for i in a:
		ma = min(ma, i)
	for i in b:
		mb = min(mb, i)
	for i in range(len(a)):
		a[i] = a[i] - ma
		b[i] = b[i] - mb
	ans = 0
	for i in range(len(a)):
		ans += max(a[i], b[i])
	return ans
n = int(input())
for i in range(n):
	k = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(giftFixing(a, b))


result = []

def fun(n, cand, org):
	candMin = min(cand)
	orgMin = min(org)
	ans = 0
	for i in range(n):
		ans += max(cand[i] - candMin, org[i] - orgMin)
	result.append(ans)
t = int(input())
for i in range(t):
	n = int(input())
	cand = list(map(int, input().split()))
	org = list(map(int, input().split()))
	fun(n, cand, org)
for i in result:
	print(i)


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

def main():
	for case in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		b = [int(x) for x in input().split()]
		a_min = min(a)
		b_min = min(b)
		ans = 0
		for i in range(n):
			x1 = a[i] - a_min
			x2 = b[i] - b_min
			ans += max(x1, x2)
		print(ans)
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')
main()


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	b = list(map(int, stdin.readline().rstrip().split()))
	mia = min(a)
	mib = min(b)
	ans = 0
	for i in range(n):
		rema = a[i] - mia
		remb = b[i] - mib
		ans += max(rema, remb)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	v1 = min(a)
	v2 = min(b)
	cnt = 0
	for j in range(n):
		Num1 = a[j] - v1
		Num2 = b[j] - v2
		num1 = a[j] - v1
		num2 = b[j] - v2
		cnt += min(num1, num2)
		Num1 -= min(num1, num2)
		Num2 -= min(num1, num2)
		cnt += max(Num1, Num2)
	print(cnt)


from fractions import Fraction
from collections import defaultdict
import math
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	n = int(input())
	a = list([int(x) for x in input().split()])
	b = list([int(x) for x in input().split()])
	am = min(a)
	bm = min(b)
	m = 0
	for i in range(n):
		v1 = abs(am - a[i])
		v2 = abs(bm - b[i])
		m += max(v1, v2)
	print(m)


t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	amin = min(a)
	bmin = min(b)
	diff_array = [max(i - amin, j - bmin) for (i, j) in zip(a, b)]
	print(sum(diff_array))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		da = a[i] - mina
		db = b[i] - minb
		ans += max(da, db)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	candyLeast = min(a)
	orangeLeast = min(b)
	moves = 0
	i = 0
	while i < n:
		candy = a[i] - candyLeast
		orange = b[i] - orangeLeast
		moves += abs(candy - orange) + min(candy, orange)
		i += 1
	print(moves)


def test_case():
	n = int(input())
	oranges = list(map(int, input().split()))
	candies = list(map(int, input().split()))
	mo = min(oranges)
	mc = min(candies)
	counter = 0
	for i in range(n):
		counter += max(oranges[i] - mo, candies[i] - mc)
	print(counter)
for i in range(int(input())):
	test_case()


for test in range(0, int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr2 = [int(x) for x in input().split()]
	ans = 0
	m = min(arr)
	n = min(arr2)
	for i in range(0, len(arr)):
		ans += max(arr[i] - m, arr2[i] - n)
	print(ans)


for i in range(0, int(input())):
	c = 0
	n = int(input())
	a = []
	b = []
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	i = 0
	x = min(a)
	y = min(b)
	while i < n:
		if a[i] == x and b[i] == y:
			i += 1
			continue
		elif a[i] == x and b[i] != y:
			c += b[i] - y
		elif a[i] != x and b[i] == y:
			c += a[i] - x
		else:
			x1 = a[i] - x
			y1 = b[i] - y
			c += min(x1, y1) + max(x1, y1) - min(x1, y1)
		i += 1
	print(c)


a = int(input())
for i in range(a):
	m = 0
	b = int(input())
	candy = [int(s) for s in input().split()]
	orange = [int(s) for s in input().split()]
	mincandy = candy[0]
	minorange = orange[0]
	for i in range(1, b):
		if candy[i] < mincandy:
			mincandy = candy[i]
		if orange[i] < minorange:
			minorange = orange[i]
	for i in range(b):
		if candy[i] > mincandy and orange[i] > minorange:
			if candy[i] - mincandy >= orange[i] - minorange:
				candy[i] = candy[i] - (orange[i] - minorange)
				m = m + orange[i] - minorange
				orange[i] = minorange
			else:
				orange[i] = orange[i] - (candy[i] - mincandy)
				m = m + candy[i] - mincandy
				candy[i] = mincandy
		if candy[i] > mincandy:
			m = m + candy[i] - mincandy
		if orange[i] > minorange:
			m = m + orange[i] - minorange
	print(m)


x = int(input())
for y in range(x):
	z = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	a1 = min(arr1)
	a2 = min(arr2)
	c = 0
	for (p1, p2) in zip(arr1, arr2):
		if p1 - a1 > p2 - a2:
			c += p1 - a1
		else:
			c += p2 - a2
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	aList = list(map(int, input().split()))
	bList = list(map(int, input().split()))
	minA = min(aList)
	minB = min(bList)
	counter = 0
	for i in range(n):
		counter += max(aList[i] - minA, bList[i] - minB)
	print(counter)


import math
from collections import defaultdict
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()]
	atmp = sorted(a)
	btmp = sorted(b)
	moves = 0
	(amin, bmin) = (atmp[0], btmp[0])
	for x in range(n):
		moves += min(abs(a[x] - amin), abs(b[x] - bmin))
		moves += abs(abs(a[x] - amin) - abs(b[x] - bmin))
	print(moves)


t = int(input())
R = lambda : map(int, input().split())
answers = []
for i in range(0, t):
	n = int(input())
	a = list(R())
	b = list(R())
	mina = min(a)
	minb = min(b)
	z = 0
	for j in range(0, n):
		z += max(a[j] - mina, b[j] - minb)
	answers.append(z)
for a in answers:
	print(a)


s = input()
while True:
	try:
		t = int(input())
		t1 = list(map(int, input().split(' ')))
		t2 = list(map(int, input().split(' ')))
		m1 = min(t1)
		m2 = min(t2)
		l = 0
		for i in range(t):
			if t1[i] > m1 and t2[i] > m2:
				c1 = t1[i] - m1
				c2 = t2[i] - m2
				l += min(c1, c2) + abs(c1 - c2)
			elif t1[i] > m1:
				l += t1[i] - m1
			elif t2[i] > m2:
				l += t2[i] - m2
		print(l)
	except:
		break


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

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 equal(x, y):
	return abs(x - y) <= 1e-09

def getAngle(a, b, c):
	ang = math.degrees(math.atan2(c[1] - b[1], c[0] - b[0]) - math.atan2(a[1] - b[1], a[0] - b[0]))
	return ang + 360 if ang < 0 else ang

def getLength(a, b):
	return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
from heapq import heapify, heappush, heappop

def bfs(adj):
	s = set()
	d = defaultdict(set)
	q = deque([])
	s.add(0)
	d[0].add(0)
	q.append((0, 0))
	while len(q) > 0:
		(v, depth) = q.popleft()
		for u in adj[v]:
			if u not in s:
				s.add(u)
				d[depth + 1].add(u)
				q.append((u, depth + 1))
	return d

def isSubsetSum(arr, n, summ):
	subarr = [[False for i in range(summ + 1)] for i in range(n + 1)]
	for i in range(n + 1):
		subarr[i][0] = True
	for i in range(1, summ + 1):
		subarr[0][i] = False
	for i in range(1, n + 1):
		for j in range(1, summ + 1):
			if j < arr[i - 1]:
				subarr[i][j] = subarr[i - 1][j]
			if j >= arr[i - 1]:
				subarr[i][j] = subarr[i - 1][j] or subarr[i - 1][j - arr[i - 1]]
	return subarr[n][summ]

def bfs(v, adj, onpath):
	s = set()
	d = defaultdict(set)
	q = deque([])
	s.add(0)
	d[0].add(0)
	q.append((0, 0))
	while len(q) > 0:
		(v, depth) = q.popleft()
		for u in adj[v]:
			if u not in s:
				s.add(u)
				d[depth + 1].add(u)
				q.append((u, depth + 1))
	return d

def solution(a, b, n):
	ma = min(a)
	mb = min(b)
	cnt = 0
	for i in range(n):
		da = a[i] - ma
		db = b[i] - mb
		together = min(db, da)
		apart = max(db, da) - together
		cnt += apart + together
	return cnt

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()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	t = 0
	for i in range(n):
		if a[i] > amin and b[i] > bmin:
			da = a[i] - amin
			db = b[i] - bmin
			t += abs(da - db) + min(da, db)
		else:
			if a[i] > amin:
				t += a[i] - amin
			if b[i] > bmin:
				t += b[i] - bmin
	print(t)


import sys
tc = int(sys.stdin.readline())
for _ in range(tc):
	n = int(sys.stdin.readline())
	candy = list(map(int, sys.stdin.readline().split()))
	orange = list(map(int, sys.stdin.readline().split()))
	min_candy = min(candy)
	min_orange = min(orange)
	ans = 0
	for i in range(n):
		(now_candy, now_orange) = (candy[i], orange[i])
		if now_candy == min_candy and now_orange > min_orange:
			ans += now_orange - min_orange
		elif now_candy > min_candy and now_orange == min_orange:
			ans += now_candy - min_candy
		elif now_candy > min_candy and now_orange > min_orange:
			if now_candy - min_candy < now_orange - min_orange:
				ans += now_candy - min_candy
				now_orange -= now_candy - min_candy
				if now_orange > min_orange:
					ans += now_orange - min_orange
			elif now_candy - min_candy > now_orange - min_orange:
				ans += now_orange - min_orange
				now_candy -= now_orange - min_orange
				if now_candy > min_candy:
					ans += now_candy - min_candy
			else:
				ans += now_candy - min_candy
	print(ans)


for t in range(int(input())):
	n = int(input())
	can = list(map(int, input().split()))
	orn = list(map(int, input().split()))
	mcan = min(can)
	morn = min(orn)
	ans = 0
	for i in range(n):
		a = can[i] - mcan
		b = orn[i] - morn
		ans += max(a, b)
	print(ans)


T = int(input())
for case in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(min_a, min_b) = (min(a), min(b))
	ans = 0
	for i in range(n):
		a_to_eat = a[i] - min_a
		b_to_eat = b[i] - min_b
		min_op = min(a_to_eat, b_to_eat)
		ans += min_op + (a_to_eat - min_op) + (b_to_eat - min_op)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aa = min(a)
	bb = min(b)
	dea = [0] * n
	deb = [0] * n
	ans = 0
	for i in range(n):
		dea[i] = a[i] - aa
		deb[i] = b[i] - bb
		ans += min(dea[i], deb[i]) + abs(dea[i] - deb[i])
	print(ans)


def main():
	t = int(input())
	for case in range(t):
		n = int(input())
		a = [int(x) for x in input().split()]
		b = [int(y) for y in input().split()]
		ma = min(a)
		mb = min(b)
		cost = 0
		for i in range(n):
			if a[i] > ma and b[i] > mb:
				da = a[i] - ma
				db = b[i] - mb
				cost += max(da, db)
			elif a[i] > ma:
				cost += a[i] - ma
			else:
				cost += b[i] - mb
		print(cost)
main()


def solution():
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		a_i = a[i] - min_a
		b_i = b[i] - min_b
		ans += a_i + b_i - min(a_i, b_i)
	print(ans)
for t in range(int(input())):
	solution()


test_case = int(input())
for _ in range(test_case):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	temp_a = [i - min(a) for i in a]
	temp_b = [i - min(b) for i in b]
	print(sum(map(max, temp_a, temp_b)))


import math
t = int(input())
for g in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	a = min(A)
	b = min(B)
	ans = 0
	for i in range(n):
		ans += max(A[i] - a, B[i] - b)
	print(ans)


n = int(input())

def fun(l1, l2, l):
	a = min(l1)
	b = min(l2)
	c = 0
	for i in range(l):
		if l1[i] > a and l2[i] > b:
			g = l1[i] - a
			h = l2[i] - b
			v = max(g, h)
			c += v
		if l1[i] > a and (not (l1[i] > a and l2[i] > b)):
			g = l1[i] - a
			c += g
		if l2[i] > b and (not (l1[i] > a and l2[i] > b)):
			h = l2[i] - b
			c += h
	return c
for i in range(n):
	a = int(input())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	print(fun(a1, b1, a))


def candies(candy, orange):
	c = min(candy)
	o = min(orange)
	count = 0
	for i in range(len(candy)):
		if candy[i] == c and orange[i] == o:
			continue
		if candy[i] != c and orange[i] != o:
			x = min(orange[i] - o, candy[i] - c)
			orange[i] = orange[i] - x
			candy[i] = candy[i] - x
			count = count + x
		if candy[i] == c and orange[i] != o:
			count = count + orange[i] - o
		if candy[i] != c and orange[i] == o:
			count = count + candy[i] - c
	return count
t = int(input())
for i in range(t):
	n = int(input())
	arr1 = list(map(int, input().strip().split()))
	arr2 = list(map(int, input().strip().split()))
	print(candies(arr1, arr2))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		da = a[i] - ma
		db = b[i] - mb
		a[i] = a[i] - min(da, db)
		b[i] = b[i] - min(da, db)
		c += min(da, db)
	for i in range(n):
		if a[i] != ma:
			c += a[i] - ma
		if b[i] != mb:
			c += b[i] - mb
	print(c)


t = input()
t = int(t)
while t > 0:
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	(a_min, b_min) = (min(a), min(b))
	ans = []
	ans1 = []
	cnt = 0
	for (idx, eval) in enumerate(a):
		ans.append(abs(a[idx] - a_min))
	for (idx, eval) in enumerate(b):
		ans1.append(abs(b[idx] - b_min))
	for (idx, eval) in enumerate(ans):
		cnt += max(ans[idx], ans1[idx])
	print(cnt)
	t -= 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()]
	a_min = min(a)
	b_min = min(b)
	count = 0
	for i in range(n):
		count += max(a[i] - a_min, b[i] - b_min)
	print(count)


for t in range(int(input())):
	n = int(input())
	a = [int(k) for k in input().split()]
	b = [int(k) for k in input().split()]
	ami = min(a)
	bmi = min(b)
	step = 0
	for i in range(n):
		adi = a[i] - ami
		bdi = b[i] - bmi
		if adi > bdi:
			step += bdi
			step += adi - bdi
		else:
			step += adi
			step += bdi - adi
	print(step)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min1 = min(a)
	for i in range(n):
		a[i] -= min1
	min1 = min(b)
	for i in range(n):
		b[i] -= min1
	moves = 0
	for i in range(n):
		moves += max(a[i], b[i])
	print(moves)


t = int(input())
for p in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_candy = min(a)
	min_orange = min(b)
	count = 0
	for i in range(n):
		count += max(a[i] - min_candy, b[i] - min_orange)
	print(count)


for t in range(int(input())):
	m = int(input())
	ar1 = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	(min1, min2) = (min(ar1), min(ar2))
	ans = 0
	for i in range(m):
		t1 = ar1[i] - min1
		t2 = ar2[i] - min2
		ans += max(t1, t2)
	print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

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 [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('../output.txt', 'w')
except:
	pass
for _ in range(L()[0]):
	n = L()[0]
	A = L()
	B = L()
	x = []
	ma = mb = 10 ** 10
	for i in range(n):
		x.append([A[i], B[i]])
		ma = min(A[i], ma)
		mb = min(B[i], mb)
	moves = 0
	for ele in x:
		diffa = ele[0] - ma
		diffb = ele[1] - mb
		moves += max(diffa, diffb)
	print(moves)


q = int(input())
for _ in range(q):
	n = int(input())
	data = list(map(int, input().split()))
	datb = list(map(int, input().split()))
	targeta = min(data)
	targetb = min(datb)
	res = 0
	for i in range(n):
		kaisuu = min(data[i] - targeta, datb[i] - targetb)
		res += kaisuu
		res += data[i] - kaisuu - targeta
		res += datb[i] - kaisuu - targetb
	print(res)


for i in range(int(input())):
	x = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	steps = 0
	c_min = min(c)
	o_min = min(o)
	for i in range(x):
		steps += max(c[i] - c_min, o[i] - o_min)
	print(steps)


for __ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = 0
	min_a = min(a)
	min_b = min(b)
	for i in range(n):
		ans += max(a[i] - min_a, b[i] - min_b)
	print(ans)


tests = int(input())
contador = 0
for i in range(0, tests):
	gifts = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	minimo_candies = min(candies)
	minimo_oranges = min(oranges)
	maximomovimiento = 0
	for j in range(0, gifts):
		maximomovimiento += max(candies[j] - minimo_candies, oranges[j] - minimo_oranges)
	print(maximomovimiento)


def fixequalgift(n, a, b):
	(mina, minb) = (min(a), min(b))
	move = 0
	for i in range(n):
		if a[i] > mina:
			if b[i] > minb:
				if a[i] - mina > b[i] - minb:
					move += a[i] - mina
				elif a[i] - mina < b[i] - minb:
					move += b[i] - minb
				else:
					move += a[i] - mina
			else:
				move += a[i] - mina
		elif b[i] > minb:
			move += b[i] - minb
	print(move)
for i in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	fixequalgift(n, c, o)


t = int(input())

def fix(param1, param2):
	(i, j, k) = (0, 0, 0)
	if param1 > a_min and param2 > b_min:
		look = min(param1 - a_min, param2 - b_min)
		(param1, param2) = (param1 - look, param2 - look)
		k = k + look
	if param1 > a_min:
		i = param1 - a_min
	elif param2 > b_min:
		i = param2 - b_min
	return i + j + k
for _ in range(t):
	found = 0
	n = int(input())
	(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
	(a_min, b_min) = (sorted(a)[0], sorted(b)[0])
	for inx in range(len(a)):
		found = found + fix(a[inx], b[inx])
	print(found)


for i in range(int(input())):
	n = int(input())
	s = 0
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aa = min(a)
	bb = min(b)
	for i in range(n):
		s += max(a[i] - aa, b[i] - bb)
	print(s)


n = int(input())
for i in range(0, n):
	o = int(input())
	p = input().rstrip().split(' ')
	q = input().rstrip().split(' ')
	L = []
	Q = []
	for j in range(0, len(p)):
		L.append(int(p[j]))
	for j in range(0, len(q)):
		Q.append(int(q[j]))
	A = min(L)
	B = min(Q)
	W = []
	E = []
	for j in range(0, len(L)):
		if L[j] != A:
			W.append(L[j] - A)
		else:
			W.append(0)
	for j in range(0, len(Q)):
		T = Q[j] - B
		if Q[j] != B:
			E.append(T)
		else:
			E.append(0)
	S = 0
	for j in range(0, len(W)):
		S += min(W[j], E[j]) + (max(W[j], E[j]) - min(W[j], E[j]))
	print(S)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	mini1 = min(a)
	mini2 = min(b)
	ans = 0
	for i in range(0, len(a)):
		if abs(a[i] - mini1) == abs(b[i] - mini2):
			ans += abs(a[i] - mini1)
		elif abs(a[i] - mini1) > abs(b[i] - mini2):
			ans += abs(b[i] - mini2)
			ans += abs(a[i] - mini1) - abs(b[i] - mini2)
		else:
			ans += abs(a[i] - mini1)
			ans += abs(b[i] - mini2) - abs(a[i] - mini1)
	print(ans)


def solve():
	sum = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	for i in range(n):
		if a[i] > ma and b[i] > mb:
			de = min(a[i] - ma, b[i] - mb)
			sum += de
			sum += a[i] - ma - de if a[i] - de > ma else b[i] - mb - de
		else:
			sum += a[i] - ma + b[i] - mb
	print(sum)
for _ in range(int(input())):
	solve()


t = int(input(''))
for l in range(t):
	n = int(input(''))
	a = list(map(int, input('').strip().split()))[:n]
	b = list(map(int, input('').strip().split()))[:n]
	a1 = min(a)
	b1 = min(b)
	coun = 0
	for i in range(n):
		if a[i] > a1 and b[i] > b1:
			r1 = abs(a[i] - a1)
			r2 = abs(b[i] - b1)
			if r1 == r2:
				coun += r1
			elif r1 > r2:
				coun += r2
				coun += r1 - r2
			else:
				coun += r1
				coun += r2 - r1
		elif a[i] > a1:
			r1 = abs(a[i] - a1)
			coun += r1
		elif b[i] > b1:
			r2 = abs(b[i] - b1)
			coun += r2
	print(coun)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		if a[i] > amin and b[i] > bmin:
			d1 = a[i] - amin
			d2 = b[i] - bmin
			d = min(d1, d2)
			ans += d
			ans += max(d1 - d, d2 - d)
		elif a[i] == amin:
			d = b[i] - bmin
			ans += d
		elif b[i] == bmin:
			d = a[i] - amin
			ans += d
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	sum1 = 0
	for num in range(n):
		sum1 += max(a[num] - x, b[num] - y)
	print(sum1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	val = 0
	for j in range(n):
		mini = min(a[j] - mina, b[j] - minb)
		val += mini
		a[j] -= mini
		b[j] -= mini
		if a[j] != mina:
			val += a[j] - mina
		elif b[j] != minb:
			val += b[j] - minb
	print(val)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	if n == 1:
		print(0)
	else:
		min_a = min(a)
		min_b = min(b)
		diff_a = []
		diff_b = []
		for i in a:
			diff_a.append(i - min_a)
		for i in b:
			diff_b.append(i - min_b)
		ans = 0
		for i in range(len(a)):
			ans += max(diff_a[i], diff_b[i])
		print(ans)
	t -= 1


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		N = int(input())
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		mina = min(A)
		minb = min(B)
		ans = 0
		for (a, b) in zip(A, B):
			a_ = a - mina
			b_ = b - minb
			ans += min(a_, b_) + abs(a_ - b_)
		print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	m1 = min(arr1)
	m2 = min(arr2)
	ans = 0
	for i in range(n):
		ans += min(arr1[i] - m1 + arr2[i] - m2, max(arr1[i] - m1, arr2[i] - m2))
	print(ans)


T = int(input())
while T > 0:
	n = int(input())
	line = input().split(' ')
	A = []
	B = []
	minA = 10 ** 9
	minB = 10 ** 9
	for a in line:
		A.append(int(a))
		minA = min(int(a), minA)
	line = input().split(' ')
	for b in line:
		B.append(int(b))
		minB = min(int(b), minB)
	C = []
	Ta = 0
	Tb = 0
	Tc = 0
	for i in range(0, n):
		xA = A[i] - minA
		xB = B[i] - minB
		Ta += xA
		Tb += xB
		if xA > 0 and xB > 0:
			Tc += min(xA, xB)
	print(Ta + Tb - Tc)
	T -= 1


import sys
input = sys.stdin.readline

def solve(n, a, b):
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(n):
		while min_a != a[i] or min_b != b[i]:
			if a[i] > min_a and b[i] > min_b:
				eat = min(a[i] - min_a, b[i] - min_b)
				a[i] -= eat
				b[i] -= eat
				count += eat
			elif a[i] > min_a:
				eat = a[i] - min_a
				a[i] -= eat
				count += eat
			else:
				eat = b[i] - min_b
				b[i] -= eat
				count += eat
	return count
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(n, a, b))


t = int(input())
ans = [0] * t

def cal():
	n = int(input())
	a = [0] * n
	b = [0] * n
	count = 0
	am = 1000000000
	bm = 1000000000
	a1 = input().split(' ')
	b1 = input().split(' ')
	for i in range(n):
		(a[i], b[i]) = (int(a1[i]), int(b1[i]))
		am = min(am, a[i])
		bm = min(bm, b[i])
	for i in range(n):
		count += max(a[i] - am, b[i] - bm)
	return count
for i in range(t):
	ans[i] = cal()
for i in range(t):
	print(ans[i])


from collections import defaultdict as dfd
import math
import sys
import heapq

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def main():
	for _ in range(int(input())):
		N = II()
		A = LI()
		B = LI()
		a = min(A)
		b = min(B)
		val = 0
		for i in range(N):
			if A[i] == a and B[i] == b:
				continue
			else:
				vap = A[i] - a
				var = B[i] - b
				val += min(vap, var)
				val += max(vap, var) - min(vap, var)
		print(val)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	a = min(arr1)
	b = min(arr2)
	ans = 0
	for i in range(n):
		ans += max(arr1[i] - a, arr2[i] - b)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	ls1 = [int(a) for a in input().split()]
	ls2 = [int(a) for a in input().split()]
	(mn1, mn2) = (min(ls1), min(ls2))
	mvs = 0
	for j in range(n):
		mvs += max(ls1[j] - mn1, ls2[j] - mn2)
	print(mvs)


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	min_a = min(a)
	min_b = min(b)
	a_diff = [i - min_a for i in a]
	b_diff = [j - min_b for j in b]
	print(sum([max(a_diff[i], b_diff[i]) for i in range(n)]))


t = int(input())
for _ in range(t):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	mc = min(candy)
	mo = min(orange)
	res = 0
	for i in range(n):
		res += max(candy[i] - mc, orange[i] - mo)
	print(res)


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	count = 0
	for i in range(n):
		if a[i] != mina and b[i] != minb:
			ma = a[i] - mina
			mb = b[i] - minb
			count = count + max(ma, mb)
		else:
			if a[i] != mina:
				count = count + a[i] - mina
			if b[i] != minb:
				count = count + b[i] - minb
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_m = min(a)
	b_m = min(b)
	a = [x - a_m for x in a]
	b = [x - b_m for x in b]
	result = 0
	for (x, y) in zip(a, b):
		result += x + y - min(x, y)
	print(result)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	moves = 0
	for i in range(n):
		if a[i] == min(a) and b[i] == min(b):
			continue
		else:
			moves += max(a[i] - min(a), b[i] - min(b))
	print(moves)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(y) for y in input().split()]
	h = min(a)
	k = min(b)
	count = 0
	for i in range(n):
		d = a[i] - h
		e = b[i] - k
		count += min(d, e) + abs(d - e)
	print(count)


def solve(l1, l2, e):
	min1 = min(l1)
	min2 = min(l2)
	l3 = []
	l4 = []
	l5 = []
	l6 = []
	l7 = []
	for i in range(e):
		l3.append(l1[i] - min1)
		l4.append(l2[i] - min2)
	for i in range(e):
		l5.append(min(l4[i], l3[i]))
		l6.append(max(l4[i], l3[i]))
	for i in range(e):
		l7.append(l6[i] - l5[i])
	print(sum(l7) + sum(l5))
n = int(input())
for i in range(n):
	e = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	solve(l1, l2, e)


import sys
try:
	sys.stdin = open('inputs.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
finally:
	input = sys.stdin.readline
	print = sys.stdout.write
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - mina, b[i] - minb)
	print(str(ans))
	print('\n')


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = 0
	m1 = min(a)
	m2 = min(b)
	for i in range(n):
		p = max(abs(a[i] - m1), abs(b[i] - m2))
		c += p
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a0 = min(a)
	b0 = min(b)
	(s1, s2) = (0, 0)
	c = 0
	for i in range(n):
		if a[i] > a0 and b[i] > b0:
			v = min(a[i] - a0, b[i] - b0)
			c += v
			a[i] -= v
			b[i] -= v
	for i in range(n):
		if a[i] > a0:
			s1 += a[i] - a0
		if b[i] > b0:
			s2 += b[i] - b0
	print(s1 + s2 + c)


t = int(input())
for T in range(t):
	n = int(input())
	ar1 = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	a = min(ar1)
	b = min(ar2)
	count = 0
	for i in range(n):
		count += max(ar1[i] - a, ar2[i] - b, 0)
	print(count)


for i in range(int(input())):
	r = int(input())
	ls1 = list(map(int, input().split()))
	ls2 = list(map(int, input().split()))
	a = min(ls1)
	b = min(ls2)
	count = 0
	for i in range(r):
		count += max(ls1[i] - a, ls2[i] - b)
	print(count)


for _ in range(int(input())):
	num = int(input())
	li1 = [int(i) for i in input().split()]
	li2 = [int(i) for i in input().split()]
	min1 = min(li1)
	min2 = min(li2)
	count = 0
	for i in range(len(li1)):
		num1 = li1[i] - min1
		num2 = li2[i] - min2
		count += max(num1, num2)
	print(count)


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 1000000007

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

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

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

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

def a():
	n = int(input())
	arr = array()
	arr.sort()
	res = 'YES'
	for i in range(1, n):
		if arr[i] != arr[i - 1] and arr[i - 1] + 1 != arr[i]:
			res = 'NO'
			break
	print(res)

def b():
	n = int(input())
	a = array()
	b = array()
	ma = min(a)
	mb = min(b)
	cnt = 0
	for i in range(n):
		if a[i] > ma:
			diff = min(b[i] - mb, a[i] - ma)
			cnt += diff
			a[i] -= diff
			b[i] -= diff
			cnt += a[i] - ma
	for i in range(n):
		cnt += b[i] - mb
	print(cnt)

def c():
	pass
t = int(input())
for _ in range(t):
	b()


from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	n = I()
	a = LI()
	b = LI()
	c = min(a)
	d = min(b)
	ans = 0
	for i in range(n):
		f1 = a[i] - c
		f2 = b[i] - d
		ans += max(f1, f2)
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	s1 = []
	s2 = []
	for i in range(n):
		s1.append(abs(a[i] - mina))
		s2.append(abs(b[i] - minb))
	s = 0
	for i in range(n):
		s += max(s1[i], s2[i])
	print(s)


import sys
from collections import defaultdict
t = 1
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, sys.stdin.readline().strip().split()))
	b = list(map(int, sys.stdin.readline().strip().split()))
	op = 0
	x = min(a)
	y = min(b)
	for j in range(n):
		op += max(a[j] - x, b[j] - y)
	print(op)


a = int(input())
i = 0
bc = []
while i < a:
	b = int(input())
	aa = list(map(int, input().strip().split()))
	ab = list(map(int, input().strip().split()))
	aaa = min(aa)
	aab = min(ab)
	j = 0
	count = 0
	while j < len(aa):
		ba = aa[j] - aaa
		bb = ab[j] - aab
		if ba > bb:
			count += ba
		else:
			count += bb
		j += 1
	bc.append(count)
	i += 1
for each in bc:
	print(each)


t = int(input())
for i in range(t):
	n = int(input())
	l_c = list(map(int, input().split()))
	l_o = list(map(int, input().split()))
	mi_c = min(l_c)
	mi_o = min(l_o)
	cou = 0
	mi = max(mi_o, mi_c)
	for j in range(n):
		if l_c[j] > mi_c and l_o[j] > mi_o:
			cou += max(l_c[j] - mi_c, l_o[j] - mi_o)
		elif l_c[j] > mi_c:
			cou += l_c[j] - mi_c
		elif l_o[j] > mi_o:
			cou += l_o[j] - mi_o
	print(cou)


for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = list(map(int, input().split()))
	(y, x) = (min(d), min(l))
	c = 0
	for i in range(n):
		xx = abs(l[i] - x)
		yy = abs(d[i] - y)
		c = c + max(xx, yy)
	print(c)


for t in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	(x, y) = (min(arr1), min(arr2))
	s = 0
	for i in range(n):
		a = abs(arr1[i] - x)
		b = abs(arr2[i] - y)
		if a == 0:
			s += b
		elif b == 0:
			s += a
		else:
			s += max(a, b)
	print(s)


from collections import Counter
tst = int(input())
t = 1
while t <= tst:
	n = int(input())
	arr = list(map(int, input().split()))
	arr1 = list(map(int, input().split()))
	mn = min(arr)
	mn1 = min(arr1)
	i = 0
	sum = 0
	while i < n:
		p = arr[i] - mn
		q = arr1[i] - mn1
		sum += max(p, q)
		i += 1
	print(sum)
	t += 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(am, bm, ans) = (min(a), min(b), 0)
	for i in range(n):
		(c, d) = (a[i] - am, b[i] - bm)
		ans += max(c, d)
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	s = 0
	for j in range(n):
		s += max(a[j] - am, b[j] - bm)
	print(s)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
from atexit import register
from io import BytesIO
import io
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary_rep(n):
	l = []
	while n > 0:
		l.append(n % 2)
		n = n // 2
	return l
for _ in range(int(input())):
	n = int(input())
	arA = list(map(int, input().split()))
	arB = list(map(int, input().split()))
	minA = min(arA)
	minB = min(arB)
	answer = 0
	for i in range(n):
		answer += max(arA[i] - minA, arB[i] - minB)
	print(answer)


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	mc = min(c)
	mo = min(o)
	min_steps = 0
	i = 0
	while i < n:
		min_steps += max(c[i] - mc, o[i] - mo)
		i += 1
	print(min_steps)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	sum = 0
	for i in range(n):
		if a[i] > mina and b[i] > minb:
			difa = a[i] - mina
			difb = b[i] - minb
			sum += difa + difb
			sum -= min(difa, difb)
		else:
			sum += a[i] - mina
			sum += b[i] - minb
	return sum
for i in range(int(input())):
	print(main())


try:
	t = int(input())
	while t != 0:
		n = int(input())
		arr = list(map(int, input().split()))
		Ab = list(map(int, input().split()))
		popi = []
		f = min(arr)
		g = min(Ab)
		sumi = 0
		for i in range(n):
			sumi += max(abs(arr[i] - f), abs(Ab[i] - g))
		print(sumi)
		t = t - 1
except EOFError:
	print(' ')


T = int(input())
for test in range(T):
	n = int(input())
	f = 0
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = min(a)
	q = min(b)
	ans = 0
	for i in range(n):
		a[i] -= p
		b[i] -= q
		if a[i] > b[i]:
			ans += a[i]
		else:
			ans += b[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	moves = 0
	for i in range(n):
		if a[i] - ma <= b[i] - mb:
			moves += b[i] - mb
		else:
			moves += a[i] - ma
	print(moves)


for i in range(int(input())):
	n = int(input())
	a = [int(y) for y in input().split()]
	b = [int(y) for y in input().split()]
	min_a = min(a)
	min_b = min(b)
	s = 0
	for i in range(n):
		s += max(abs(a[i] - min_a), abs(abs(b[i] - min_b)))
	print(s)


for i in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	(m1, m2) = (min(A), min(B))
	count = 0
	for i in range(len(A)):
		if A[i] > m1 and B[i] > m2:
			count = count + max(A[i] - m1, B[i] - m2)
		elif A[i] > m1 and B[i] == m2:
			count = count + (A[i] - m1)
		elif A[i] == m1 and B[i] > m2:
			count = count + (B[i] - m2)
		else:
			pass
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	ops = 0
	for (xa, xb) in zip(a, b):
		da = xa - ma
		db = xb - mb
		ops += max(da, db)
	print(ops)


import sys
import heapq
import math
from collections import deque
from collections import defaultdict
from collections import Counter
modH = int(10 ** 9) + 7
I = lambda : list(map(int, input().split(' ')))

def PRINT(lst, sep=' '):
	print(sep.join(map(str, lst)))
for _ in range(int(input())):
	n = int(input())
	lst_c = I()
	lst_o = I()
	num_c = min(lst_c)
	num_o = min(lst_o)
	s = 0
	for (candy, orange) in zip(lst_c, lst_o):
		s += min(candy - num_c, orange - num_o) + abs(abs(candy - num_c) - abs(orange - num_o))
	print(s)


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_min = min(a)
	b_min = min(b)
	count = 0
	for i in range(n):
		count += max(a[i] - a_min, b[i] - b_min)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	candy = min(a)
	orange = min(b)
	moves = 0
	for i in range(n):
		moves += min(a[i] - candy, b[i] - orange)
		k = min(a[i] - candy, b[i] - orange)
		a[i] -= k
		b[i] -= k
	for i in range(n):
		if a[i] != candy:
			moves += a[i] - candy
		if b[i] != orange:
			moves += b[i] - orange
	print(moves)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = min(l1)
	m2 = min(l2)
	total = 0
	for i in range(n):
		x = l1[i] - m1
		y = l2[i] - m2
		total += x + y
		if x > 0 and y > 0:
			total -= min(x, y)
	print(total)


for s in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mini = 9999999999
	for i in range(n):
		mini = min(mini, a[i])
	for i in range(n):
		a[i] = a[i] - mini
	mini = 9999999999
	for i in range(n):
		mini = min(mini, b[i])
	for i in range(n):
		b[i] = b[i] - mini
	maxi = 0
	mini = 0
	for i in range(n):
		mini += min(a[i], b[i])
		maxi += max(a[i], b[i]) - min(a[i], b[i])
	print(maxi + mini)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	mincandy = min(a)
	b = [int(i) for i in input().split()]
	minorange = min(b)
	count = 0
	for i in range(n):
		count += max(a[i] - mincandy, b[i] - minorange)
	print(count)


T = int(input())
for _ in range(0, T):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	e1 = min(a)
	e2 = min(b)
	c = 0
	for i in range(0, n):
		t1 = a[i] - e1
		t2 = b[i] - e2
		c += min(t1, t2)
		c += max(t1, t2) - min(t1, t2)
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		if a[i] > min_a and b[i] > min_b:
			temp = min(a[i] - min_a, b[i] - min_b)
			ans += temp
			a[i] -= temp
			b[i] -= temp
		if a[i] > min_a:
			ans += a[i] - min_a
		if b[i] > min_b:
			ans += b[i] - min_b
	print(ans)


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()]
	mna = min(a)
	mnb = min(b)
	ans = 0
	for i in range(n):
		ans += a[i] - mna + b[i] - mnb
		ans -= min(a[i] - mna, b[i] - mnb)
	print(ans)


r = int(input())
for i in range(r):
	l = int(input())
	num1 = input()
	num2 = input()
	list1 = [int(x) for x in num1.split()]
	list2 = [int(x) for x in num2.split()]
	a = min(list1)
	b = min(list2)
	k = 0
	for i in range(l):
		p = 0
		q = 0
		if list1[i] > a:
			p = list1[i] - a
		if list2[i] > b:
			q = list2[i] - b
		g = max(p, q)
		k += g
	print(k)


for tt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	r = 0
	x = min(a)
	y = min(b)
	if len(set(a)) == 1 and len(set(b)) == 1:
		print(0)
	else:
		for i in range(n):
			if a[i] != x and b[i] != y:
				a[i] -= x
				b[i] -= y
				r1 = min(a[i], b[i])
				r2 = max(a[i], b[i]) - r1
				r += r1 + r2
			else:
				if a[i] != x:
					r += a[i] - x
				if b[i] != y:
					r += b[i] - y
		print(r)


T = int(input())
for t in range(T):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	min_a = min(a)
	min_b = min(b)
	move = 0
	for i in range(n):
		if a[i] >= min_a:
			ac = a[i] - min_a
		if b[i] >= min_b:
			bc = b[i] - min_b
		count = max(ac, bc)
		move += count
	print(move)


import sys

def main():
	t = int(input())
	while t > 0:
		n = int(input())
		arr1 = [int(x) for x in input().split()]
		arr2 = [int(x) for x in input().split()]
		min1 = min(arr1)
		min2 = min(arr2)
		ans = 0
		count = 0
		for i in range(n):
			if arr1[i] == min1 and arr2[i] == min2:
				continue
			elif arr1[i] == min1:
				count += arr2[i] - min2
			elif arr2[i] == min2:
				count += arr1[i] - min1
			elif arr1[i] - min1 <= arr2[i] - min2:
				x = arr1[i] - min1
				count += x
				count += arr2[i] - x - min2
			else:
				x = arr2[i] - min2
				count += x
				count += arr1[i] - x - min1
		print(count)
		t -= 1
main()


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mna = min(a)
	mnb = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - mna, b[i] - mnb)
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = 1000000000.0
	mb = 1000000000.0
	for i in range(n):
		ma = min(ma, a[i])
		mb = min(mb, b[i])
	x = []
	y = []
	z = []
	for i in range(n):
		z.append(max(a[i] - ma, b[i] - mb))
	ans = 0
	for x in z:
		ans += x
	print(int(ans))


n = int(input())
N = {}
candle = []
orange = []
for i in range(n):
	N[i] = int(input())
	candle += [list(map(int, input().split()))]
	orange += [list(map(int, input().split()))]
for i in range(n):
	moves = 0
	minc = min(candle[i])
	mino = min(orange[i])
	c = list(map(lambda x: x - minc, candle[i]))
	o = list(map(lambda x: x - mino, orange[i]))
	out = list(zip(c, o))
	out = list(map(lambda x: max(x), out))
	moves = sum(out)
	print(moves)


t = int(input())
k = [0]
for i in range(0, t, 1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	d = min(b)
	for j in range(0, n, 1):
		while a[j] > c or b[j] > d:
			if a[j] > c and b[j] > d:
				m = min(a[j] - c, b[j] - d)
				k[i] += m
				b[j] -= m
				a[j] -= m
			elif a[j] > c:
				k[i] += a[j] - c
				a[j] -= a[j] - c
			elif b[j] > d:
				k[i] += b[j] - d
				b[j] -= b[j] - d
	k.append('ggg')
	k[i + 1] = 0
for i in range(0, t, 1):
	print(k[i])


t = int(input())
a = [[]] * t
b = [[]] * t
for i in range(t):
	n = int(input())
	a[i] = list(map(int, input().strip().split()))[:n]
	b[i] = list(map(int, input().strip().split()))[:n]
for i in range(t):
	ans = 0
	am = min(a[i])
	bm = min(b[i])
	for j in range(len(a[i])):
		ans += max(a[i][j] - am, b[i][j] - bm)
	print(ans)


import sys
t = int(input())
for cases in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().strip().split()))
	b = list(map(int, sys.stdin.readline().strip().split()))
	amin = min(a)
	bmin = min(b)
	cnt = 0
	for i in range(n):
		k1 = a[i] - amin
		k2 = b[i] - bmin
		cnt += min(k1, k2) + abs(k1 - k2)
	sys.stdout.write(str(cnt) + '\n')


t = int(input())
rpta = []
for j in range(t):
	number = int(input())
	count = 0
	first = list(map(int, input().split()))
	second = list(map(int, input().split()))
	min_1 = min(first)
	min_2 = min(second)
	for i in range(number):
		if first[i] > min_1 and second[i] > min_2:
			if first[i] - min_1 > second[i] - min_2:
				count = second[i] - min_2 + count
				first[i] = first[i] - (second[i] - min_2)
				second[i] = min_2
			elif first[i] - min_1 < second[i] - min_2:
				count = first[i] - min_1 + count
				second[i] = second[i] - (first[i] - min_1)
				first[i] = min_1
			else:
				count = first[i] - min_1 + count
				first[i] = min_1
				second[i] = min_2
		if first[i] > min_1:
			count = count + first[i] - min_1
			first[i] = min_1
		if second[i] > min_2:
			count = count + second[i] - min_2
			second[i] = min_2
	rpta.append(count)
for maiden in rpta:
	print(maiden)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_candy = min(a)
	min_oranges = min(b)
	count = 0
	for i in range(n):
		if a[i] != min_candy and b[i] != min_oranges:
			count += max(a[i] - min_candy, b[i] - min_oranges)
		elif a[i] == min_candy and b[i] != min_oranges:
			count += b[i] - min_oranges
		elif a[i] != min_candy and b[i] == min_oranges:
			count += a[i] - min_candy
	print(count)


t = int(input())
for k in range(t):
	res = 0
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	a_f = min(a)
	b_f = min(b)
	for i in range(n):
		if a[i] > a_f and b[i] > b_f:
			res += min(a[i] - a_f, b[i] - b_f)
			if a[i] - a_f == min(a[i] - a_f, b[i] - b_f):
				b[i] -= a[i] - a_f
				res += b[i] - b_f
			else:
				a[i] -= b[i] - b_f
				res += a[i] - a_f
		elif a[i] > a_f:
			res += a[i] - a_f
		else:
			res += b[i] - b_f
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	c = 0
	for i in range(n):
		t1 = a[i] - x
		t2 = b[i] - y
		c += max(t1, t2)
	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()))
	mina = 1000000000
	minb = 1000000000
	counta = []
	countb = []
	for i in range(n):
		if A[i] < mina:
			mina = A[i]
		if B[i] < minb:
			minb = B[i]
	for i in range(n):
		counta.append(A[i] - mina)
		countb.append(B[i] - minb)
	ans = 0
	for i in range(n):
		ans += max(counta[i], countb[i])
	print(ans)


from os import path
import sys
from heapq import heappush, heappop, heapify
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def b(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		b = li()
		x1 = min(a)
		x2 = min(b)
		ans = 0
		for i in range(n):
			x3 = a[i] - x1
			x4 = b[i] - x2
			ans += max(x3, x4)
		print(ans)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


t = int(input())
cases = []
for i in range(0, t):
	n = int(input())
	a_str = str(input())
	b_str = str(input())
	p = {'first': [int(x) for x in a_str.split(' ')], 'second': [int(x) for x in b_str.split(' ')]}
	cases.append(p)
res = []
for P in cases:
	candy = P['first']
	orange = P['second']
	min_candy = min(candy)
	min_orange = min(orange)
	tot = 0
	for i in range(0, len(candy)):
		tot += max(candy[i] - min_candy, orange[i] - min_orange)
	res.append(tot)
for r in res:
	print(r)


def f(a, b):
	a_min = min(a)
	b_min = min(b)
	moves = 0
	for i in range(len(a)):
		if a[i] != a_min and b[i] != b_min:
			(p, q) = (a[i], b[i])
			if p - a_min > q - b_min:
				moves += p - a_min
			else:
				moves += q - b_min
		elif a[i] == a_min and b[i] != b_min:
			moves += b[i] - b_min
		elif a[i] != a_min and b[i] == b_min:
			moves += a[i] - a_min
		else:
			pass
	return moves
results = []
t = int(input())
for num in range(t):
	n = int(input())
	arr_a = input()
	arr_b = input()
	if n != 1:
		arr_a = arr_a.split()
		a = [int(x) for x in arr_a]
		arr_b = arr_b.split()
		b = [int(x) for x in arr_b]
		results.append(f(a, b))
	else:
		a = int(arr_a)
		b = int(arr_b)
		results.append(0)
for elem in results:
	print(elem)


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(' ')]
	am = min(a)
	bm = min(b)
	c = 0
	for i in range(n):
		if a[i] > am and b[i] > bm:
			d = min(a[i] - am, b[i] - bm)
			c = c + d
			a[i] = a[i] - d
			b[i] = b[i] - d
		if a[i] > am:
			c = c + (a[i] - am)
			a[i] = am
		if b[i] > bm:
			c = c + (b[i] - bm)
			b[i] = bm
	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()))
	p = min(a)
	q = min(b)
	l = 0
	z = 0
	for j in range(n):
		l += a[j] + b[j] - (p + q)
		if a[j] > p and b[j] > q:
			x = a[j] - p
			y = b[j] - q
			z += min(x, y)
	print(l - z)


import sys
input = sys.stdin.buffer.readline
from math import *
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	mina = min(arr)
	brr = list(map(int, input().split()))
	minb = min(brr)
	ans = 0
	for i in range(n):
		c = arr[i] - mina
		d = brr[i] - minb
		ans += max(c, d)
	print(ans)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A_min = min(A)
	B_min = min(B)
	ans = 0
	for i in range(N):
		A_diff = A[i] - A_min
		B_diff = B[i] - B_min
		cnt = max(A_diff, B_diff)
		ans += cnt
	print(ans)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	miniA = a[0]
	miniB = b[0]
	res = 0
	for i in a:
		miniA = min(miniA, i)
	for i in b:
		miniB = min(miniB, i)
	for i in range(n):
		res += max(a[i] - miniA, b[i] - miniB)
	print(res)
	t -= 1


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	x = min(lst1)
	y = min(lst2)
	z = 0
	for i in range(n):
		c1 = 0
		c2 = 0
		a = lst1[i]
		if lst1[i] == x:
			c1 = 0
		else:
			c1 = a - x
		b = lst2[i]
		if lst2[i] == y:
			c2 = 0
		else:
			c2 = b - y
		z = z + max(c1, c2)
	print(z)


t = int(input())
for k in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_candy = min(candies)
	min_oranges = min(oranges)
	moves = 0
	for i in range(n):
		if candies[i] > min_candy and oranges[i] > min_oranges:
			sub = min(candies[i] - min_candy, oranges[i] - min_oranges)
			candies[i] -= sub
			oranges[i] -= sub
			moves += sub
		if candies[i] > min_candy:
			moves += candies[i] - min_candy
		if oranges[i] > min_oranges:
			moves += oranges[i] - min_oranges
	print(moves)


t = int(input())
for _ in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	minarr1 = min(arr1)
	minarr2 = min(arr2)
	cnt = 0
	for i in range(n):
		if arr1[i] == minarr1 and arr2 == minarr2:
			continue
		elif arr1[i] == minarr1 and arr2 != minarr2:
			cnt = cnt + arr2[i] - minarr2
		elif arr1[i] != minarr1 and arr2 == minarr2:
			cnt = cnt + arr1[i] - minarr1
		else:
			x = arr1[i] - minarr1
			y = arr2[i] - minarr2
			cnt = cnt + max(x, y)
	print(cnt)


def back(a, b, n):
	amn = min(a)
	bmn = min(b)
	(i, j) = (0, 0)
	c = 0
	while i < n and j < n:
		xai = a[i] - amn
		xbi = b[j] - bmn
		c += min(xai, xbi)
		c += abs(xai - xbi)
		i += 1
		j += 1
	return c
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(back(a, b, n))


t = int(input())
while t != 0:
	n = int(input())
	arr = [int(x) for x in input().split()]
	brr = [int(x) for x in input().split()]
	min1 = min(arr)
	min2 = min(brr)
	count = 0
	for i in range(0, len(arr), 1):
		ans1 = abs(arr[i] - min1)
		ans2 = abs(brr[i] - min2)
		count += max(ans1, ans2)
	print(count)
	t = t - 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	c = 0
	for i in range(n):
		l1 = a[i] - m1
		l2 = b[i] - m2
		if l1 >= l2:
			c = c + l1
		else:
			c = c + l2
	print(c)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	mna = min(a)
	b = list(map(int, input().split()))
	mnb = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - mna, b[i] - mnb)
	print(ans)
	t -= 1


t = int(input())
n = [0] * t
a = [0] * t
b = [0] * t
for i in range(t):
	n[i] = int(input())
	a[i] = [0] * n[i]
	b[i] = [0] * n[i]
	a[i] = list(map(int, input().split()))
	b[i] = list(map(int, input().split()))
for j in range(t):
	z = min(a[j])
	x = min(b[j])
	c = 0
	for i in range(n[j]):
		while a[j][i] != z and b[j][i] != x:
			m = min(a[j][i] - z, b[j][i] - x)
			c += m
			a[j][i] -= m
			b[j][i] -= m
		while a[j][i] != z:
			c += a[j][i] - z
			a[j][i] = z
		while b[j][i] != x:
			c += b[j][i] - x
			b[j][i] = x
	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()))
	ans = 0
	for m in range(0, n):
		a = A[m] - min(A)
		b = B[m] - min(B)
		if a >= b:
			ans += a
		else:
			ans += b
	print(ans)


def max_arr(a, b):
	if a > b:
		return a
	else:
		return b

def min_arr(arr, n):
	min_temp = arr[0]
	for i in range(n - 1):
		if min_temp > arr[i + 1]:
			min_temp = arr[i + 1]
	return min_temp
t = int(input())
for i in range(t):
	n = int(input())
	input_string_a = input()
	input_string_b = input()
	input_data_a = input_string_a.split(' ')
	input_data_b = input_string_b.split(' ')
	a = [int(x) for x in input_data_a]
	b = [int(x) for x in input_data_b]
	moves = 0
	min_of_a = min_arr(a, n)
	min_of_b = min_arr(b, n)
	for k in range(n):
		temp_moves = max_arr(a[k] - min_of_a, b[k] - min_of_b)
		moves = moves + temp_moves
	print(moves)


def solution(arr1, arr2):
	ans1 = min(arr1)
	ans2 = min(arr2)
	count = 0
	for i in range(len(arr1)):
		val1 = arr1[i] - ans1
		val2 = arr2[i] - ans2
		count = count + max(val1, val2)
	return count
for _ in range(int(input())):
	n = int(input())
	arr1 = [int(x) for x in input().split()]
	arr2 = [int(x) for x in input().split()]
	print(solution(arr1, arr2))


t = int(input())
ans = 0
for i in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	ma = min(a)
	mb = min(b)
	for k in range(n):
		if a[k] > ma and b[k] > mb:
			mx = max(a[k] - ma, b[k] - mb)
			ans += mx
		elif a[k] > ma:
			ans += a[k] - ma
		elif b[k] > mb:
			ans += b[k] - mb
	print(ans)
	ans = 0


T = int(input())
while T:
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	minA = min(a)
	minB = min(b)
	minMoves = 0
	for i in range(n):
		minMoves += min(a[i] - minA, b[i] - minB) + (a[i] - min(a[i] - minA, b[i] - minB) - minA) + (b[i] - min(a[i] - minA, b[i] - minB) - minB)
	print(minMoves)
	T -= 1


T = int(input())
for z in range(T):
	N = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	amin = min(a)
	bmin = min(b)
	sum = 0
	for i in range(N):
		areq = a[i] - amin
		breq = b[i] - bmin
		sum = sum + max(areq, breq)
	print(sum)


from sys import *
t = int(stdin.readline())
while t > 0:
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	brr = list(map(int, stdin.readline().split()))
	ans = 0
	f = min(arr)
	s = min(brr)
	for i in range(n):
		arr[i] -= f
		brr[i] -= s
	for i in range(n):
		ans += max(arr[i], brr[i])
	print(ans)
	t -= 1


def findNumMoves(n, a, b):
	mina = min(a)
	minb = min(b)
	moves = 0
	for i in range(n):
		if a[i] > mina and b[i] > minb:
			minq = min(a[i] - mina, b[i] - minb)
			a[i] -= minq
			b[i] -= minq
			moves += minq
		if a[i] > mina:
			moves += a[i] - mina
		if b[i] > minb:
			moves += b[i] - minb
	return moves
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(findNumMoves(n, a, b))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 0
	j = min(a)
	jj = min(b)
	ss = 0
	sss = 0
	for i in range(n):
		if a[i] > j:
			ss = a[i] - j
		if b[i] > jj:
			sss = b[i] - jj
		s += max(ss, sss)
		ss = 0
		sss = 0
	print(s)


for _ in [0] * int(input()):
	n = int(input())
	arr1 = [int(a) for a in input().split()]
	arr2 = [int(b) for b in input().split()]
	tar1 = min(arr1)
	tar2 = min(arr2)
	ans = 0
	for i in range(n):
		ans += max(abs(tar1 - arr1[i]), abs(tar2 - arr2[i]))
	print(ans)


for i in range(int(input())):
	count = 0
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	c1 = min(x)
	c2 = min(y)
	for i in range(len(x)):
		count = count + max(x[i] - c1, y[i] - c2)
	print(count)


import io, os, math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
rr = lambda : input()
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))
INF = float('inf')

def solve(N, A, B):
	targetA = min(A)
	targetB = min(B)
	ops = 0
	for (ga, gb) in zip(A, B):
		diffA = ga - targetA
		diffB = gb - targetB
		ops += max(diffA, diffB)
	return ops
t = rri()
for _ in range(t):
	N = rri()
	A = rrm()
	B = rrm()
	print(solve(N, A, B))


from collections import defaultdict

def moves(nums1, nums2):
	min1 = min(nums1)
	min2 = min(nums2)
	res = 0
	for i in range(len(nums1)):
		res += max(nums1[i] - min1, nums2[i] - min2, 0)
	return res

def solve():
	_ = input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	return moves(a, b)
t = int(input())
for _ in range(t):
	print(solve())


t = int(input())
for t1 in range(t):
	n = int(input())
	a = [int(n1) for n1 in input().split()]
	b = [int(n1) for n1 in input().split()]
	count = 0
	for i in range(len(a)):
		c = a[i] - min(a)
		d = b[i] - min(b)
		if c == 0 or d == 0:
			count = count + max(c, d)
		else:
			count = count + min(c, d) + max(c, d) - min(c, d)
	print(count)


def solve(n, arr, brr):
	mc = min(arr)
	mo = min(brr)
	count = 0
	for i in range(n):
		a = arr[i] - mc
		b = brr[i] - mo
		count = count + max(a, b)
	return count
t = int(input())
for i in range(t):
	n = input()
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	result = solve(int(n), arr, brr)
	print(result)


t = int(input())
ii = 0
while ii < t:
	n = int(input())
	a = input().split()
	b = input().split()
	i = 0
	while i < n:
		a[i] = int(a[i])
		b[i] = int(b[i])
		i = i + 1
	i = 0
	min_a = a[0]
	min_b = b[0]
	while i < n:
		if a[i] < min_a:
			min_a = a[i]
		if b[i] < min_b:
			min_b = b[i]
		i += 1
	r = 0
	l = 0
	p = 0
	i = 0
	while i < n:
		r = a[i] - min_a
		l = b[i] - min_b
		if r <= l:
			p += l - r + r
		else:
			p += r - l + l
		i = i + 1
	print(p)
	ii += 1


import sys
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	a1 = min(a)
	b1 = min(b)
	ans = 0
	for i in range(n):
		f1 = 0
		f2 = 0
		if a[i] > a1:
			f1 = a[i] - a1
		if b[i] > b1:
			f2 = b[i] - b1
		z = min(f1, f2)
		ans += z
		f1 -= z
		f2 -= z
		ans += f1 + f2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	cnt = 0
	for i in range(n):
		p = a[i] - x
		q = b[i] - y
		cnt += max(p, q)
	print(cnt)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	minimum_a = min(a)
	minimum_b = min(b)
	for i in range(n):
		num_1 = a[i] - minimum_a
		num_2 = b[i] - minimum_b
		res = max(num_1, num_2)
		count += res
	print(count)


t = int(input())
while t:
	t -= 1
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	p1 = 0
	p2 = 0
	cnt = 0
	mx = min(ar)
	my = min(br)
	while p1 < n and p2 < n:
		x = abs(ar[p1] - mx)
		y = abs(br[p2] - my)
		if x > y:
			cnt += x
		else:
			cnt += y
		p1 += 1
		p2 += 1
	print(cnt)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	a = I()
	b = I()
	(x, y) = (min(a), min(b))
	an = 0
	for i in range(n):
		an += max(a[i] - x, b[i] - y)
	print(an)


t = int(input())
for _ in range(t):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	x = min(candy)
	y = min(orange)
	total = 0
	for i in range(n):
		total += max(candy[i] - x, orange[i] - y)
	print(total)


n = int(input())
g = []
for i in range(n):
	g.append([0, 0])
	j = int(input())
	g[i][0] = (0 for k in range(j))
	g[i][0] = list(map(int, input().split()))
	g[i][1] = (0 for k in range(j))
	g[i][1] = list(map(int, input().split()))
for i in range(n):
	sum = 0
	ma = int(min(g[i][0]))
	mb = int(min(g[i][1]))
	for j in range(len(g[i][0])):
		a = g[i][0][j] - ma
		b = g[i][1][j] - mb
		sum += max(a, b)
	print(sum)


T = int(input())

def solve(a, b):
	ans = 0
	(ma, mb) = (min(a), min(b))
	for i in range(0, len(a)):
		ea = a[i]
		eb = b[i]
		d = min(ea - ma, eb - mb)
		ans += d
		ea = ea - d
		eb = eb - d
		ans += ea - ma + (eb - mb)
	print(ans)
while T > 0:
	n = int(input())
	a = [int(el) for el in input().split(' ')]
	b = [int(el) for el in input().split(' ')]
	solve(a, b)
	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_min = min(a)
	b_min = min(b)
	res = 0
	for i in a:
		res += i - a_min
	for i in b:
		res += i - b_min
	for (i, j) in zip(a, b):
		res -= min(abs(i - a_min), abs(j - b_min))
	print(res)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	Min = min(a)
	Min1 = min(b)
	count = 0
	for i in range(n):
		k = a[i] - Min
		kk = b[i] - Min1
		count += max(k, kk)
	print(count)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	o = list(map(int, input().split()))
	lm = min(l)
	om = min(o)
	cnt = 0
	for i in range(len(o)):
		d1 = l[i] - lm
		d2 = o[i] - om
		cnt = cnt + max(d1, d2)
	print(cnt)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ma = min(a)
	b = list(map(int, input().split()))
	mb = min(b)
	l = [max(a[i] - ma, b[i] - mb) for i in range(n)]
	print(sum(l))


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	c = 0
	d = min(l1)
	e = min(l2)
	for j in range(n):
		a = l1[j] - d
		b = l2[j] - e
		c = c + max(a, b)
	print(c)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	(ma, mb) = (min(l1), min(l2))
	ans = 0
	for i in range(len(l1)):
		(x1, x2) = (l1[i] - ma, l2[i] - mb)
		ans += max(x1, x2)
	print(ans)


a = input()
for x in range(int(a)):
	c = int(input())
	d = input().split(' ')
	f = input().split(' ')
	list1 = [int(i) for i in d]
	list2 = [int(i) for i in f]
	ans = 0
	for i in range(len(list1)):
		tag = list1[i] - min(list1)
		tag1 = list2[i] - min(list2)
		ans += max(tag, tag1)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	c = 0
	for i in range(n):
		if a[i] > am and b[i] > bm:
			x = a[i] - am
			y = b[i] - bm
			c += max(x, y)
		elif a[i] > am:
			c += a[i] - am
		elif b[i] > bm:
			c += b[i] - bm
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	c1 = min(b)
	c2 = min(c, c1)
	ans = 0
	for i in range(n):
		ans = ans + max(abs(a[i] - c), abs(b[i] - c1))
	print(ans)


from collections import defaultdict, Counter
from math import log, ceil, floor

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	ans = 0
	for i in range(n):
		ans1 = a[i] - am
		ans2 = b[i] - bm
		ans += max(ans1, ans2)
	print(ans)
t = 1
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	b = list(map(int, input().strip().split(' ')))
	(x, y) = ([], [])
	for i in range(n):
		x.append(abs(a[i] - min(a)))
	for j in range(n):
		y.append(abs(b[j] - min(b)))
	z = 0
	for i in range(n):
		z += max(x[i], y[i])
	print(z)


def gift_fix(candies: list, oranges: list) -> int:
	ans = 0
	for i in range(len(oranges)):
		ans += max(oranges[i] - min(oranges), candies[i] - min(candies))
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	oranges = [int(x) for x in input().split()]
	candies = [int(x) for x in input().split()]
	print(gift_fix(candies, oranges))


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	min_a = int(min(A))
	min_b = int(min(B))
	ans = 0
	for i in range(n):
		ans += max(A[i] - min_a, B[i] - min_b)
	print(ans)


import sys
for bruh in range(0, int(sys.stdin.readline())):
	leng = int(sys.stdin.readline())
	appel = list(map(int, sys.stdin.readline().split()))
	orang = list(map(int, sys.stdin.readline().split()))
	minap = min(appel)
	minor = min(orang)
	out = 0
	for i in range(0, leng):
		out += max([appel[i] - minap, orang[i] - minor])
	sys.stdout.write(str(out) + '\n')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	moves = 0
	for gift in range(n):
		a_dif = a[gift] - a_min
		b_dif = b[gift] - b_min
		moves += max(a_dif, b_dif)
	print(moves)


import sys, os, io

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

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

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

def ws(s):
	sys.stdout.write(s + '\n')

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import deque, defaultdict
for _ in range(ri()):
	n = ri()
	x = ria()
	a = min(x)
	y = ria()
	b = min(y)
	cnt = 0
	for i in range(n):
		p = x[i] - a
		q = y[i] - b
		cnt = cnt + p + q - min(p, q)
	wi(cnt)


test_cases = int(input())
for test_case in range(test_cases):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		if a[i] != amin and b[i] != bmin:
			x = min(a[i] - amin, b[i] - bmin)
			ans += x
			a[i] -= x
			b[i] -= x
	a.sort()
	b.sort()
	for i in range(n):
		if a[i] != a[0]:
			ans += a[i] - a[0]
		if b[i] != b[0]:
			ans += b[i] - b[0]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	ar1 = [int(a) for a in input().strip().split(' ')]
	ar2 = [int(a) for a in input().strip().split(' ')]
	m1 = min(ar1)
	m2 = min(ar2)
	c = 0
	for i in range(n):
		(x, y) = (ar1[i], ar2[i])
		if x != m1 and y != m2:
			c += max(x - m1, y - m2)
		if x != m1 and y == m2:
			c += x - m1
		if x == m1 and y != m2:
			c += y - m2
		if x == m1 and y == m2:
			pass
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_a = sorted(candies)[0]
	min_b = sorted(oranges)[0]
	answer = 0
	for i in range(n):
		answer += max(candies[i] - min_a, oranges[i] - min_b)
	print(answer)


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()]
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		xa = a[i] - ma
		xb = b[i] - mb
		c += max(xa, xb)
	print(c)


ans = []
for _ in range(int(input())):
	moves = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	for i in range(n):
		moves += max(a[i] - am, b[i] - bm)
	ans.append(moves)
for __ in ans:
	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()
	mna = 10000000000.0
	mnb = 10000000000.0
	for i in range(n):
		mna = min(mna, a[i])
		mnb = min(mnb, b[i])
	ans = 0
	for i in range(n):
		ans += min(a[i] - mna, b[i] - mnb) + max(a[i] - min(a[i] - mna, b[i] - mnb) - mna, b[i] - min(a[i] - mna, b[i] - mnb) - mnb)
	print(ans)


def method():
	n = int(input())
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	min1 = min(a1)
	min2 = min(a2)
	moves = 0
	for i in range(n):
		x = a1[i] - min1
		y = a2[i] - min2
		if x < y:
			(x, y) = (y, x)
		if x > 0 and y > 0:
			x -= y
			moves = moves + y
		if x > 0:
			moves = moves + x
	print(moves)
m = int(input())
while m:
	method()
	m -= 1


n = int(input())
while n > 0:
	t = int(input())
	m = list(map(int, input().split()))
	k = list(map(int, input().split()))
	x = min(m)
	y = min(k)
	res = 0
	for i in range(t):
		diff_x = m[i] - x
		diff_y = k[i] - y
		res += max(diff_x, diff_y)
	n -= 1
	print(res)


t = int(input().strip())
while t > 0:
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	(m_a, m_b) = (min(a), min(b))
	res = 0
	for i in range(n):
		(x, y) = (a[i], b[i])
		z = min(x - m_a, y - m_b)
		res += z + (x - z - m_a) + (y - z - m_b)
	print(res)
	t -= 1


def findgift(arr1, arr2):
	a = min(arr1)
	b = min(arr2)
	count = 0
	for i in range(len(arr1)):
		if arr1[i] == a:
			count = count + (arr2[i] - b)
		elif arr1[i] > a:
			ex = arr1[i] - a
			ex1 = arr2[i] - b
			w = min(ex, ex1)
			if w == 0:
				count += arr1[i] - a
			else:
				ext = arr1[i] - w
				ext1 = arr2[i] - w
				count = count + w
				count = count + (ext - a)
				count = count + (ext1 - b)
	return count
n = int(input())
for i in range(n):
	t = int(input())
	arr1 = [int(i) for i in input().split()]
	arr2 = [int(i) for i in input().split()]
	print(findgift(arr1, arr2))


T = int(input())
for i in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	d = min(a)
	e = min(b)
	for i in range(len(a)):
		if a[i] > d and b[i] > e:
			k = min(a[i] - d, b[i] - e)
			c += k
			a[i] -= k
			b[i] -= k
			if a[i] != d:
				c += a[i] - d
			elif b[i] != e:
				c += b[i] - e
		elif a[i] > d and b[i] == e:
			c += a[i] - d
		elif b[i] > e and a[i] == d:
			c += b[i] - e
	print(c)


for t in range(int(input())):
	p = int(input())
	k = list(map(int, input().split()))
	a = list(map(int, input().split()))
	ek = min(k)
	ea = min(a)
	r = 0
	for i in range(p):
		r += max(k[i] - ek, a[i] - ea)
	print(r)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = []
	y = []
	ans = []
	for i in range(n):
		x.append(a[i] - min(a))
		y.append(b[i] - min(b))
	for i in range(n):
		ans.append(max(x[i], y[i]))
	print(sum(ans))


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ma = min(a)
	mb = min(b)
	count = 0
	for i in range(n):
		mi = min(a[i] - ma, b[i] - mb)
		a[i] -= mi
		b[i] -= mi
		count += mi
		count += a[i] - ma
		count += b[i] - mb
	print(count)


import math
import os
import random
import re
import string
from sys import *
from collections import *

def bs(arr, x, l, r):
	if l <= r:
		mid = (r + l) // 2
		if arr[mid] == x:
			return mid
		elif arr[md] > x:
			return bs(arr, x, l, mid - 1)
		else:
			return bs(arr, x, mid + 1, r)
	else:
		return -1

def solve():
	for _ in range(int(stdin.readline())):
		n = int(stdin.readline())
		l1 = list(map(int, stdin.readline().strip().split()))
		l2 = list(map(int, stdin.readline().strip().split()))
		mi1 = min(l1)
		mi2 = min(l2)
		c = 0
		for i in range(n):
			if l1[i] > mi1 and l2[i] > mi2:
				mi = min(l1[i] - mi1, l2[i] - mi2)
				l1[i] -= mi
				l2[i] -= mi
				c += mi
			if l1[i] > mi1 and l2[i] == mi2:
				c += l1[i] - mi1
			if l1[i] == mi1 and l2[i] > mi2:
				c += l2[i] - mi2
		print(c)
solve()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	c = 0
	for j in range(n):
		c += max(a[j] - a1, b[j] - b1)
	print(c)


for testcases in range(int(input())):
	num = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	temp1 = min(a)
	temp2 = min(b)
	for x in range(num):
		ans = ans + max(a[x] - temp1, b[x] - temp2)
	print(ans)


moveT = []
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	ma = min(a)
	mb = min(b)
	moves = 0
	for i in range(n):
		moves = moves + max(a[i] - ma, b[i] - mb)
	moveT.append(moves)
for m in moveT:
	print(m)


for _ in range(int(input())):
	n = int(input())
	candies = [int(x) for x in input().split()]
	oranges = [int(x) for x in input().split()]
	min_c = min(candies)
	min_o = min(oranges)
	moves = 0
	for i in range(n):
		if candies[i] > min_c and oranges[i] > min_o:
			mini = min(candies[i] - min_c, oranges[i] - min_o)
			moves += mini
			candies[i] -= mini
			oranges[i] -= mini
		if candies[i] > min_c:
			moves += candies[i] - min_c
			candies[i] = min_c
		if oranges[i] > min_o:
			moves += oranges[i] - min_o
			candies[i] = min_o
	print(moves)


loop = int(input())
while loop != 0:
	length = int(input())
	candys = input().split()
	oranges = input().split()
	move = 0
	for i in range(length):
		candys[i] = int(candys[i])
		oranges[i] = int(oranges[i])
	(candy, orange) = (min(candys), min(oranges))
	i = 0
	for i in range(length):
		if candys[i] > candy and oranges[i] > orange:
			diff_candy = candys[i] - candy
			diff_orange = oranges[i] - orange
			diff = min(diff_orange, diff_candy)
			candys[i] -= diff
			oranges[i] -= diff
			move += diff
		if candys[i] > candy:
			diff = candys[i] - candy
			candys[i] -= diff
			move += diff
		if oranges[i] > orange:
			diff = oranges[i] - orange
			oranges[i] -= diff
			move += diff
	print(move)
	loop -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	d = 0
	ok = False
	if len(list(set(a))) == 1 and len(list(set(b))) == 1:
		print(0)
		ok = False
	else:
		ma = min(a)
		mb = min(b)
		ok = True
		for i in range(len(a)):
			c += max(a[i] - ma, b[i] - mb)
	if ok:
		print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	o = list(map(int, input().strip().split()))
	keya = min(a)
	keyo = min(o)
	res = 0
	for (i, j) in zip(a, o):
		res += max(i - keya, j - keyo)
	print(res)


def returnMinSequence(arr1, arr2):
	Sum1 = 0
	Sum2 = 0
	FinalSum = 0
	a = min(arr1)
	b = min(arr2)
	for (x, y) in zip(arr1, arr2):
		Sum1 = abs(x - a)
		Sum2 = abs(y - b)
		FinalSum += max(Sum1, Sum2)
	return FinalSum
t = int(input())
for i in range(t):
	n = input()
	arr1 = [int(x) for x in input().split()]
	arr2 = [int(y) for y in input().split()]
	print(returnMinSequence(arr1, arr2))


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		arr1 = list(map(int, input().split()))
		arr2 = list(map(int, input().split()))
		min1 = min(arr1)
		min2 = min(arr2)
		moves = 0
		for i in range(n):
			x = arr1[i] - min1
			y = arr2[i] - min2
			moves += max(x, y)
		print(moves)
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')
inlist = lambda : list(map(int, input().split()))
inmap = lambda : map(int, input().split())
main()


for z in range(int(input())):
	n = int(input())
	swe = [int(x) for x in input().split()]
	ora = [int(x) for x in input().split()]
	swemin = min(swe)
	oramin = min(ora)
	res = 0
	for i in range(n):
		res += max(abs(oramin - ora[i]), abs(swemin - swe[i]))
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	k1 = min(l)
	h1 = min(m)
	a = []
	b = []
	c = 0
	for i in range(n):
		a.append(l[i] - k1)
		b.append(m[i] - h1)
	for i in range(n):
		c += max(a[i], b[i])
	print(c)


n = int(input())
for i in range(n):
	y = int(input())
	x = list(map(int, input().split()))
	z = list(map(int, input().split()))
	s = 0
	for j in range(y):
		s += max(x[j] - min(x), z[j] - min(z))
	print(s)


f = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(f())
	b = list(f())
	mina = min(a)
	minb = min(b)
	m = 0
	for i in range(n):
		if a[i] > mina and b[i] > minb:
			t = min(a[i] - mina, b[i] - minb)
			a[i] -= t
			b[i] -= t
			m += t
		if a[i] > mina:
			m += a[i] - mina
		if b[i] > minb:
			m += b[i] - minb
	print(m)


t = int(input())
for some_num in range(0, t):
	n = int(input())
	c = [int(i) for i in input().split(' ')]
	o = [int(i) for i in input().split(' ')]
	min_c = min(c)
	min_o = min(o)
	cost = 0
	for i in range(0, n):
		cost += max(c[i] - min_c, o[i] - min_o)
	print(cost)


a = int(input())
q1 = []
count = 0
for i in range(a):
	b = int(input())
	c = input().split()
	d = input().split()
	for i1 in range(len(c)):
		c[i1] = int(c[i1])
	for j1 in range(len(d)):
		d[j1] = int(d[j1])
	for l in range(b):
		count += max(c[l] - min(c), d[l] - min(d))
	print(count)
	count = 0


for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	c = 0
	m1 = min(b)
	m2 = min(b1)
	for j in range(0, a):
		c = c + max(b[j] - m1, b1[j] - m2)
	print(c)


for _ in range(int(input())):
	g = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	cm = min(c)
	om = min(o)
	n = 0
	for i in range(g):
		n = n + max(c[i] - cm, o[i] - om)
	print(n)


t = int(input())
for i in range(t):
	a = int(input())
	c = list(map(int, input().split(' ')))
	o = list(map(int, input().split(' ')))
	cmin = min(c)
	omin = min(o)
	c1 = 0
	o1 = 0
	while c1 < len(c) and o1 < len(o):
		d = 0
		for j in range(len(c)):
			while c[j] > cmin or o[j] > omin:
				if c[j] > cmin and o[j] > omin:
					if c[j] - cmin > o[j] - omin:
						x = o[j] - omin
						d = d + x
						o[j] = omin
						c[j] = c[j] - x
					elif c[j] - cmin < o[j] - omin:
						x = c[j] - cmin
						d = d + x
						c[j] = cmin
						o[j] = o[j] - x
					else:
						d = d + c[j] - cmin
						c[j] = cmin
						o[j] = omin
				elif c[j] > cmin:
					x = c[j] - cmin
					c[j] = cmin
					d = d + x
				elif o[j] > omin:
					x = o[j] - omin
					o[j] = omin
					d = d + x
		for j in c:
			if j == c[0]:
				c1 = c1 + 1
			else:
				break
		for j in o:
			if j == o[0]:
				o1 = o1 + 1
			else:
				break
		print(d)


T = int(input())
while T:
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ma = min(A)
	mb = min(B)
	for i in range(n):
		A[i] = A[i] - ma
		B[i] = B[i] - mb
	c = 0
	for i in range(n):
		c = c + max(A[i], B[i])
	print(c)
	T = T - 1


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	minl = min(l)
	minm = min(m)
	count = 0
	for i in range(n):
		if any([l[i] == minl, m[i] == minm]):
			count += l[i] - minl + m[i] - minm
		else:
			count += max(l[i] - minl, m[i] - minm)
	print(count)


test = int(input())
for t in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(n):
		if a[i] > min_a and b[i] > min_b:
			diff_a = abs(a[i] - min_a)
			diff_b = abs(b[i] - min_b)
			if diff_a >= diff_b:
				count += diff_b
				count += diff_a - diff_b
			else:
				count += diff_a
				count += diff_b - diff_a
		else:
			count += a[i] - min_a
			count += b[i] - min_b
	print(count)


for _ in range(0, int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	nin1 = 1000000000
	nin2 = 1000000000
	for i in l1:
		nin1 = min(i, nin1)
	for i in l2:
		nin2 = min(i, nin2)
	ans = 0
	for i in range(0, n):
		t1 = l1[i] - nin1
		t2 = l2[i] - nin2
		ans += max(t1, t2)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	ans = 0
	for i in range(n):
		d1 = a[i] - ma
		d2 = b[i] - mb
		c = min(d1, d2)
		ans += c + (d1 - c) + (d2 - c)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_candies = min(candies)
	min_oranges = min(oranges)
	ans = []
	for u in range(n):
		maxi = max(candies[u] - min_candies, oranges[u] - min_oranges)
		ans.append(maxi)
	print(sum(ans))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	aa = min(a)
	bb = min(b)
	count = 0
	for x in range(n):
		count = count + max(a[x] - aa, b[x] - bb)
	print(count)


t = int(input())
(n, a, b) = ([], [], [])
for i in range(t):
	n.append(int(input()))
	a.append(list(map(int, input().split(' '))))
	b.append(list(map(int, input().split(' '))))
for i in range(t):
	mina = min(a[i])
	minb = min(b[i])
	count = 0
	counta = 0
	countb = 0
	for j in range(n[i]):
		counta = a[i][j] - mina
		countb = b[i][j] - minb
		count += counta + countb - min(counta, countb)
	print(count)


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	m1 = min(arr)
	m2 = min(brr)
	cnt = 0
	for i in range(n):
		if arr[i] > m1 and brr[i] > m2:
			cnt += arr[i] - m1 + brr[i] - m2 - min(arr[i] - m1, brr[i] - m2)
		elif arr[i] > m1:
			cnt += arr[i] - m1
		elif brr[i] > m2:
			cnt += brr[i] - m2
	print(cnt)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	c1 = min(a)
	b = list(map(int, input().strip().split(' ')))
	c2 = min(b)
	c = 0
	for i in range(n):
		if a[i] == c1 and b[i] == c2:
			c += 0
		elif a[i] == c1:
			c += b[i] - c2
		elif b[i] == c2:
			c += a[i] - c1
		else:
			c += max(a[i] - c1, b[i] - c2)
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	p = min(a)
	q = min(b)
	for i in range(n):
		s = a[i] - p
		r = b[i] - q
		ans += min(s, r) + s - min(s, r) + r - min(s, r)
	print(ans)


t = int(input())
for i in range(t):
	g = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sum = 0
	for j in range(g):
		if a[j] - min(a) >= b[j] - min(b):
			sum += a[j] - min(a)
		elif b[j] - min(b) > a[j] - min(a):
			sum += b[j] - min(b)
	print(sum)


for _ in range(int(input())):
	ans = 0
	n = int(input())
	candies = [int(i) for i in input().split()]
	apples = [int(i) for i in input().split()]
	minc = min(candies)
	mina = min(apples)
	for i in range(n):
		if candies[i] > minc and apples[i] > mina:
			minn = min(candies[i] - minc, apples[i] - mina)
			ans += minn
			candies[i] -= minn
			apples[i] -= minn
		if candies[i] > minc:
			ans += candies[i] - minc
		if apples[i] > mina:
			ans += apples[i] - mina
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minna = min(a)
	minnb = min(b)
	tot = 0
	for i in range(n):
		fora = 0
		forb = 0
		if a[i] > minna:
			fora = a[i] - minna
		if b[i] > minnb:
			forb = b[i] - minnb
		tot += max(forb, fora)
	print(tot)


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	cmin = min(c)
	omin = min(o)
	_c = [x - cmin for x in c]
	_o = [x - omin for x in o]
	ans = 0
	for i in range(n):
		ans += max(_c[i], _o[i])
	print(ans)


def solve(al, bl):
	(minA, minB) = (min(al), min(bl))
	tot = 0
	for i in range(len(al)):
		diffA = al[i] - minA
		diffB = bl[i] - minB
		tot += max(diffA, diffB)
	return tot
test_cases = int(input())
for i in range(test_cases):
	n = input()
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	res = solve(a, b)
	print(res)


def Input():
	Str = input('')
	List = Str.split(' ')
	for i in range(len(List)):
		List[i] = int(List[i])
	return List

def Minimize(x1, x2, Min1, Min2):
	Distances = [x1 - Min1, x2 - Min2]
	return max(Distances)

def Moves():
	List1 = Input()
	List2 = Input()
	Min1 = min(List1)
	Min2 = min(List2)
	Sum = 0
	for i in range(len(List1)):
		Sum += Minimize(List1[i], List2[i], Min1, Min2)
	return Sum
trials = int(input(''))
for i in range(trials):
	input('')
	print(Moves())


t = int(input())
while t:
	n = int(input())
	lst1 = [int(i) for i in input().split()]
	lst2 = [int(j) for j in input().split()]
	mina = min(lst1)
	minb = min(lst2)
	res = 0
	for i in range(n):
		res += max(lst1[i] - mina, lst2[i] - minb)
	print(res)
	t = t - 1


z = int(input())
for i in range(z):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1m = min(l1)
	l2m = min(l2)
	c = 0
	d = 0
	for i in range(n):
		if l1[i] != l1m and l2[i] != l2m:
			c = min(l1[i] - l1m, l2[i] - l2m)
			d += c
			l1[i] -= c
			l2[i] -= c
	for i in range(n):
		d += l1[i] - l1m
		d += l2[i] - l2m
	print(d)


testcases = int(input())
for i in range(testcases):
	n = int(input())
	a = input()
	a = a.split(' ')
	b = input()
	b = b.split(' ')
	for i in range(len(a)):
		a[i] = int(a[i])
	for j in range(len(b)):
		b[j] = int(b[j])
	smallest_a = min(a)
	smallest_b = min(b)
	count = 0
	for p in range(0, n):
		differnece_a = a[p] - smallest_a
		differnece_b = b[p] - smallest_b
		if differnece_b > differnece_a:
			count += differnece_a
			count = count + (differnece_b - differnece_a)
		else:
			count += differnece_b
			count = count + (differnece_a - differnece_b)
	print(count)


n = int(input())
for i in range(n):
	s = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	t = min(a)
	l = min(b)
	s = 0
	for j in range(len(a)):
		y = a[j] - t
		z = b[j] - l
		mini = min(y, z)
		s = s + mini
		a[j] = a[j] - mini
		b[j] = b[j] - mini
		s = s + a[j] - t
		s = s + b[j] - l
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	konf = min(a)
	apel = min(b)
	E = 0
	for i in range(n):
		E += max(a[i] - konf, b[i] - apel)
	print(E)


t = int(input())
for ii in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		diffa = a[i] - mina
		diffb = b[i] - minb
		if diffa > 0 and diffb > 0:
			ans += diffa + diffb - min(diffa, diffb)
		else:
			if diffa < 0:
				diffa = 0
			if diffb < 0:
				diffb = 0
			ans += diffa + diffb
	print(ans)


for _ in range(int(input())):
	num = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mini_a = min(a)
	mini_b = min(b)
	ans = 0
	for i in range(num):
		if a[i] == mini_a and b[i] == mini_b:
			continue
		elif a[i] == mini_a:
			ans += b[i] - mini_b
		elif b[i] == mini_b:
			ans += a[i] - mini_a
		elif b[i] - mini_b >= a[i] - mini_a:
			ans += a[i] - mini_a + b[i] - (a[i] - mini_a) - mini_b
		else:
			ans += b[i] - mini_b + a[i] - (b[i] - mini_b) - mini_a
	print(ans)


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

def gift():
	for _ in range(t):
		n = int(input())
		arry1 = list(map(int, input().split()))
		arry2 = list(map(int, input().split()))
		a = min(arry1)
		b = min(arry2)
		ans = 0
		for i in range(n):
			ans += max(arry1[i] - a, arry2[i] - b)
		yield ans
t = int(input())
ans = gift()
print(*ans, sep='\n')


t = int(input())

def solve(a, b, n):
	mina = min(a)
	minb = min(b)
	steps = 0
	for i in range(n):
		fora = a[i] - mina
		forb = b[i] - minb
		both = min(fora, forb)
		onlya = fora - both
		onlyb = forb - both
		steps += both + onlya + onlyb
	return steps
for testIteration in range(t):
	n = int(input())
	a = []
	b = []
	while len(a) < n:
		a.extend([int(s) for s in input().split(' ')])
	while len(b) < n:
		b.extend([int(s) for s in input().split(' ')])
	print(solve(a, b, n))


n = int(input())
results = []
for t in range(n):
	n = input()
	count = 0
	nums1 = list(map(int, input().split()))
	n1 = min(nums1)
	nums2 = list(map(int, input().split()))
	n2 = min(nums2)
	for i in range(len(nums1)):
		diff = min(nums1[i] - n1, nums2[i] - n2)
		count += diff
		count += nums1[i] - n1 - diff
		count += nums2[i] - n2 - diff
	results.append(count)
for _ in results:
	print(_)


tests = int(input())
for t in range(tests):
	n = int(input())
	candy = list(map(int, input().split(' ')))
	orange = list(map(int, input().split(' ')))
	mincandy = min(candy)
	minorange = min(orange)
	ans = 0
	for i in range(n):
		a = candy[i] - mincandy
		b = orange[i] - minorange
		ans += min([a, b]) + abs(a - b)
	print(ans)


n = int(input())
for i in range(n):
	m = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	c = min(a)
	d = min(b)
	sum = 0
	for j in range(len(a)):
		e = abs(c - a[j])
		f = abs(d - b[j])
		if e == 0 and f >= 1:
			sum = sum + f
		elif e >= 1 and f == 0:
			sum = sum + e
		elif e > f:
			sum = sum + e
		elif f > e:
			sum = sum + f
		else:
			sum = sum + e
	print(sum)


trial = int(input())
for _ in range(trial):
	dummy = input()
	list1 = list(map(int, input().split()))
	list2 = list(map(int, input().split()))
	minList1 = min(list1)
	minList2 = min(list2)
	move = list(map(lambda x: max([x[0] - minList1, x[1] - minList2]), zip(list1, list2)))
	print(sum(move))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = min(a)
	l = min(b)
	count = 0
	for i in range(n):
		if a[i] != k and b[i] == l:
			count += a[i] - k
		elif b[i] != l and a[i] == k:
			count += b[i] - l
		elif b[i] != l and a[i] != k:
			if a[i] - k > b[i] - l:
				z = b[i] - l
				count += z
				a[i] -= z
				count += abs(a[i] - k)
			else:
				z = a[i] - k
				count += z
				b[i] -= z
				count += abs(b[i] - l)
	print(count)


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	c_min = min(c)
	o_min = min(o)
	count = 0
	for i in range(n):
		count += max(abs(c[i] - c_min), abs(o[i] - o_min))
	print(count)


(z, zz, dgraphs) = (input, lambda : list(map(int, z().split())), {})
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	n = int(z())
	l1 = zz()
	l2 = zz()
	x = min(l1)
	y = min(l2)
	move = 0
	for (i, j) in zip(l1, l2):
		t1 = i - x
		t2 = j - y
		p = min(t1, t2)
		k = max(t1, t2)
		move += p
		move += k - p
	print(move)


t = int(input())
A = []
B = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	A.append(a)
	B.append(b)
for (a, b) in zip(A, B):
	mina = min(a)
	minb = min(b)
	ans = 0
	for (i, j) in zip(a, b):
		ans += max(i - mina, j - minb)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	result = 0
	for i in range(n):
		if a[i] > min(a) and b[i] > min(b):
			result += min(a[i] - min(a), b[i] - min(b))
			result += max(a[i] - min(a), b[i] - min(b)) - min(a[i] - min(a), b[i] - min(b))
		else:
			result += a[i] - min(a)
			result += b[i] - min(b)
	print(result)


def solve(aa, bb):
	mina = min(aa)
	minb = min(bb)
	m = 0
	for (a, b) in zip(aa, bb):
		da = a - mina
		db = b - minb
		m += max(da, db)
	return m
for _ in range(int(input())):
	n = int(input())
	aa = [int(x) for x in input().split()]
	bb = [int(x) for x in input().split()]
	print(solve(aa, bb))


from sys import stdin, stdout

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

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	moves = 0
	for i in range(n):
		a1 = a[i] - min_a
		b1 = b[i] - min_b
		moves += min(a1, b1)
		moves += abs(a1 - b1)
	print(moves)
for t in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	a = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1m = min(l1)
	l2m = min(l2)
	moves = 0
	for j in range(a):
		moves += max(l1[j] - l1m, l2[j] - l2m)
	print(moves)


import sys
t = int(input())
while t:
	n = int(input())
	a = list(map(int, sys.stdin.readline().strip().split()))
	b = list(map(int, sys.stdin.readline().strip().split()))
	moves = 0
	minA = min(a)
	minB = min(b)
	for i in range(n):
		if a[i] == minA and b[i] == minB:
			continue
		elif a[i] == minA and b[i] != minB:
			moves += b[i] - minB
		elif a[i] != minA and b[i] == minB:
			moves += a[i] - minA
		else:
			moves += min(a[i] - minA, b[i] - minB)
			temp = a[i]
			a[i] -= min(a[i] - minA, b[i] - minB)
			b[i] -= min(temp - minA, b[i] - minB)
			moves += b[i] - minB
			moves += a[i] - minA
	print(moves)
	t -= 1


for j in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	c = 0
	for i in range(n):
		c = c + min(a[i] - mina, b[i] - minb)
		(l, r) = (a[i], b[i])
		a[i] = a[i] - min(l - mina, r - minb)
		b[i] = b[i] - min(l - mina, r - minb)
		c = c + a[i] - mina
		c = c + b[i] - minb
	print(c)


test = int(input())
for i in range(test):
	n = int(input())
	ax = list(map(int, input().split()))
	bx = list(map(int, input().split()))
	mina = min(ax)
	while False:
		break
	minb = min(bx)
	num = 0
	for j in range(n):
		z = ax[j] - mina
		zz = bx[j] - minb
		while False:
			break
		if z < zz:
			num += zz
		else:
			num += z
	print(num)


t = int(input())
for test in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	min_a = min(a)
	min_b = min(b)
	step = [max(a[i] - min_a, b[i] - min_b) for i in range(n)]
	print(sum(step))


t = int(input())
for test in range(t):
	n = int(input())
	candies = [int(x) for x in input().split()]
	oranges = [int(x) for x in input().split()]
	c = min(candies)
	m = min(oranges)
	ans = 0
	for i in range(n):
		deltac = candies[i] - c
		deltam = oranges[i] - m
		delta = min(deltac, deltam)
		ans += delta
		f = deltac - delta
		s = deltam - delta
		ans = ans + f + s
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_m = min(a)
	b_m = min(b)
	s = 0
	for j in range(n):
		if a[j] > a_m and b[j] > b_m:
			s += max(a[j] - a_m, b[j] - b_m)
		elif a[j] > a_m:
			s += a[j] - a_m
		elif b[j] > b_m:
			s += b[j] - b_m
	print(s)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	res = 0
	for x in range(n):
		eat_a = a[x] - min_a
		eat_b = b[x] - min_b
		diff = abs(eat_b - eat_a)
		res += diff + min(eat_a, eat_b)
	print(res)
	t -= 1


y = int(input())
for i in range(y):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	z = min(a)
	x = min(b)
	ans = 0
	for j in range(n):
		dz = a[j] - z
		dx = b[j] - x
		t = dz + dx
		ans = ans + t - min(dz, dx)
	print(ans)


for _ in range(int(input())):
	w = int(input())
	orange = list(map(int, input().split()))
	candies = list(map(int, input().split()))
	mnOra = min(orange)
	mnCan = min(candies)
	sum = 0
	for i in range(w):
		rem1 = orange[i] - mnOra
		rem2 = candies[i] - mnCan
		sum += max(rem1, rem2)
	print(sum)


n = int(input())
for i in range(n):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	result = 0
	for j in range(len(a)):
		result += max(a[j] - a_min, b[j] - b_min)
	print(result)


def saurabh(a, b, count, n):
	a_min = min(a)
	b_min = min(b)
	for i in range(n):
		xx = 0
		yy = 0
		if a[i] > a_min:
			xx = a[i] - a_min
		if b[i] > b_min:
			yy = b[i] - b_min
		count += max(xx, yy)
	return count
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	print(saurabh(a, b, 0, n))


m = int(input())
for f in range(m):
	n = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	l1 = min(lst1)
	l2 = min(lst2)
	freq = 0
	for (c1, c2) in zip(lst1, lst2):
		if c1 - l1 > c2 - l2:
			freq += c1 - l1
		else:
			freq += c2 - l2
	print(freq)


n = int(input())
ans = []
for i in range(n):
	m = int(input())
	orange = [int(a) for a in input().split()]
	present = [int(a) for a in input().split()]
	mo = min(orange)
	mp = min(present)
	I = 0
	ctn = 0
	while I < m:
		ctn += max(orange[I] - mo, present[I] - mp)
		I += 1
	ans.append(ctn)
for i in ans:
	print(i)


t = int(input())

def find_n(a):
	(j, k) = (0, 0)
	x = max(a)
	for i in range(len(a)):
		if a[i] == x:
			s = i
			break
	for i in a:
		if i != x and i <= min(a) and (i != '\x00'):
			a[j] += 1
			a[s] -= 1
			x -= 1
			k += 1
			j += 1
		elif i != '\x00':
			j += 1
	for i in range(len(a)):
		if a[i] != x:
			k = -1
		break
	return k
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	for i in range(n):
		(g, h) = (0, 0)
		if a[i] != min(a):
			g = a[i] - min(a)
			a[i] -= a[i] - min(a)
		if b[i] != min(b):
			h = b[i] - min(b)
			b[i] -= b[i] - min(b)
		c += max(g, h)
	print(c)


import sys
input = sys.stdin.readline

def name(n, o, c):
	mino = min(o)
	minc = min(c)
	count = 0
	for i in range(n):
		if o[i] > mino and c[i] > minc:
			if mino <= minc:
				gap = o[i] - mino
			else:
				gap = c[i] - minc
			o[i] -= gap
			c[i] -= gap
			count += gap
			if o[i] > mino:
				count += o[i] - mino
				o[i] = mino
			if c[i] > minc:
				count += c[i] - minc
				c[i] = minc
		else:
			if o[i] > mino:
				count += o[i] - mino
				o[i] = mino
			if c[i] > minc:
				count += c[i] - minc
				c[i] = minc
	return count

def solution():
	n = int(input())
	o = list(map(lambda x: int(x), input().split()))
	c = list(map(lambda x: int(x), input().split()))
	print(name(n, o, c))
t = int(input())
for i in range(0, t):
	solution()


t = int(input())
while t:
	t -= 1
	m = int(input())
	lst = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	m1 = min(lst)
	m2 = min(arr)
	count = 0
	for i in range(m):
		if abs(lst[i] - m1) > 0 and abs(arr[i] - m2) > 0:
			count += max(abs(lst[i] - m1), abs(arr[i] - m2))
		elif abs(lst[i] - m1) > 0 and abs(arr[i] - m2) == 0:
			count += abs(lst[i] - m1)
		elif abs(lst[i] - m1) == 0 and abs(arr[i] - m2) > 0:
			count += abs(arr[i] - m2)
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	lista_a = input().split(' ')
	lista_b = input().split(' ')
	movimientos = 0
	for j in range(n):
		lista_a[j] = int(lista_a[j])
		lista_b[j] = int(lista_b[j])
	min_a = min(lista_a)
	min_b = min(lista_b)
	for j in range(n):
		movimientos += max(lista_a[j] - min_a, lista_b[j] - min_b)
	print(movimientos)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

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)

def toord(c):
	return ord(c) - ord('a')

def lcm(a, b):
	return a * b // lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		n = N()
		arra = RLL()
		arrb = RLL()
		(ma, mb) = (min(arra), min(arrb))
		res = 0
		for i in range(n):
			(nowa, nowb) = (arra[i], arrb[i])
			(na, nb) = (nowa - ma, nowb - mb)
			res += min(na, nb)
			res += max(na, nb) - min(na, nb)
		print(res)
main()


t = int(input())
for i in range(t):
	n = int(input())
	ko = list(map(int, input().split()))
	ap = list(map(int, input().split()))
	ans = 0
	minko = min(ko)
	minap = min(ap)
	for j in range(n):
		abko = ko[j] - minko
		abap = ap[j] - minap
		together = min(abap, abko)
		ans += together
		abko -= together
		abap -= together
		if abko > 0:
			ans += abko
		if abap > 0:
			ans += abap
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mna = min(a)
	mnb = min(b)
	mnd = abs(mna - mnb)
	mn = min(mna, mnb)
	f = 0
	res = 0
	for i in range(n):
		mnaa = a[i] - mna
		mnbb = b[i] - mnb
		res += max(mnaa, mnbb)
	print(res)


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(lambda x: int(x), input().split()))
	b = list(map(lambda x: int(x), input().split()))
	minimum_a = min(a)
	minimum_b = min(b)
	total = 0
	for i in range(0, len(a)):
		total += max(a[i] - minimum_a, b[i] - minimum_b)
	print(total)


T = int(input())
for t in range(T):
	n = int(input())
	A = [int(i) for i in input().split()]
	B = [int(i) for i in input().split()]
	smallest_A = min(A)
	smallest_B = min(B)
	ans = 0
	for i in range(n):
		ans += max(A[i] - smallest_A, B[i] - smallest_B)
	print(ans)


for i in range(int(input())):
	a = int(input())
	Candy = input().split()
	Oranges = input().split()
	Candy = [int(x) for x in Candy]
	Oranges = [int(x) for x in Oranges]
	BaseCandy = min(Candy[:])
	BaseOranges = min(Oranges[:])
	MaxMoves = sum(Candy) - BaseCandy * a + (sum(Oranges) - BaseOranges * a)
	Candy = [x - BaseCandy for x in Candy]
	Oranges = [x - BaseOranges for x in Oranges]
	counter = 0
	for i in range(a):
		if Candy[i] > 0 and Oranges[i] > 0:
			counter += min(Candy[i], Oranges[i])
		else:
			continue
	print(MaxMoves - counter)


from collections import deque
from math import *
import heapq
from random import *
import sys
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	c = 0
	for j in range(len(a)):
		if a[j] == a1 and b[j] == b1:
			c += 0
		elif a[j] == a1:
			c += b[j] - b1
		elif b[j] == b1:
			c += a[j] - a1
		else:
			diff1 = a[j] - a1
			diff2 = b[j] - b1
			if diff1 == diff2:
				c += diff1
				continue
			elif diff1 < diff2:
				c += diff1
				b[j] -= diff1
				a[j] -= diff1
			else:
				c += diff2
				b[j] -= diff2
				a[j] -= diff2
			if a[j] == a1:
				c += b[j] - b1
			elif b[j] == b1:
				c += a[j] - a1
	print(c)


a = int(input(''))
for i in range(0, a):
	b = int(input(''))
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	e = min(c)
	f = min(d)
	l = 0
	for j in range(0, b):
		p = c[j] - e
		q = d[j] - f
		if p > q:
			l = l + p
		elif q > p:
			l = l + q
		else:
			l = l + p
	print(l)


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	ma = min(a)
	mb = min(b)
	ans = 0
	for i in range(n):
		tmp = min(a[i] - ma, b[i] - mb)
		a[i] = a[i] - tmp
		b[i] = b[i] - tmp
		ans += tmp
		if a[i] == ma:
			ans += b[i] - mb
		elif b[i] == mb:
			ans += a[i] - ma
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	count = 0
	for i in range(n):
		if b[i] > min(b) and a[i] > min(a):
			t = min(b[i] - min(b), a[i] - min(a))
			count += t
			b[i] = b[i] - t
			a[i] = a[i] - t
			if b[i] > min(b):
				count += b[i] - min(b)
			if a[i] > min(a):
				count += a[i] - min(a)
		elif a[i] > min(a):
			count += a[i] - min(a)
		else:
			count += b[i] - min(b)
	print(count)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	f = 1
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	cha = []
	chb = []
	mna = min(a)
	mnb = min(b)
	for v in a:
		cha += [v - mna]
	for v in b:
		chb += [v - mnb]
	ans = 0
	for (v, v1) in zip(cha, chb):
		ans += max(v, v1)
	print(ans)


from typing import List

def get_input():
	try:
		text = input()
		text = text.strip()
		if len(text) == 0:
			return None
		else:
			return text
	except EOFError:
		return None

def min_steps(xs: List[int], ys: List[int]):
	x_min = min(xs)
	y_min = min(ys)
	xs_d = [x - x_min for x in xs]
	ys_d = [y - y_min for y in ys]
	return sum((max(x_d, y_d) for (x_d, y_d) in zip(xs_d, ys_d)))
total_cases = int(get_input())
for _ in range(total_cases):
	get_input()
	xs = list(map(int, get_input().split(' ')))
	ys = list(map(int, get_input().split(' ')))
	print(min_steps(xs, ys))


for _ in range(int(input())):
	cantidadRegalos = int(input())
	listaRegalos = []
	listaRegalos.append(list(map(int, input().split())))
	listaRegalos.append(list(map(int, input().split())))
	contador = 0
	minimunCandies = min(listaRegalos[0])
	minimunOranges = min(listaRegalos[1])
	for i in range(cantidadRegalos):
		if listaRegalos[0][i] > minimunCandies and listaRegalos[1][i] > minimunOranges:
			aux1 = abs(minimunCandies - listaRegalos[0][i])
			aux2 = abs(minimunOranges - listaRegalos[1][i])
			aux = min(aux1, aux2)
			listaRegalos[0][i] = listaRegalos[0][i] - aux
			listaRegalos[1][i] = listaRegalos[1][i] - aux
			contador = contador + aux
		if listaRegalos[0][i] > minimunCandies:
			aux = abs(minimunCandies - listaRegalos[0][i])
			listaRegalos[0][i] = listaRegalos[0][i] - aux
			contador = contador + aux
		if listaRegalos[1][i] > minimunOranges:
			aux = abs(minimunOranges - listaRegalos[1][i])
			listaRegalos[1][i] = listaRegalos[1][i] - aux
			contador = contador + aux
	print(contador)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

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

def oint():
	return int(input())
t = oint()
for _ in range(t):
	n = oint()
	a = list(rint())
	b = list(rint())
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		adiff = a[i] - amin
		bdiff = b[i] - bmin
		if adiff > bdiff:
			ans += adiff
		else:
			ans += bdiff
	print(ans)


for _ in range(int(input())):
	n = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	cnt = 0
	(a, b) = (min(lst1), min(lst2))
	for i in range(n):
		if lst1[i] != a and lst2[i] != b:
			x = min(lst1[i] - a, lst2[i] - b)
			cnt += x
			lst1[i] -= x
			lst2[i] -= x
		cnt += lst1[i] - a + (lst2[i] - b)
	print(cnt)


import sys
T = int(sys.stdin.readline())
for i in range(T):
	N = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	test_a = []
	test_b = []
	a_min = min(a)
	b_min = min(b)
	count = 0
	for j in range(N):
		test_a.append(a[j] - a_min)
		test_b.append(b[j] - b_min)
	for k in zip(test_a, test_b):
		if min(k) == 0:
			count += max(k)
		else:
			count += max(k)
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min1 = 1000000001
	min2 = 1000000001
	for j in range(n):
		if a[j] < min1:
			min1 = a[j]
		if b[j] < min2:
			min2 = b[j]
	c1 = [0 for i in range(n)]
	c2 = [0 for i in range(n)]
	for j in range(n):
		c1[j] = a[j] - min1
		c2[j] = b[j] - min2
	s = 0
	for j in range(n):
		s += max(c1[j], c2[j])
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	cmin = min(candy)
	omin = min(orange)
	tot = 0
	for i in range(n):
		tot += max(candy[i] - cmin, orange[i] - omin)
	print(tot)


import sys
input = sys.stdin.buffer.readline
from collections import deque as que, defaultdict as vector
from bisect import bisect as bsearch
from heapq import *
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
INF = float('inf')
testcase = inin()
for Case in range(testcase):
	n = inin()
	a = inar()
	b = inar()
	ans = 0
	a1 = min(a)
	b1 = min(b)
	for i in range(n):
		ans += max(a[i] - a1, b[i] - b1)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	d = min(b)
	arr1 = []
	arr2 = []
	for i in range(len(a)):
		f = a[i] - c
		arr1.append(f)
	for i in range(len(b)):
		g = b[i] - d
		arr2.append(g)
	count = 0
	for (i, j) in zip(arr1, arr2):
		count += max(i, j)
	print(count)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	a2 = min(b)
	ans = 0
	for i in range(n):
		k1 = a[i] - a1
		k2 = b[i] - a2
		ans += max(k1, k2)
	print(ans)
	t -= 1


test_cases = int(input())
for i in range(test_cases):
	no_of_gifts = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	(min_candies, min_oranges) = (min(candies), min(oranges))
	ate = [max(abs(candies[i] - min_candies), abs(oranges[i] - min_oranges)) for i in range(no_of_gifts)]
	print(sum(ate))


for t in range(int(input())):
	n = int(input())
	li = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	ma = min(li)
	mb = min(l2)
	ans = 0
	for i in range(n):
		temp = max(li[i] - ma, l2[i] - mb)
		ans += temp
	print(ans)


from sys import stdin

def main():
	iint = int
	llist = list
	mmap = map
	mmin = min
	input = stdin.readline
	t = iint(input())
	for i in range(t):
		n = iint(input())
		arr1 = llist(mmap(iint, input().split()))
		arr2 = llist(mmap(iint, input().split()))
		m1 = mmin(arr1)
		m2 = mmin(arr2)
		ans = 0
		for j in range(n):
			if arr1[j] - m1 > arr2[j] - m2:
				ans = ans + arr1[j] - m1
			else:
				ans = ans + arr2[j] - m2
		print(ans)
main()


N = int(input())
for _ in range(N):
	count = 0
	both = 0
	countc = 0
	counto = 0
	n = int(input())
	data1 = input()
	data2 = input()
	split1 = data1.split(' ')
	split2 = data2.split(' ')
	c = []
	o = []
	for x in split1:
		c.append(int(x))
	for x in split2:
		o.append(int(x))
	minc = c[0]
	mino = o[0]
	for i in range(n):
		if c[i] < minc:
			minc = c[i]
		if o[i] < mino:
			mino = o[i]
	for i in range(n):
		if c[i] > minc and o[i] > mino:
			both = both + min(c[i] - minc, o[i] - mino)
			if c[i] - minc > o[i] - mino:
				countc = countc + (c[i] - minc) - min(c[i] - minc, o[i] - mino)
			elif c[i] - minc < o[i] - mino:
				counto = counto + (o[i] - mino) - min(c[i] - minc, o[i] - mino)
		elif c[i] > minc:
			countc = countc + c[i] - minc
		elif o[i] > mino:
			counto = counto + o[i] - mino
	count = both + countc + counto
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	b = input().split()
	for k in range(n):
		a[k] = int(a[k])
		b[k] = int(b[k])
	c = min(a)
	d = min(b)
	s = 0
	for j in range(n):
		a[j] = int(a[j]) - int(c)
		b[j] = int(b[j]) - int(d)
		if int(a[j]) < int(b[j]):
			s += b[j]
		else:
			s += a[j]
	print(s)


fin = list()
t = int(input())
for i in range(t):
	k = 0
	n = int(input())
	s = input()
	a = list(map(int, s.split()))
	s = input()
	b = list(map(int, s.split()))
	min_a = min(a)
	min_b = min(b)
	for j in range(n):
		t1 = a[j] - min_a
		t2 = b[j] - min_b
		k = k + max(t1, t2)
	fin.append(k)
for i in range(t):
	print(fin[i])


test = int(input())
for x in range(test):
	number = int(input())
	moves = 0
	i = 0
	atemp = input()
	a = [int(x) for x in atemp.split(' ')]
	btemp = input()
	b = [int(x) for x in btemp.split(' ')]
	amin = min(a)
	bmin = min(b)
	reduce = 0
	allequal = False
	adiff = [x - amin for x in a]
	bdiff = [z - bmin for z in b]
	while not allequal:
		if adiff[i] > 0 and bdiff[i] > 0:
			reduce = min(adiff[i], bdiff[i])
			adiff[i] -= reduce
			bdiff[i] -= reduce
			moves += reduce
		if adiff[i] > 0:
			moves += adiff[i]
			adiff[i] -= adiff[i]
		if bdiff[i] > 0:
			moves += bdiff[i]
			bdiff[i] -= bdiff[i]
		if sum(adiff) == 0 and sum(bdiff) == 0:
			allequal = True
			break
		if adiff[i] == 0 and bdiff[i] == 0:
			if i <= number - 1:
				i += 1
	print(moves)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		if a[i] == amin and b[i] == bmin:
			continue
		elif a[i] == amin and b[i] != bmin:
			ans += b[i] - bmin
		elif b[i] == bmin and a[i] != amin:
			ans += a[i] - amin
		else:
			ax = a[i] - amin
			bx = b[i] - bmin
			ans += min(ax, bx) + max(ax, bx) - min(ax, bx)
	print(ans)


from sys import stdin
import sys
import functools
import heapq
from collections import *
sys.setrecursionlimit(100000)

def _input(type=int):
	return list(map(type, stdin.readline().split()))
for tc in range(_input()[0]):
	n = _input()[0]
	(a, b) = (_input(), _input())
	(ma, mb) = (min(a), min(b))
	ans = 0
	for [x, y] in zip(a, b):
		ans += max(x - ma, y - mb)
	print(ans)


k = int(input())
for _ in range(k):
	sw_difference = True
	or_difference = True
	k_el = int(input())
	sweets = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	if len(set(sweets)) == 1 and len(sweets) != 1:
		sw_difference = False
	if len(set(orange)) == 1 and len(orange) != 1:
		or_difference = False
	if not sw_difference and (not or_difference):
		print(0)
		continue
	sw_aim = None
	or_aim = None
	k_result = 0
	if sw_difference:
		sw_aim = min(sweets)
	if or_difference:
		or_aim = min(orange)
	for i in range(k_el):
		if sw_aim is not None and sweets[i] != sw_aim:
			sw_count = sweets[i] - sw_aim
		else:
			sw_count = 0
		if or_aim is not None and orange[i] != or_aim:
			or_count = orange[i] - or_aim
		else:
			or_count = 0
		k_result += max(or_count, sw_count)
	print(k_result)
	k_result = 0


def gifts_fixing():
	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()]
		min_a = min(a)
		min_b = min(b)
		total = 0
		for i in range(n):
			moves_a = a[i] - min_a
			moves_b = b[i] - min_b
			common = min(moves_a, moves_b)
			diff = abs(moves_a - moves_b)
			total += common + diff
		print(total)
gifts_fixing()


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()]
	a1 = []
	min1 = min(a)
	min2 = min(b)
	for i in range(n):
		num1 = a[i] - min1
		num2 = b[i] - min2
		if num1 > num2:
			a1.append(num1)
		else:
			a1.append(num2)
	print(sum(a1))


def solution(A, B, n):
	a_min = min(A)
	b_min = min(B)
	total = 0
	for i in range(n):
		total += max(abs(A[i] - a_min), abs(B[i] - b_min))
	return total
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	print(solution(A, B, n))


import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda : list(map(int, input().split()))

def printARR(arr):
	for e in arr:
		print(e, end=' ')
	print()

def main():
	n = I()
	a = ARR()
	b = ARR()
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		d1 = a[i] - min_a
		d2 = b[i] - min_b
		ans += max(d1, d2)
	print(ans)
tc = 1
tc = I()
for _ in range(tc):
	main()


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	ans = 0
	n = int(input())
	(*a,) = map(int, input().split())
	(*b,) = map(int, input().split())
	x = min(a)
	y = min(b)
	for i in range(n):
		ans += max(a[i] - x, b[i] - y)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	c = [0 for i in range(n)]
	candy = min(a)
	orange = min(b)
	ops = 0
	for i in range(n):
		ci = a[i] - candy
		oi = b[i] - orange
		m = min(ci, oi)
		ops = ops + ci + oi - m
	print(ops)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		if a[i] != ma and b[i] != mb:
			c += a[i] - ma + (b[i] - mb) - min(a[i] - ma, b[i] - mb)
		elif a[i] != ma:
			c += a[i] - ma
		elif b[i] != mb:
			c += b[i] - mb
	print(c)


for _ in range(int(input())):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	min_candy = min(candy)
	min_orange = min(orange)
	ans = 0
	for i in range(n):
		req1 = candy[i] - min_candy
		req2 = orange[i] - min_orange
		ans += max(req1, req2)
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import threading
from collections import defaultdict

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	a = min(arr)
	b = min(brr)
	ans = 0
	for i in range(n):
		a1 = arr[i] - a
		b1 = brr[i] - b
		ans = ans + max(a1, b1)
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	main()


t = int(input())
for i in range(t):
	n = int(input())
	lisa = [int(k) for k in str(input()).split()]
	a = min(lisa)
	lisb = [int(k) for k in str(input()).split()]
	b = min(lisb)
	sum = 0
	for c in range(n):
		sum += max(lisa[c] - a, lisb[c] - b)
	print(sum)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	m1 = min(a)
	m2 = min(b)
	for i in range(n):
		d1 = a[i] - m1
		d2 = b[i] - m2
		if d1 == 0 and d2 != 0:
			c += d2
		elif d1 != 0 and d2 == 0:
			c += d1
		else:
			c += min(d1, d2)
			c += abs(d1 - d2)
	print(c)


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(' ')]
	c = 0
	m1 = min(a)
	m2 = min(b)
	for i in range(n):
		x = a[i] - m1
		y = b[i] - m2
		c += max(x, y)
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	counta = 0
	countb = 0
	count = 0
	for x in range(len(a)):
		if a[x] > mina and b[x] > minb:
			counta = a[x] - mina
			countb = b[x] - minb
			count += max(counta, countb)
		elif a[x] > mina:
			count += a[x] - mina
		elif b[x] > minb:
			count += b[x] - minb
	print(count)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s1 = min(a)
	s2 = min(b)
	count = 0
	for i in range(len(a)):
		count += max(abs(a[i] - s1), abs(b[i] - s2))
	print(count)
	t -= 1


t = int(input())
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]
	amin = min(a)
	bmin = min(b)
	k = 0
	j = 0
	while j < n:
		k += max(a[j] - amin, b[j] - bmin)
		j += 1
	print(k)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(get_ints())
	b = list(get_ints())
	ma = min(a)
	mb = min(b)
	ans = 0
	for i in range(n):
		tempa = tempb = 0
		if a[i] > ma:
			tempa = a[i] - ma
		if b[i] > mb:
			tempb = b[i] - mb
		ans += max(tempa, tempb)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x1 = min(a)
	x2 = min(b)
	a1 = [x - x1 for x in a]
	a2 = [x - x2 for x in b]
	a3 = [max(a1[i], a2[i]) for i in range(n)]
	print(sum(a3))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	c = 0
	mb = min(b)
	for i in range(n):
		if a[i] > ma and b[i] > mb:
			k1 = a[i] - ma
			k2 = b[i] - mb
			c = c + max(k1, k2)
		elif a[i] > ma and b[i] == mb:
			c = c + a[i] - ma
		elif a[i] == ma and b[i] > mb:
			c = c + b[i] - mb
	print(c)


n = int(input())
for i in range(n):
	m = int(input())
	s = input().split(' ')
	s1 = input().split(' ')
	a = []
	b = []
	for i in range(m):
		a.append(int(s[i]))
		b.append(int(s1[i]))
	min1 = min(a)
	min2 = min(b)
	sum1 = 0
	for i in range(m):
		sum1 += max([a[i] - min1, b[i] - min2])
	print(sum1)


n = int(input())
ansList = []
for _ in range(n):
	arrSize = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aMin = min(a)
	bMin = min(b)
	counter = 0
	for i in range(arrSize - 1, -1, -1):
		aDiff = a[i] - aMin
		bDiff = b[i] - bMin
		if aDiff > bDiff:
			counter += bDiff
			counter += a[i] - bDiff - aMin
		elif bDiff > aDiff:
			counter += aDiff
			counter += b[i] - aDiff - bMin
		else:
			counter += aDiff
	ansList.append(counter)
for s in ansList:
	print(s)


t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	count = 0
	for i in range(n):
		if a[i] != mina or b[i] != minb:
			if a[i] - mina == b[i] - minb:
				count = count + a[i] - mina
			else:
				k = a[i] - mina
				l = b[i] - minb
				m = max(k, l)
				count = count + m
	print(count)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ar1 = list(map(int, input().split()))
	t = min(ar)
	u = min(ar1)
	sub = 0
	count = 0
	for i in range(n):
		if ar[i] > t and ar1[i] > u:
			sub = min(ar[i], ar1[i]) - min(t, u)
			count += sub
			ar[i] -= sub
			ar1[i] -= sub
	for i in range(n):
		if ar[i] > t:
			count += ar[i] - t
	for i in range(n):
		if ar1[i] > u:
			count += ar1[i] - u
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	inp1 = [int(j) for j in input().split()]
	inp2 = [int(j) for j in input().split()]
	temp1 = min(inp1)
	temp2 = min(inp2)
	res = 0
	for i in range(n):
		res = res + max(inp1[i] - temp1, inp2[i] - temp2)
	print(res)


import sys
input = sys.stdin.readline
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 = min(a)
	B = min(b)
	ans = 0
	for i in range(n):
		ans += max([a[i] - A, b[i] - B])
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	temp1 = []
	temp2 = []
	common = 0
	unique = 0
	am = min(a)
	bm = min(b)
	for x in range(n):
		temp1.append(abs(a[x] - am))
		temp2.append(abs(b[x] - bm))
		common += min(temp1[x], temp2[x])
		unique += abs(temp1[x] - temp2[x])
	ans = common + unique
	print(ans)


def giftsFixing():
	a_min = min(a)
	b_min = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - a_min, b[i] - b_min)
	return ans
t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().rstrip().split(' ')]
	b = [int(x) for x in input().rstrip().split(' ')]
	print(giftsFixing())


for _ in range(int(input())):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_candie = min(candies)
	min_orange = min(oranges)
	total = 0
	for i in range(n):
		total += max(abs(min_candie - candies[i]), abs(min_orange - oranges[i]))
	print(total)


def isEqual(ls):
	a = ls[0]
	for i in ls:
		if i != a:
			return False
	return True
a = int(input())
ans_list = []
for i in range(a):
	ans = 0
	o = 0
	a = input()
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	while not isEqual(a) or not isEqual(b):
		if a[o] != min(a) and b[o] != min(b):
			temp = min(a[o] - min(a), b[o] - min(b))
			ans += temp
			a[o] -= temp
			b[o] -= temp
		elif a[o] != min(a):
			ans += a[o] - min(a)
			a[o] = min(a)
		elif b[o] != min(b):
			ans += b[o] - min(b)
			b[o] = min(b)
		o += 1
		if o == len(a):
			o = 0
	ans_list.append(str(ans))
print('\n'.join(ans_list))


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	ans = 0
	for (ai, bi) in zip(a, b):
		da = ai - x
		db = bi - y
		mind = min(da, db)
		maxd = max(da, db)
		ans += mind
		ans += maxd - mind
	print(ans)


T = input()
T = int(T)
for t in range(0, T):
	n = input()
	n = int(n)
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	minimum_candies = min(candies)
	minimum_oranges = min(oranges)
	moves = 0
	for i in range(0, n):
		count = 0
		if candies[i] > minimum_candies:
			moves = moves + (candies[i] - minimum_candies)
			count = count + 1
		if oranges[i] > minimum_oranges:
			moves = moves + (oranges[i] - minimum_oranges)
			count = count + 1
		if count == 2:
			moves = moves - min(candies[i] - minimum_candies, oranges[i] - minimum_oranges)
	print(moves)


n = int(input())
for i in range(n):
	c = 0
	k = int(input())
	m = list(map(int, input().split()))
	n = list(map(int, input().split()))
	for j in range(k):
		a = m[j] - min(m)
		b = n[j] - min(n)
		c += max(a, b)
	print(c)


t = int(input())
responses = []
for _ in range(t):
	n = int(input())
	a = [int(part) for part in input().split()]
	b = [int(part) for part in input().split()]
	min_a = min(a)
	min_b = min(b)
	moves = 0
	for i in range(n):
		if a[i] > min_a and b[i] > min_b:
			diff_a = a[i] - min_a
			diff_b = b[i] - min_b
			moves += min(diff_a, diff_b)
			a[i] -= min(diff_a, diff_b)
			b[i] -= min(diff_a, diff_b)
		if a[i] > min_a:
			moves += a[i] - min_a
			a[i] -= a[i] - min_a
		if b[i] > min_b:
			moves += b[i] - min_b
			b[i] -= b[i] - min_b
	responses.append(moves)
for response in responses:
	print(response)


import sys
from math import sqrt
from collections import defaultdict
inpt = sys.stdin.readline

def inp():
	return int(inpt())

def inlist():
	return list(map(int, inpt().split()))

def instr():
	s = inpt()
	return list(s[:len(s) - 1])

def invr():
	return map(int, inpt().split())

class Graph:

	def __init__(self, n):
		self.n = n
		self.graph = defaultdict(list)
		self.marked = defaultdict(int)

	def addEdge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def dfs(self, u):
		self.marked[u] = 1
		for i in self.graph[u]:
			if self.marked[i] == 0:
				self.dfs(i)

def main():
	t = inp()
	for f in range(t):
		n = inp()
		a = inlist()
		b = inlist()
		ans = 0
		(ma, mb) = (min(a), min(b))
		for i in range(n):
			ans += max(a[i] - ma, b[i] - mb)
		print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arrb = list(map(int, input().split()))
	c = 0
	if len(set(arr)) == len(set(arrb)) == 1:
		print(0)
	else:
		a = min(arr)
		b = min(arrb)
		for i in range(n):
			if arr[i] > a and arrb[i] > b:
				c += max(arr[i] - a, arrb[i] - b)
			else:
				c += max(arr[i] - a, arrb[i] - b)
		print(c)


for _ in range(int(input())):
	n = int(input())
	L1 = list(map(int, input().split()))
	L2 = list(map(int, input().split()))
	m1 = min(L1)
	m2 = min(L2)
	s = 0
	for i in range(len(L1)):
		s = s + max(L1[i] - m1, L2[i] - m2)
	print(s)


import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io

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

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

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

def main():
	for i in range(ii()):
		n = ii()
		a = li()
		b = li()
		ma = min(a)
		mb = min(b)
		su = 0
		for i in range(n):
			moves = 0
			if a[i] > ma and b[i] > mb:
				x = a[i] - ma
				y = b[i] - mb
				moves += min(x, y)
				moves += abs(x - y)
			elif a[i] > ma:
				x = a[i] - ma
				moves += x
			elif b[i] > mb:
				y = b[i] - mb
				moves += y
			else:
				pass
			su += moves
		print(su)
main()


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = 0
	(mia, mib) = (min(a), min(b))
	for i in range(n):
		ans += max(a[i] - mia, b[i] - mib)
	print(ans)


c = int(input())
for x in range(c):
	i = 0
	count = 0
	_ = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minA = min(a)
	minB = min(b)
	while i < len(a):
		count += max(a[i] - minA, b[i] - minB)
		i += 1
	print(count)


import io, os
from collections import deque
import bisect
RL = lambda : list(map(int, input().split(' ')))
T = int(input())
for _ in range(T):
	n = int(input())
	a = RL()
	b = RL()
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		diffa = a[i] - mina
		diffb = b[i] - minb
		ans += +max(diffa, diffb)
	print(ans)


t = int(input())
n = 0
move = 0
for i in range(t):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	m_c = min(candy)
	m_o = min(orange)
	move = 0
	i = 0
	temp = 0
	while all((element == m_c for element in candy)) == False or all((element == m_o for element in orange)) == False:
		if candy[i] > m_c and orange[i] > m_o:
			temp = min(candy[i] - m_c, orange[i] - m_o) * 1
			move += temp
			candy[i] -= temp
			orange[i] -= temp
		if candy[i] == m_c and orange[i] > m_o:
			move += (orange[i] - m_o) * 1
			orange[i] -= (orange[i] - m_o) * 1
		if candy[i] > m_c and orange[i] == m_o:
			move += (candy[i] - m_c) * 1
			candy[i] -= (candy[i] - m_c) * 1
		i = i + 1
		if i >= len(candy):
			i = 0
	print(move)


def fun():
	rag = input()
	k1 = input()
	ar1 = k1.split()
	ar1 = list(map(int, ar1))
	min1 = min(ar1)
	k2 = input()
	ar2 = k2.split()
	ar2 = list(map(int, ar2))
	min2 = min(ar2)
	l = len(ar1)
	d = 0
	for i in range(l):
		a = ar1[i] - min1
		b = ar2[i] - min2
		c = min(a, b)
		d += a + b - c
	print(d)
k = int(input())
for i in range(k):
	fun()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	g = min(a)
	h = min(b)
	l = [0] * n
	for i in range(n):
		l[i] = max(a[i] - g, b[i] - h)
	print(sum(l))


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	count1 = 0
	total = 0
	a_min = min(a)
	b_min = min(b)
	for i in range(n):
		count = a[i] - a_min
		count1 = b[i] - b_min
		total += max(count1, count)
	print(total)


test_cases = int(input())
for _ in range(test_cases):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	a_min = min(a)
	b_min = min(b)
	counter = 0
	for i in range(len(a)):
		if a[i] > a_min and b[i] > b_min:
			min_val = min(a[i] - a_min, b[i] - b_min)
			counter += min_val
			a[i] -= min_val
			b[i] -= min_val
		if a[i] > a_min:
			diff = a[i] - a_min
			counter += diff
		if b[i] > b_min:
			diff = b[i] - b_min
			counter += diff
	print(counter)


t = int(input())
for i in range(t):
	n = int(input())
	c = [int(k) for k in input().split()]
	o = [int(k) for k in input().split()]
	mc = min(c)
	oc = min(o)
	count = 0
	for j in range(n):
		count += max(c[j] - mc, o[j] - oc)
	print(count)


xyz = input
t = int(xyz())
for t1 in [0] * t:
	n = int(xyz())
	a = list(map(int, xyz().split()))
	b = list(map(int, xyz().split()))
	pairs = []
	for i in range(n):
		pairs.append([a[i], b[i]])
	pairs.sort(key=lambda x: (x[0], x[1]))
	min_a = min(a)
	min_b = min(b)
	counter = 0
	for pair in pairs:
		if pair[0] > min_a and pair[1] > min_b:
			counter += min(pair[0] - min_a, pair[1] - min_b)
			counter += max(pair[0] - min_a, pair[1] - min_b) - min(pair[0] - min_a, pair[1] - min_b)
		elif pair[0] > min_a and pair[1] == min_b:
			counter += pair[0] - min_a
		elif pair[0] == min_a and pair[1] > min_b:
			counter += pair[1] - min_b
	print(counter)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	k = 0
	for i in range(n):
		while not (a[i] == am and b[i] == bm):
			if a[i] != am and b[i] != bm:
				mo = min(a[i] - am, b[i] - bm)
				a[i] -= mo
				b[i] -= mo
				k += mo
			elif a[i] != am:
				k += a[i] - am
				a[i] = am
			elif b[i] != bm:
				k += b[i] - bm
				b[i] = bm
	print(k)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	needa = min(a)
	needb = min(b)
	moves = 0
	for i in range(n):
		moves += a[i] - needa + b[i] - needb - min(a[i] - needa, b[i] - needb)
	print(moves)


def solve(l, arr1, arr2):
	m1 = min(arr1)
	m2 = min(arr2)
	c = 0
	for i in range(l):
		if arr1[i] != m1 and arr2[i] != m2:
			c += max(arr1[i] - m1, arr2[i] - m2)
		if arr1[i] == m1 and arr2[i] != m2:
			c += arr2[i] - m2
		if arr2[i] == m2 and arr1[i] != m1:
			c += arr1[i] - m1
	return c
try:
	t = int(input())
	for _ in range(t):
		l = int(input())
		arr1 = list(map(int, input().split()))
		arr2 = list(map(int, input().split()))
		print(solve(l, arr1, arr2))
except EOFError:
	pass


t = int(input())
for _ in range(0, t):
	n = int(input())
	result = 0
	alist = list(map(int, input().split()))
	blist = list(map(int, input().split()))
	amin = min(alist)
	bmin = min(blist)
	for i in range(0, n):
		da = alist[i] - amin
		db = blist[i] - bmin
		realmin = min(da, db)
		alist[i] -= realmin
		blist[i] -= realmin
		result += realmin
	for i in range(0, n):
		da = alist[i] - amin
		db = blist[i] - bmin
		result += da
		result += db
	print(result)


def equalizing_gifts(l1, l2):
	min_1 = min(l1)
	min_2 = min(l2)
	count = 0
	for num_gift in range(len(l1)):
		while l1[num_gift] != min_1 or l2[num_gift] != min_2:
			if l1[num_gift] == min_1:
				count += l2[num_gift] - min_2
				l2[num_gift] = min_2
			elif l2[num_gift] == min_2:
				count += l1[num_gift] - min_1
				l1[num_gift] = min_1
			else:
				diff_1 = l1[num_gift] - min_1
				diff_2 = l2[num_gift] - min_2
				if diff_1 < diff_2:
					count += diff_1
					l1[num_gift] -= diff_1
					l2[num_gift] -= diff_1
				else:
					count += diff_2
					l1[num_gift] -= diff_2
					l2[num_gift] -= diff_2
	return count
number_banks = int(input())
for _ in range(number_banks):
	num_elem_in_bank = input()
	bank_oranges = [int(el) for el in input().split(' ')]
	bank_candies = [int(el) for el in input().split(' ')]
	print(equalizing_gifts(bank_oranges, bank_candies))


import sys
input = sys.stdin.buffer.readline

def ch():
	n = int(input())
	a = list(map(int, input().split()))
	am = min(a)
	b = list(map(int, input().split()))
	bm = min(b)
	an = 0
	for i in range(n):
		ans = max(abs(am - a[i]), abs(bm - b[i]))
		an += ans
	print(an)
t = int(input())
while t:
	t -= 1
	ch()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	for i in range(len(a)):
		a[i] -= ma
	for i in range(len(b)):
		b[i] -= mb
	ans = 0
	for i in range(len(a)):
		ans += min(a[i], b[i]) + abs(a[i] - b[i])
	print(ans)


def giftFixing(a, b):
	minA = min(a)
	minB = min(b)
	count = 0
	for i in range(len(a)):
		x = a[i] - minA
		y = b[i] - minB
		count += abs(x - y) + min(x, y)
	return count
n = int(input())
outputs = []
for i in range(n):
	l = int(input())
	s = input() + ' '
	r = input() + ' '
	a = [None] * l
	b = [None] * l
	for j in range(l):
		c = s.find(' ')
		d = r.find(' ')
		a[j] = int(s[0:c])
		b[j] = int(r[0:d])
		s = s[c + 1:len(s)]
		r = r[d + 1:len(r)]
	outputs.append(giftFixing(a, b))
for x in outputs:
	print(x)


t = int(input())
for _ in range(t):
	n = int(input())
	carr = list(map(int, input().split()))
	oarr = list(map(int, input().split()))
	c = min(carr)
	o = min(oarr)
	ans = 0
	for i in range(n):
		temp = min(carr[i] - c, oarr[i] - o)
		ans += carr[i] - c - temp
		ans += oarr[i] - o - temp
		ans += temp
	print(ans)


t = int(input())
for t in range(t):
	a = int(input())
	n = list(map(int, input().split()))[:a]
	m = list(map(int, input().split()))[:a]
	dec = 0
	minn = min(n)
	minm = min(m)
	for i in range(a):
		dec += max(n[i] - minn, m[i] - minm)
	print(dec)


t = int(input())
for _ in range(t):
	n = int(input())
	num_candies = list(map(int, input().split()))
	num_oranges = list(map(int, input().split()))
	final_num_candies = min(num_candies)
	final_num_oranges = min(num_oranges)
	num_moves = 0
	gift_no = 0
	for gift_no in range(n):
		if num_candies[gift_no] != final_num_candies and num_oranges[gift_no] != final_num_oranges:
			num_moves += num_candies[gift_no] - final_num_candies + (num_oranges[gift_no] - final_num_oranges) - min(num_candies[gift_no] - final_num_candies, num_oranges[gift_no] - final_num_oranges)
		elif num_candies[gift_no] != final_num_candies:
			num_moves += num_candies[gift_no] - final_num_candies
		elif num_oranges[gift_no] != final_num_oranges:
			num_moves += num_oranges[gift_no] - final_num_oranges
	print(num_moves)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	ad = 0
	bd = 0
	bmin = min(b)
	s = 0
	for i in range(n):
		ad = a[i] - amin
		bd = b[i] - bmin
		s = s + max(ad, bd)
	print(s)
	t = t - 1


t = int(input())
for t_qr in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	a_1 = min(a)
	b_1 = min(b)
	c = 0
	for i in range(n):
		if a[i] > b[i] or a[i] > a_1:
			c = c + (a[i] - a_1)
			x = b[i] - (a[i] - a_1)
			if x > b_1:
				c = c + (x - b_1)
		elif b[i] > a[i] or b[i] > b_1:
			c = c + (b[i] - b_1)
			y = a[i] - (b[i] - b_1)
			if y > a_1:
				c = c + (y - a_1)
	print(c)


def func(arr1, arr2, n):
	m1 = min(arr1)
	m2 = min(arr2)
	ans = 0
	for i in range(n):
		ans += max(arr1[i] - m1, arr2[i] - m2)
	return ans

def main():
	for tc in range(int(input())):
		n = int(input())
		arr1 = [int(i) for i in input().split()]
		arr2 = [int(i) for i in input().split()]
		print(func(arr1, arr2, n))
main()


n = int(input())
for _ in range(n):
	a = int(input())
	cs = list(map(int, input().split()))
	os = list(map(int, input().split()))
	ds = sorted(cs)
	ls = sorted(os)
	minc = ds[0]
	mino = ls[0]
	tally = 0
	for x in range(a):
		tally += max(cs[x] - minc, os[x] - mino)
	print(tally)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	count = 0
	for i in range(n):
		both_sub = min(a[i] - a_min, b[i] - b_min)
		count += both_sub
		a[i] = a[i] - both_sub
		b[i] = b[i] - both_sub
		if a[i] > a_min:
			count += a[i] - a_min
		if b[i] > b_min:
			count += b[i] - b_min
	print(count)


import sys, math
try:
	(sys.stdin, sys.stdout) = (open('input.txt', 'r'), open('output.txt', 'w'))
except:
	pass
from sys import stdin, stdout
mod = int(1000000000.0 + 7)
from statistics import mode
from collections import *
from math import ceil, floor, inf, factorial, gcd, log2, sqrt, log
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()

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

def setbits(n):
	return bin(n).count('1')

def resetbits(n):
	return bin(n).count('0')

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

def ncr(n, r):
	(num, den) = (1, 1)
	r = min(n, n - r)
	for i in range(r):
		num *= n - i
		den *= i + 1
	return num // den

def ncr_p(n, r, p):
	(num, den) = (1, 1)
	r = min(r, n - r)
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * modinv(den, p) % p

def isPrime(num):
	if num <= 1:
		return False
	if num == 2 or n == 3:
		return True
	if num % 2 == 0 or num % 3 == 0:
		return False
	m = int(num ** 0.5) + 1
	for i in range(5, m, 6):
		if num % i == 0 or num % (i + 2) == 0:
			return False
	return True

def bin_search(arr, low, high, val):
	while low <= high:
		mid = low + (high - low) // 2
		if arr[mid] == val:
			return mid
		elif arr[mid] < val:
			low = mid + 1
		else:
			high = mid - 1
	return -1

def sumofdigit(num):
	count = 0
	while num:
		count += num % 10
		num //= 10
	return count

def inputmatrix():
	(r, c) = iia()
	mat = [0] * r
	for i in range(r):
		mat[i] = iia()
	return (r, c, mat)

def prefix_sum(n, arr):
	for i in range(1, n):
		arr[i] += arr[i - 1]
	return arr

def binomial(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def divisors(n):
	res = []
	for i in range(1, ceil(sqrt(n)) + 1):
		if n % i == 0:
			if i == n // i:
				res.append(i)
			else:
				res.append(i)
				res.append(n // i)
	return res

def fun(n, arr):
	flag = True
	for i in range(n - 1):
		if abs(arr[i] - arr[i + 1]) > 1:
			return False
	return True
for _ in range(ii1()):
	n = ii1()
	arr = iia()
	ar = iia()
	a = min(arr)
	b = min(ar)
	res = 0
	for i in range(n):
		extra = arr[i] - a
		extra2 = ar[i] - b
		res += abs(extra - extra2)
		res += min(extra, extra2)
	print(res)


import sys

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

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

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
	n = iinput()
	a = get_list()
	b = get_list()
	ai = min(a)
	bi = min(b)
	ans = 0
	for i in range(n):
		m1 = a[i] - ai
		m2 = b[i] - bi
		ans += min(m1, m2) + abs(m1 - m2)
	print(ans)


def f(n, candies, oranges, min_candy, min_orange):
	ans = 0
	for i in range(n):
		candy = candies[i]
		orange = oranges[i]
		cd = candy - min_candy
		og = orange - min_orange
		ans += max(cd, og)
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	min_candy = min(candies)
	oranges = list(map(int, input().split()))
	min_orange = min(oranges)
	print(f(n, candies, oranges, min_candy, min_orange))


for i in range(int(input())):
	n = int(input())
	apple = [int(x) for x in input().split()]
	orange = [int(x) for x in input().split()]
	min_apple = min(apple)
	min_orng = min(orange)
	moves = 0
	for j in range(n):
		org = orange[j] - min_orng
		app = apple[j] - min_apple
		moves += max(org, app)
	print(moves)


test = int(input())
while test != 0:
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	amin = min(a)
	bmin = min(b)
	count = 0
	for i in range(n):
		if a[i] == amin and b[i] == bmin:
			continue
		else:
			xmin = a[i] - amin
			ymin = b[i] - bmin
			nowmin = min(xmin, ymin)
			count += nowmin
			xmin -= nowmin
			ymin -= nowmin
			count += xmin + ymin
	print(count)
	test -= 1


test = int(input())
for _ in range(test):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	min1 = min(arr1)
	min2 = min(arr2)
	count = 0
	for i in range(n):
		sub1 = arr1[i] - min1
		sub2 = arr2[i] - min2
		count += sub1 + sub2 - min(sub1, sub2)
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	sol = 0
	for s in range(n):
		sol += max(a[s] - x, b[s] - y)
	print(sol)


t = int(input())
for i in range(t):
	a = int(input())
	b = [int(s) for s in input().split()]
	bb = [int(s) for s in input().split()]
	minb = min(b)
	minbb = min(bb)
	sss = 0
	for k in range(a):
		t = b[k] - minb
		tt = bb[k] - minbb
		sss += max(t, tt)
	print(sss)


for i in range(int(input())):
	ans = 0
	n = int(input())
	candys = [*map(int, input().split())]
	mnc = min(candys)
	oranges = [*map(int, input().split())]
	mno = min(oranges)
	for j in range(n):
		ans += max(candys[j] - mnc, oranges[j] - mno)
	print(ans)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	moves = 0
	a_min = min(a)
	b_min = min(b)
	a = [i - a_min for i in a]
	b = [i - b_min for i in b]
	for i in range(n):
		p = a[i]
		q = b[i]
		moves += max(p, q)
	print(moves)
t = int(input())
for test in range(t):
	solve()


def solve(n, a, b):
	(min_a, min_b) = (min(a), min(b))
	moves = 0
	for i in range(n):
		if a[i] > min_a and b[i] > min_b:
			moves += max(a[i] - min_a, b[i] - min_b)
		elif a[i] > min_a:
			moves += a[i] - min_a
		else:
			moves += b[i] - min_b
	return moves
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(n, a, b))


for j in range(int(input())):
	a = int(input())
	b1 = list(map(int, input().split()))
	c1 = list(map(int, input().split()))
	h = 0
	b = min(b1)
	c = min(c1)
	for i in range(a):
		if b1[i] - b >= c1[i] - c:
			h = h + b1[i] - b
		else:
			h = h + c1[i] - c
	print(h)


T = int(input())
for i in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(x, y) = (min(a), min(b))
	m = 0
	for j in range(n):
		d = abs(a[j] - x)
		c = abs(b[j] - y)
		m += max(c, d)
	print(m)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	out = 0
	for i in range(n):
		out += max(a[i] - x, b[i] - y)
	print(out)


import sys, os, io

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

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

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

def ws(s):
	sys.stdout.write(s + '\n')

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		n = ri()
		a = ria()
		b = ria()
		za = min(a)
		zb = min(b)
		tc = 0
		for i in range(n):
			da = a[i] - za
			db = b[i] - zb
			tc += max(da, db)
		print(tc)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ya = list(map(int, input().split()))
	a = min(ar)
	b = min(ya)
	c = 0
	for i in range(n):
		x = abs(a - ar[i])
		y = abs(b - ya[i])
		z = min(x, y)
		c = c + x + y - z
	print(c)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	ans = 0
	for i in range(len(a)):
		if a[i] > a_min and b[i] > b_min:
			if a[i] - a_min > b[i] - b_min:
				ans += b[i] - b_min
				ans += a[i] - (b[i] - b_min) - a_min
			else:
				ans += a[i] - a_min
				ans += b[i] - (a[i] - a_min) - b_min
		elif a[i] > a_min:
			ans += a[i] - a_min
		else:
			ans += b[i] - b_min
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	moves = 0
	for i in range(n):
		temp_a = max(0, a[i] - min_a)
		temp_b = max(0, b[i] - min_b)
		if temp_a <= temp_b:
			moves += b[i] - min_b
		else:
			moves += a[i] - min_a
	print(moves)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(m1, m2) = (min(a), min(b))
	c = 0
	for i in range(n):
		c = c + max(abs(a[i] - m1), abs(b[i] - m2))
	print(c)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	move = 0
	for i in range(n):
		d = abs(a[i] - min(a))
		move += d
		if b[i] - d >= min(b):
			b[i] = b[i] - d
			move += b[i] - min(b)
		else:
			b[i] = min(b)
	print(move)


from sys import stdin, stdout
x = lambda : list(map(int, stdin.readline().strip().split()))

def func(arra, arrb):
	m = 0
	ans = 0
	checka = min(arra)
	checkb = min(arrb)
	for i in range(0, len(arra)):
		a = arra[i] - checka
		b = arrb[i] - checkb
		ans += max(a, b)
	return ans
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	arra = x()
	arrb = x()
	ans = func(arra, arrb)
	print(ans)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	minnA = min(A)
	minnB = min(B)
	c = 0
	i = 0
	while i < N:
		if A[i] > minnA and B[i] > minnB:
			c += min(A[i] - minnA, B[i] - minnB)
			if A[i] - minnA >= B[i] - minnB:
				c += A[i] - minnA - (B[i] - minnB)
				i += 1
			else:
				c += B[i] - minnB - (A[i] - minnA)
				i += 1
		elif A[i] > minnA:
			c += A[i] - minnA
			i += 1
		elif B[i] > minnB:
			c += B[i] - minnB
			i += 1
		else:
			i += 1
	print(c)


t = int(input())
while t > 0:
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	a = set(x)
	b = set(y)
	temp = 0
	s = 0
	k = 0
	r = 0
	o = min(x)
	p = min(y)
	if len(a) == 1 and len(b) == 1:
		print('0')
	else:
		for i in range(0, n):
			if x[i] > o and y[i] > p:
				s = min(x[i], y[i]) - min(o, p)
				temp += s
				x[i] = x[i] - s
				y[i] = y[i] - s
			if x[i] > o:
				k = x[i] - o
				temp += k
				x[i] = x[i] - k
			if y[i] > p:
				r = y[i] - p
				temp += r
				y[i] = y[i] - r
		print(temp)
	t = t - 1


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()]
	min_oranges = min(a)
	min_candies = min(b)
	moves = 0
	for i in range(n):
		moves += max(abs(a[i] - min_oranges), abs(b[i] - min_candies))
	print(moves)


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	A_min = min(A)
	B_min = min(B)
	diff_A = [A[j] - A_min for j in range(n)]
	diff_B = [B[j] - B_min for j in range(n)]
	moves = 0
	for j in range(n):
		moves += max(diff_A[j], diff_B[j])
	print(moves)


t = int(input())
for i in range(t):
	n = int(input())
	moves = 0
	candies = [int(x) for x in input().split()]
	oranges = [int(x) for x in input().split()]
	c = min(candies)
	o = min(oranges)
	for j in range(n):
		moves += max(candies[j] - c, oranges[j] - o)
	print(moves)


for i in range(int(input())):
	n = int(input())
	(a, b) = ([int(num) for num in input().split()], [int(num) for num in input().split()])
	(tar_a, tar_b) = (min(a), min(b))
	ans = 0
	for i in range(n):
		ans += max(a[i] - tar_a, b[i] - tar_b)
	print(ans)


import math
import sys
t = int(input())
for cs in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	ax = bx = 2000000000
	for x in ar:
		ax = min(ax, x)
	for x in br:
		bx = min(bx, x)
	ans = 0
	for i in range(n):
		ans += max(ar[i] - ax, br[i] - bx)
	print(ans)


def gifts_fix(n, a, b):
	m1 = min(a)
	m2 = min(b)
	count = 0
	if len(set(a)) == 1 and len(set(b)) == 1:
		return 0
	for i in range(n):
		if a[i] != m1 and b[i] != m2:
			k = min(a[i] - m1, b[i] - m2)
			count += k
			a[i] -= k
			b[i] -= k
		if a[i] != m1:
			count += a[i] - m1
			a[i] = m1
		if b[i] != m2:
			count += b[i] - m2
			b[i] = m2
		i += 1
	return count
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(gifts_fix(n, a, b))


def func():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	co = 0
	c = []
	d = []
	for i in a:
		c.append(i - ma)
	for i in b:
		d.append(i - mb)
	for i in range(0, n):
		co += max(c[i], d[i])
	return co
for _ in range(int(input())):
	print(func())


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 solve():
	n = inp()
	a = inlt()
	b = inlt()
	if n == 1:
		return 0
	minA = min(a)
	minB = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - minA, b[i] - minB)
	return ans
t = inp()
while t > 0:
	print(solve())
	t -= 1


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 main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		b = LI()
		c = min(a)
		d = min(b)
		r = 0
		for (e, f) in zip(a, b):
			g = e - c
			h = f - d
			r += max(g, h)
		rr.append(r)
	return JA(rr, '\n')
print(main())


t = int(input())
for i in range(t):
	l = int(input())
	c = [int(i) for i in input().split()]
	o = [int(i) for i in input().split()]
	cm = min(c)
	om = min(o)
	steps = 0
	for i in range(l):
		ca = c[i] - cm
		oa = o[i] - om
		steps += min(ca, oa) + abs(ca - oa)
	print(steps)


t = int(input())
for j in range(t):
	n = int(input())
	lista = list(map(int, input().split()))
	listb = list(map(int, input().split()))
	moves = 0
	a = min(lista)
	b = min(listb)
	for i in range(len(lista)):
		diffa = lista[i] - a
		diffb = listb[i] - b
		if diffa != 0:
			if diffa > diffb:
				moves += diffa
				lista[i] = lista[i] - diffa
				listb[i] = listb[i] - diffb
			else:
				moves += diffa
				lista[i] = lista[i] - diffa
				listb[i] = listb[i] - diffa
	for i in range(len(listb)):
		diffb = listb[i] - b
		if diffb != 0:
			moves += diffb
	print(moves)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = sorted(a)
	b1 = sorted(b)
	a1 = a1[0]
	b1 = b1[0]
	moves = 0
	for k in range(n):
		moves += max(abs(a[k] - a1), abs(b[k] - b1))
	print(moves)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(m1, m2) = (min(a), min(b))
	res = 0
	for i in range(n):
		p = a[i] - m1
		q = b[i] - m2
		res += max(p, q)
	print(res)


import sys, collections, math

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

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

def input():
	return sys.stdin.readline().strip()
mod = 1000000007
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	b = get_array()
	count = 0
	mini_A = min(a)
	mini_B = min(b)
	if all((a[0] == a[i] for i in range(n))) and all((b[0] == b[i] for i in range(n))):
		print(0)
		continue
	for i in range(n):
		if a[i] > mini_A and b[i] > mini_B:
			count += max(a[i] - mini_A, b[i] - mini_B)
		elif a[i] == mini_A and b[i] > mini_B:
			count += b[i] - mini_B
		elif a[i] > mini_A and b[i] == mini_B:
			count += a[i] - mini_A
		elif a[i] == mini_A and b[i] == mini_B:
			continue
	print(count)


n = int(input())
for i in range(n):
	s = 0
	a = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	p = min(x)
	q = min(y)
	for i in range(a):
		if x[i] > p or y[i] > q:
			s = s + max(x[i] - p, y[i] - q)
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	d = min(b)
	e = 0
	f = 0
	z = 0
	for i in range(n):
		e = a[i] - c
		f = b[i] - d
		z = z + (abs(e - f) + min(e, f))
	print(z)


tc = int(input())
for ctr in range(tc):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = 0
	p = min(a)
	q = min(b)
	for i in range(n):
		x += max(a[i] - p, b[i] - q)
	print(x)


t = int(input())
c = []
for j in range(t):
	n = int(input())
	a = [int(u) for u in input().split()]
	b = [int(u) for u in input().split()]
	total = 0
	x = min(a)
	y = min(b)
	for i in range(n):
		candies = a[i] - x
		oranges = b[i] - y
		if candies <= oranges:
			total += candies
			total += oranges - candies
		else:
			total += oranges
			total += candies - oranges
	c.append(total)
for k in c:
	print(k)


def main():
	t = int(input())
	while t:
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		minm_a = min(a)
		minm_b = min(b)
		a_i = []
		b_i = []
		count = 0
		for i in range(n):
			a_i.append(abs(minm_a - a[i]))
			b_i.append(abs(minm_b - b[i]))
		for i in range(n):
			count += max(a_i[i], b_i[i])
		print(count)
		t -= 1
main()


t = int(input())
for p in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	moves = 0
	for i in range(n):
		if a[i] == amin and b[i] == bmin:
			continue
		elif a[i] == amin and b[i] != bmin:
			moves += b[i] - bmin
		elif a[i] != amin and b[i] == bmin:
			moves += a[i] - amin
		elif a[i] != amin and b[i] != bmin:
			minab = min(a[i] - amin, b[i] - bmin)
			moves += minab
			if a[i] - minab > amin:
				moves += a[i] - minab - amin
			elif b[i] - minab > bmin:
				moves += b[i] - minab - bmin
	print(moves)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if len(set(a)) == 1 and len(set(b)) == 1:
		print('0')
	else:
		am = min(a)
		bm = min(b)
		count = 0
		for j in range(n):
			x = a[j] - am
			y = b[j] - bm
			if y > x:
				count += y
			else:
				count += x
		print(count)


def mine(lt):
	mi = lt[0]
	for i in range(len(lt)):
		if lt[i] < mi:
			mi = lt[i]
	return mi
q = int(input())
for d in range(q):
	ast = int(input())
	lt = list(map(int, input().split(' ')))
	lt1 = list(map(int, input().split(' ')))
	mi1 = mine(lt)
	mi2 = mine(lt1)
	moves = 0
	for i in range(ast):
		a = lt[i]
		b = lt1[i]
		temp1 = a - mi1
		temp2 = b - mi2
		se = max(temp1, temp2)
		moves = moves + se
	print(moves)


z = int(input())
for j in range(z):
	n = int(input())
	str1 = input()
	str2 = input()
	l1 = [int(x) for x in str1.split()]
	l2 = [int(x) for x in str2.split()]
	buff_l1 = 0
	buff_l2 = 0
	kol = 0
	min_l1 = min(l1)
	min_l2 = min(l2)
	for i in range(n):
		buff_l1 = l1[i] - min_l1
		buff_l2 = l2[i] - min_l2
		kol = kol + max(buff_l1, buff_l2)
	print(kol)


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	am = min(A)
	bm = min(B)
	ans = 0
	for (a, b) in zip(A, B):
		ans += max(a - am, b - bm)
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = [int(num) for num in input().split()]
	b = [int(num) for num in input().split()]
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		c = c + max(a[i] - ma, b[i] - mb)
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	ans = 0
	for i in range(n):
		x = a[i] - am
		y = b[i] - bm
		z = abs(x - y)
		t = z + min(x, y)
		ans += t
	print(ans)


t = int(input())
for test in range(t):
	n = int(input())
	c = [int(x) for x in input().split()]
	o = [int(x) for x in input().split()]
	if n == 1:
		print('0')
	else:
		moves = 0
		minO = min(o)
		minC = min(c)
		for i in range(n):
			diffC = c[i] - minC
			diffO = o[i] - minO
			if diffO > 0 and diffC == 0:
				moves = moves + diffO
			elif diffC > 0 and diffO == 0:
				moves = moves + diffC
			elif diffC > 0 and diffO > 0:
				if diffC > diffO:
					moves = moves + diffC
				else:
					moves = moves + diffO
		print(moves)


size = int(input())
for x in range(size):
	min_1 = 1000000000
	min_2 = 1000000000
	length = int(input())
	first = []
	second = []
	first_arr = input().split()
	second_arr = input().split()
	count = 0
	for j in range(length):
		a = int(first_arr[j])
		b = int(second_arr[j])
		first.append(a)
		second.append(b)
		if a < min_1:
			min_1 = a
		if b < min_2:
			min_2 = b
	for s in range(length):
		a_diff = abs(first[s] - min_1)
		b_diff = abs(second[s] - min_2)
		if a_diff < b_diff:
			mm = a_diff
		else:
			mm = b_diff
		count += abs(a_diff - b_diff) + mm
	print(count)


import sys

def main():
	res = ''
	input = sys.stdin.readline
	print = sys.stdout.write
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		k = 0
		am = min(a)
		bm = min(b)
		for i in range(n):
			k += max(a[i] - am, b[i] - bm)
		res += str(k) + '\n'
	print(res)
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k1 = min(a)
	k2 = min(b)
	c = 0
	for j in range(n):
		if a[j] == k1 and b[j] == k2:
			pass
		elif a[j] != k1 and b[j] != k2:
			r1 = min(abs(k1 - a[j]), abs(k2 - b[j]))
			r2 = max(abs(k1 - a[j]), abs(k2 - b[j]))
			c = c + r1
			c = c + (r2 - r1)
		elif a[j] == k1 and b[j] != k2:
			c = c + abs(b[j] - k2)
		elif a[j] != k1 and b[j] == k2:
			c = c + abs(a[j] - k1)
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	totalmoves = 0
	least_apples = min(a)
	least_oranges = min(b)
	for i in range(n):
		totalmoves += max(a[i] - least_apples, b[i] - least_oranges)
	print(totalmoves)


import sys, heapq

def get_ints():
	return map(int, I().split())

def get_list():
	return list(map(int, I().split()))

def I():
	return sys.stdin.readline().strip()
for t in range(int(I())):
	n = int(I())
	A = get_list()
	B = get_list()
	a = min(A)
	b = min(B)
	sum = 0
	for i in range(n):
		sum += max(A[i] - a, B[i] - b)
	print(sum)


import os
from collections import defaultdict, deque
is_dev = 'vscode' in os.environ
if is_dev:
	inF = open('in.txt', 'r')
	outF = open('out.txt', 'w')

def ins(r):
	return list(map(int, r.split(' ')))

def input_():
	if is_dev:
		return inF.readline()[:-1]
	else:
		return input()

def print_(data):
	if is_dev:
		outF.write(str(data) + '\n')
	else:
		print(data)
for _ in range(int(input_())):
	input_()
	a = ins(input_())
	b = ins(input_())
	min_a = min(a)
	min_b = min(b)
	step = 0
	for i in range(len(a)):
		a[i] -= min_a
		b[i] -= min_b
		step += max(a[i], b[i])
	print_(step)
if is_dev:
	outF.close()

	def compare_file():
		print(open('out.txt', 'r').read() == open('outactual.txt', 'r').read())
	compare_file()


def solve(l, arr1, arr2):
	min_arr1 = min(arr1)
	min_arr2 = min(arr2)
	ans = 0
	for i in range(l):
		diff1 = abs(arr1[i] - min_arr1)
		diff2 = abs(arr2[i] - min_arr2)
		ans += max(diff1, diff2)
	print(ans)
test_case = int(input())
while test_case != 0:
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	solve(n, a, b)
	test_case -= 1


for _ in range(int(input())):
	(n,) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(aa, bb) = (min(a), min(b))
	print(sum((max(u - aa, v - bb) for (u, v) in zip(a, b))))


def solve(n, a, b):
	minA = min(a)
	minB = min(b)
	steps = 0
	for i in range(n):
		if a[i] > minA:
			if b[i] > minB:
				steps -= min(a[i] - minA, b[i] - minB)
			steps += a[i] - minA
		if b[i] > minB:
			steps += b[i] - minB
	return steps
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(n, a, b))


t = int(input())
for i in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	x = list(map(int, input().split()))
	minl = min(l)
	minx = min(x)
	count = 0
	for i in range(0, n):
		test1 = l[i] - minl
		test2 = x[i] - minx
		count += max(test1, test2)
	print(count)


t = int(input())
while t > 0:
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	c = min(l1)
	o = min(l2)
	count = 0
	for i in range(n):
		count += max(l1[i] - c, l2[i] - o)
	print(count)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	s = 0
	for i in range(0, n):
		ad = a[i] - am
		bd = b[i] - bm
		s += max(ad, bd)
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c1 = min(a)
	c2 = min(b)
	ans = 0
	for i in range(n):
		(p, q) = (a[i] - c1, b[i] - c2)
		ans += max(p, q)
	print(ans)


for NaN in range(int(input())):
	cou = 0
	tmp = int(input())
	chater = []
	tmp_arr1 = [int(x) for x in input().split()]
	tmp_arr2 = [int(x) for x in input().split()]
	f_min = min(tmp_arr1)
	s_min = min(tmp_arr2)
	for i in range(tmp):
		chater.append([tmp_arr1[i], tmp_arr2[i]])
	for i in range(tmp):
		cur = chater[i]
		if cur[0] > f_min and cur[1] > s_min:
			g_min = min(cur[0] - f_min, cur[1] - s_min)
			chater[i][0] -= g_min
			chater[i][1] -= g_min
			cou += g_min
	for i in range(tmp):
		cur = chater[i]
		cou += cur[0] - f_min
		cou += cur[1] - s_min
	print(cou)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

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

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	moves = 0
	for i in range(n):
		temp1 = 0
		temp2 = 0
		if a[i] != ma:
			temp1 += a[i] - ma
		if b[i] != mb:
			temp2 += b[i] - mb
		moves += max(temp1, temp2)
	print(moves)


for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - x, b[i] - y)
	print(ans)


import sys
input = sys.stdin.buffer.readline

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	ans = 0
	for i in range(n):
		x = a[i]
		y = b[i]
		if a[i] != ma and b[i] != mb:
			ans += min(x - ma, y - mb)
			a[i] -= min(x - ma, y - mb)
			b[i] -= min(x - ma, y - mb)
		ans += a[i] - ma
		ans += b[i] - mb
	print(ans)
t = int(input())
for _ in range(t):
	solution()


t = int(input())
for q in range(0, t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ma = min(a)
	mb = min(b)
	ans = 0
	for i in range(0, n):
		diff1 = a[i] - ma
		diff2 = b[i] - mb
		if diff1 == diff2:
			ans += diff1
		else:
			ans += max(diff2, diff1)
	print(ans)


import sys
import math
from math import *
from collections import defaultdict
import os
from io import BytesIO, IOBase
from collections import deque

def main(d):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	b = min(arr2)
	a = min(arr1)
	cnt = 0
	for i in range(n):
		cnt += max(arr2[i] - b, arr1[i] - a)
	print(cnt)
d = defaultdict(lambda : 0)
for i in range(int(input())):
	main(d)


from statistics import *
testcases = int(input())
lis = []
for i in range(testcases):
	children = int(input())
	c = tuple(map(int, input().split(' ')))
	o = tuple(map(int, input().split(' ')))
	tup = (c, o, children)
	lis.append(tup)

def minimizer(candies, oranges, kids):
	cval = min(candies)
	oval = min(oranges)
	count = 0
	for i in range(kids):
		a = candies[i]
		b = oranges[i]
		needa = a - cval
		needb = b - oval
		if needa > needb or needa == needb:
			count += needa
		elif needb > needa:
			count += needb
	return count
for i in lis:
	print(minimizer(i[0], i[1], i[2]))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	i = 0
	while i < n:
		diffa = a[i] - amin
		diffb = b[i] - bmin
		ans += max(diffa, diffb)
		i += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	amin = min(a)
	b = list(map(int, input().split()))
	bmin = min(b)
	final = 0
	j = 0
	for i in range(n):
		if a[i] != amin and b[i] != bmin:
			k2 = max(a[i] - amin, b[i] - bmin)
			final = final + k2
		else:
			final = final + (a[i] - amin) + (b[i] - bmin)
	print(final)


x = int(input())
for i in range(x):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	s_a = 0
	s_b = 0
	s = 0
	j = 0
	while j < n:
		s_a = a[j] - min_a
		s_b = b[j] - min_b
		s += max(s_a, s_b)
		j += 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	(min_a, min_b) = (min(a), min(b))
	eat = 0
	for i in range(n):
		d_a = a[i] - min_a
		d_b = b[i] - min_b
		m = min(d_a, d_b)
		eat += m + d_a + d_b - 2 * m
	print(eat)


n = int(input())
for i in range(n):
	num = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	mina = min(a)
	minb = min(b)
	cnt = 0
	for i in range(num):
		cnt += max(a[i] - mina, b[i] - minb)
	print(cnt)


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	ans = 0
	for i in range(n):
		x = a[i] - m1
		y = b[i] - m2
		ans += min(x, y) + (max(x, y) - min(x, y))
	print(ans)


I = input
for _ in range(int(I())):
	n = int(I())
	a = list(map(int, I().split()))
	b = list(map(int, I().split()))
	ans = 0
	am = min(a)
	bm = min(b)
	for i in range(n):
		if a[i] > am and b[i] > bm:
			ans += min(a[i] - am, b[i] - bm)
			ans += max(a[i] - am, b[i] - bm) - min(a[i] - am, b[i] - bm)
		elif a[i] != am or b[i] != bm:
			if a[i] != am:
				ans += a[i] - am
			if b[i] != bm:
				ans += b[i] - bm
	print(ans)


def fun(arr, brr, n):
	am = min(arr)
	bm = min(brr)
	count = 0
	for i in range(n):
		count += max(abs(arr[i] - am), abs(brr[i] - bm))
	return count
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	print(fun(arr, brr, n))


import math
import sys
input = sys.stdin.readline

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

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

def instr():
	s = input()
	return list(s[:len(s) - 1])

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

def pbb(n, a, b):
	res = 0
	mina = min(a)
	minb = min(b)
	for i in range(n):
		minn = min(a[i] - mina, b[i] - minb)
		res += minn
		a[i] -= minn
		b[i] -= minn
		res += a[i] - mina + b[i] - minb
	return res
for _ in range(inp()):
	n = inp()
	a = inlst()
	b = inlst()
	print(pbb(n, a, b))


for z in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = min(a)
	q = min(b)
	move = 0
	for i in range(n):
		if a[i] > p and b[i] > q:
			x = min(a[i], b[i])
			if x == a[i]:
				move += a[i] - p
				b[i] -= a[i] - p
				a[i] = p
			elif x == b[i]:
				move += b[i] - q
				a[i] -= b[i] - q
				b[i] = q
	for i in range(n):
		if a[i] > p:
			move += a[i] - p
	for i in range(n):
		if b[i] > q:
			move += b[i] - q
	print(move)


gift = []
res = []
test_no = int(input())
for j in range(test_no):
	a = []
	b = []
	no = int(input())
	l1 = list(map(int, input().split()))[:no]
	l2 = list(map(int, input().split()))[:no]
	min_l1 = min(l1)
	min_l2 = min(l2)
	for x in l1:
		if x == min_l1:
			a.append(0)
		else:
			diff = x - min_l1
			a.append(diff)
	for x in l2:
		if x == min_l2:
			b.append(0)
		else:
			diff = x - min_l2
			b.append(diff)
	values = zip(a, b)
	moves = list(values)
	maxele = 0
	for (ele1, ele2) in moves:
		maxele += max(ele1, ele2)
	res.append(maxele)
for j in res:
	print(j)


n = int(input())
lst = list()
lst2 = list()
for i in range(n):
	m = int(input())
	can = list(map(int, input().rstrip().split()))
	orr = list(map(int, input().rstrip().split()))
	for i in range(m):
		x = abs(can[i] - min(can))
		y = abs(orr[i] - min(orr))
		if x > y:
			lst.append(x)
		else:
			lst.append(y)
	lst2.append(sum(lst))
	lst.clear()
lst3 = '\n'.join(map(str, lst2))
print(lst3)


for _ in range(int(input())):
	i_preze = int(input())
	cuk = [int(x) for x in input().split()]
	poma = [int(x) for x in input().split()]
	(wynik, min_c, min_p) = (0, min(cuk), min(poma))
	for x in range(i_preze):
		wynik += max(cuk[x] - min_c, poma[x] - min_p)
	print(wynik)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	m = 0
	for i in range(n):
		ad = a[i] - amin
		bd = b[i] - bmin
		m += min(ad, bd) + abs(ad - bd)
	print(m)


for _ in range(int(input())):
	t = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] > min(a) and b[i] > min(b):
			t += max(a[i] - min(a), b[i] - min(b))
		elif a[i] > min(a):
			t += a[i] - min(a)
		elif b[i] > min(b):
			t += b[i] - min(b)
	print(t)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	na = min(a)
	nb = min(b)
	ans = 0
	for i in range(n):
		da = a[i] - na
		db = b[i] - nb
		ans += max(da, db)
	print(ans)


for _ in range(int(input())):
	x = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	count = 0
	for i in range(x):
		ai = a[i] - mina
		bi = b[i] - minb
		m = max(ai, bi)
		count += m
	print(count)


def func():
	n = input()
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	c_min = min(candy)
	o_min = min(orange)
	moves = 0
	for (c, o) in zip(candy, orange):
		moves += max(c - c_min, o - o_min)
	print(moves)
t = int(input())
for i in range(t):
	func()


inp = lambda : list(map(int, input().split()))
for i in range(int(input())):
	n = int(input())
	a = inp()
	b = inp()
	mina = min(a)
	minb = min(b)
	tc = 0
	for i in range(n):
		tc = tc + max(a[i] - mina, b[i] - minb)
	print(tc)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(p, q) = (min(a), min(b))
	c = 0
	for i in range(n):
		c += max(a[i] - p, b[i] - q)
	print(c)


t = input()
t = int(t)
c = 0
for j in range(t):
	n = input()
	n = int(n)
	c = 0
	d1 = 0
	d2 = 0
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	mi1 = min(l1)
	mi2 = min(l2)
	for i in range(0, len(l1)):
		if l1[i] > mi1 and l2[i] > mi2:
			d1 = l1[i] - mi1
			d2 = l2[i] - mi2
			if d1 >= d2:
				c = c + (d1 - d2) + d2
			else:
				c = c + (d2 - d1) + d1
		if l1[i] > mi1 and l2[i] == mi2:
			c = c + l1[i] - mi1
		if l1[i] == mi1 and l2[i] > mi2:
			c = c + l2[i] - mi2
	print(c)


def gift(a, b):
	minimuma = min(a)
	minimumb = min(b)
	count = 0
	for i in range(len(a)):
		if a[i] > minimuma and b[i] > minimumb:
			value = min(b[i] - minimumb, a[i] - minimuma)
			count = count + value
			a[i] = a[i] - value
			b[i] = b[i] - value
		if a[i] > minimuma:
			count = count + a[i] - minimuma
			a[i] = minimuma
		if b[i] > minimumb:
			count = count + b[i] - minimumb
			b[i] = minimumb
	return count
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(gift(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()))
	ma = min(a)
	mb = min(b)
	k = 0
	for j in range(n):
		ra = a[j] - ma
		rb = b[j] - mb
		k += max(ra, rb)
	print(k)


t = int(input())
while t > 0:
	n = int(input())
	candies = input().split(' ')
	candies = list(map(int, candies))
	oranges = input().split(' ')
	oranges = list(map(int, oranges))
	(low_orange, low_candies) = (min(oranges), min(candies))
	res = 0
	for (a, b) in zip(oranges, candies):
		res += max(a - low_orange, b - low_candies)
	print(res)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	min1 = min(a1)
	min2 = min(b1)
	c = 0
	for j in range(0, n):
		c += max(a1[j] - min1, b1[j] - min2)
	print(c)


for _ in range(int(input())):
	length = int(input())
	a = tuple((int(i) for i in input().split()))
	b = tuple((int(i) for i in input().split()))
	min_a = min(a)
	min_b = min(b)
	total = 0
	for i in range(length):
		x = a[i] - min_a
		y = b[i] - min_b
		total += max(x, y)
	print(total)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(n):
		if a[i] > min_a and b[i] > min_b:
			dis = min(a[i] - min_a, b[i] - min_b)
			count += dis
			a[i] = a[i] - dis
			b[i] = b[i] - dis
		if a[i] > min_a:
			count += a[i] - min_a
		if b[i] > min_b:
			count += b[i] - min_b
	print(count)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import deque as que, defaultdict as vector
from bisect import bisect as bsearch
from heapq import *
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
INF = float('inf')
testcase = inin()
for Case in range(testcase):
	n = inin()
	a = inar()
	b = inar()
	ans = 0
	a1 = min(a)
	b1 = min(b)
	for i in range(n):
		ans += max(a[i] - a1, b[i] - b1)
	print(ans)


t = int(input())
while t > 0:
	perm = 0
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	for i in range(n):
		perm += max(l[i] - min(l), m[i] - min(m))
	print(perm)
	t -= 1


for _ in range(int(input())):
	h = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	an = 0
	(t1, t2) = (min(a), min(b))
	for i in range(h):
		(f, g) = (a[i] - t1, b[i] - t2)
		an += max(f, g, 0)
	print(an)


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	b = [int(x) for x in stdin.readline().split()]
	ma = min(a)
	mb = min(b)
	ans = 0
	for i in range(n):
		da = a[i] - min(a)
		db = b[i] - min(b)
		temp = min(da, db)
		ans += temp + (da - temp) + (db - temp)
	print(ans)


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	mina = min(a)
	b = list(map(int, input().split()))
	minb = min(b)
	ctr = 0
	for i in range(n):
		if a[i] > mina or b[i] > minb:
			ctr += max(a[i] - mina, b[i] - minb)
	print(ctr)


for i in range(int(input())):
	n = int(input())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	ma = min(a1)
	mb = min(b1)
	a = [a1[i] - ma for i in range(n)]
	b = [i - mb for i in b1]
	cost = 0
	for i in range(n):
		cost += a[i] + b[i] - min(a[i], b[i])
	print(cost)


import sys
import math
from collections import Counter

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	b = get_array()
	c = min(a)
	d = min(b)
	x = []
	y = []
	sumi = 0
	for i in range(n):
		x.append(a[i] - c)
		y.append(b[i] - d)
		sumi = sumi + max(x[i], y[i])
	print(sumi)


def sol(l1, l2):
	m1 = min(l1)
	m2 = min(l2)
	res = 0
	for i in range(len(l1)):
		res += max(l1[i] - m1, l2[i] - m2)
	return res
k = int(input())
for i in range(k):
	input()
	s1 = list(map(int, input().split(' ')))
	s2 = list(map(int, input().split(' ')))
	print(sol(s1, s2))


for _ in range(int(input())):
	input()
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	print(sum((max(i - min(A), j - min(B)) for (i, j) in zip(A, B))))


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		total = 0
		(mina, minb) = (min(a), min(b))
		for i in range(n):
			total += max(a[i] - mina, b[i] - minb)
		print(total)
main()


from sys import stdin, stdout
import bisect
import math
from collections import deque
mod = 10 ** 9 + 7

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 DFS(dictionary, vertex, visited):
	visited[vertex] = True
	stack = [vertex]
	print(vertex)
	while stack:
		a = stack.pop()
		for i in dictionary[a]:
			if not visited[i]:
				print(i)
				visited[i] = True
				stack.append(i)

def BFS(dictionary, vertex, visited):
	visited[vertex] = True
	q = deque()
	q.append(vertex)
	while q:
		a = q.popleft()
		for i in dictionary[a]:
			if not visited[i]:
				visited[i] = True
				q.append(i)
				print(i)

def soe(limit):
	l = [1] * (limit + 1)
	l[0] = 0
	l[1] = 0
	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 gcd(a, b):
	while b:
		a = a % b
		(b, a) = (a, b)
	return a

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()
	c = 0
	x = min(l)
	y = min(k)
	for i in range(n):
		if l[i] != x and k[i] != y:
			a = l[i] - x
			b = k[i] - y
			z = min(a, b)
			c += z
			a -= z
			b -= z
			c += max(a, b)
		else:
			c += max(l[i] - x, k[i] - y)
	pr(c)
for _ in range(inp()):
	solve()


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
sys.setrecursionlimit(10 ** 6)
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	mini1 = inf
	mini2 = inf
	for i in range(n):
		(a, b) = (l1[i], l2[i])
		mini1 = min(mini1, a)
		mini2 = min(mini2, b)
	ans = 0
	for i in range(n):
		(a, b) = (l1[i], l2[i])
		z1 = a - mini1
		z2 = b - mini2
		ans += min(z1, z2)
		b -= min(z1, z2)
		a -= min(z1, z2)
		ans += a - mini1 + b - mini2
	print(ans)


t = int(input())
for p in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	a_min = min(a)
	b_min = min(b)
	ans = 0
	for i in range(n):
		diff = min(a[i] - a_min, b[i] - b_min)
		ans += diff
		a[i] -= diff
		b[i] -= diff
		ans += a[i] - a_min + b[i] - b_min
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	c = 0
	for i in range(n):
		g = a[i] - x
		r = b[i] - y
		c += max(g, r)
	print(c)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	minA = min(A)
	minB = min(B)
	ans = 0
	for i in range(N):
		x = A[i] - minA
		y = B[i] - minB
		if x > y:
			ans += x
		else:
			ans += y
	print(ans)


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ax = min(a)
	bx = min(b)
	move = 0
	for i in range(n):
		move += max(a[i] - ax, b[i] - bx)
	print(move)


t = int(input())
for i in range(t):
	ans = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k1 = min(a)
	k2 = min(b)
	for j in range(n):
		raz1 = a[j] - k1
		raz2 = b[j] - k2
		ans += max(raz1, raz2)
	print(ans)


t = int(input())
while t:
	n = int(input())
	l1 = input().split(' ')
	l2 = input().split(' ')
	a = []
	b = []
	for i in range(n):
		x = l1[i]
		a.append(int(x))
	for i in range(n):
		x = l2[i]
		b.append(int(x))
	x = min(a)
	y = min(b)
	count = 0
	for i in range(n):
		if a[i] == x and b[i] == y:
			continue
		elif a[i] == x and b[i] != y:
			count += b[i] - y
			b[i] = y
		elif a[i] != x and b[i] == y:
			count += a[i] - x
			a[i] = x
		else:
			p = min(x, y)
			g = min(a[i], b[i]) - p
			count += g
			a[i] -= g
			b[i] -= g
			if a[i] > x:
				count += a[i] - x
			if b[i] > y:
				count += b[i] - y
	print(count)
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for (i, j) in zip(a, b):
		ans += max(i - min_a, j - min_b)
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		(ma, mb) = (min(A), min(B))
		ans = 0
		for (a, b) in zip(A, B):
			ans += a - ma + b - mb - min(a - ma, b - mb)
		print(ans)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	c_min = min(c)
	o_min = min(o)
	i = 0
	count = 0
	while i < n:
		count += max(c[i] - c_min, o[i] - o_min)
		i += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	another = list(map(int, input().split(' ')))
	low1 = min(arr)
	low2 = min(another)
	count = 0
	for i in range(n):
		count += max(arr[i] - low1, another[i] - low2)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	x = min(a)
	y = min(b)
	moves = 0
	for i in range(n):
		m = 0
		if a[i] > x:
			m = a[i] - x
		if b[i] > y:
			m = max(b[i] - y, m)
		moves += m
	print(moves)


i = int(input())
for j in range(i):
	_ = int(input())
	mov = 0
	k = list(map(int, input().split()))
	l = list(map(int, input().split()))
	kmin = min(k)
	lmin = min(l)
	for ii in range(_):
		k[ii] -= kmin
		l[ii] -= lmin
	for ii in range(_):
		if k[ii] > l[ii]:
			mov += k[ii]
		else:
			mov += l[ii]
	print(mov)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ami = min(a)
	bmi = min(b)
	out = 0
	for i in range(len(a)):
		a[i] -= ami
		b[i] -= bmi
		out += min(a[i], b[i])
		out += abs(a[i] - b[i])
	print(out)


tc = int(input())
for _ in range(0, tc):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	amin = a[0]
	bmin = b[0]
	for item in a:
		amin = min(amin, item)
	for item in b:
		bmin = min(bmin, item)
	moves = 0
	for index in range(0, n):
		moves += max(a[index] - amin, b[index] - bmin)
	print(moves)


t = int(input())
for i in range(t):
	n = int(input())
	candy = [int(i) for i in input().split()]
	orange = [int(i) for i in input().split()]
	mn_candy = min(candy)
	mn_orange = min(orange)
	eats = [max(candy[i] - mn_candy, orange[i] - mn_orange) for i in range(n)]
	print(sum(eats))


n = int(input())
for i in range(n):
	a = int(input())
	b = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
	summ = 0
	for j in range(a):
		summ = summ + max(b[j] - min(b), c[j] - min(c))
	print(summ)


t = int(input())
for _ in range(t):
	n = int(input())
	apple = list(map(int, input().split()))
	org = list(map(int, input().split()))
	res = []
	a = min(apple)
	for i in apple:
		res.append(abs(i - a))
	a = min(org)
	for (i, c) in enumerate(org):
		res[i] = max(res[i], abs(a - c))
	print(sum(res))


def solve(n, a, b):
	miniA = min(a)
	miniB = min(b)
	cnta = 0
	cntb = 0
	cnt = 0
	for i in range(n):
		if a[i] == miniA and b[i] == miniB:
			continue
		if a[i] > miniA and b[i] == miniB:
			cnta += a[i] - miniA
			a[i] = miniA
		elif a[i] == miniA and b[i] > miniB:
			cntb += b[i] - miniB
			b[i] = miniB
		elif a[i] - miniA > b[i] - miniB:
			a[i] -= b[i] - miniB
			cnt += b[i] - miniB
			cnta += a[i] - miniA
			a[i] = miniA
			b[i] = miniB
		else:
			b[i] -= a[i] - miniA
			cnt += a[i] - miniA
			cntb += b[i] - miniB
			a[i] = miniA
			b[i] = miniB
	print(cnta + cntb + cnt)
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solve(n, a, b)


t = int(input())
for i in range(0, t):
	n = int(input())
	a = list((int(num) for num in input().split()))[:n]
	b = list((int(num) for num in input().split()))[:n]
	amin = min(a)
	bmin = min(b)
	step = 0
	for j in range(0, n):
		if a[j] > amin and b[j] > bmin:
			x2 = b[j] - bmin
			x1 = a[j] - amin
			x = min(x1, x2)
			step = step + x
			a[j] = a[j] - x
			b[j] = b[j] - x
			if b[j] > bmin:
				step = step + b[j] - bmin
			elif a[j] > amin:
				step = step + a[j] - amin
		elif a[j] > amin and b[j] == bmin:
			step = step + a[j] - amin
		elif b[j] > bmin and a[j] == amin:
			step = step + b[j] - bmin
	print(step)


def lstinput():
	lst = input()
	lst = lst.split(' ')
	lst = [int(x) for x in lst]
	return lst
t = int(input())
for i in range(0, t):
	n = int(input())
	ar = lstinput()
	br = lstinput()
	m1 = min(ar)
	m2 = min(br)
	mx = max(m1, m2)
	ans = 0
	for j in range(n):
		if ar[j] >= m1 and br[j] >= m2:
			mn = min(ar[j] - m1, br[j] - m2)
			ar[j] -= mn
			br[j] -= mn
			ans += mn
		if ar[j] >= m1:
			ans += ar[j] - m1
		if br[j] >= m2:
			ans += br[j] - m2
	print(ans)


from sys import *
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	c = 0
	for i in range(n):
		x = a[i] - m1
		y = b[i] - m2
		c += max(x, y)
	print(c)


from sys import stdin
ip = stdin.readline
for _ in range(int(ip())):
	n = int(ip())
	a = list(map(int, ip().split()))
	b = list(map(int, ip().split()))
	ans = 0
	(ma, mb) = (min(a), min(b))
	for i in range(n):
		ans += max(a[i] - ma, b[i] - mb)
	print(ans)


for _ in range(int(input())):
	N = int(input())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	Amin = min(A)
	Bmin = min(B)
	X = sum(A) - min(A) * N
	Y = sum(B) - min(B) * N
	maxAB = max(Amin, Bmin)
	Total = X + Y
	for i in range(N):
		Total -= min(A[i] - Amin, B[i] - Bmin)
	print(Total)


t = int(input())
for tests in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	min_a = min(a)
	min_b = min(b)
	moves = 0
	for i in range(n):
		a_diff = a[i] - min_a
		b_diff = b[i] - min_b
		(small_diff, big_diff) = sorted([a_diff, b_diff])
		moves += small_diff
		big_diff -= small_diff
		moves += big_diff
	print(moves)


for i in range(int(input())):
	(l1, l2) = ([], [])
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	(k1, k2) = (min(l1), min(l2))
	ctr = 0
	for i in range(n):
		if l1[i] != k1 and l2[i] != k2:
			(d1, d2) = (l1[i] - k1, l2[i] - k2)
			if d1 <= d2:
				d3 = l1[i] - k1
				ctr += d3
				l2[i] -= d3
				ctr += l2[i] - k2
			else:
				d4 = l2[i] - k2
				ctr += d4
				l1[i] -= d4
				ctr += l1[i] - k1
		elif l1[i] != k1 and l2[i] == k2:
			ctr += l1[i] - k1
		elif l1[i] == k1 and l2[i] != k2:
			ctr += l2[i] - k2
	print(ctr)


for _ in range(int(input())):
	k = int(input())
	l = list(map(int, input().split()))
	li = list(map(int, input().split()))
	(ca, ora) = (0, 0)
	out = 0
	(minc, mino) = (min(l), min(li))
	for i in range(k):
		ca = abs(l[i] - minc)
		ora = abs(li[i] - mino)
		out = out + max(ca, ora)
	print(out)


t = int(input())
for z in range(t):
	n = int(input())
	count = 0
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	min_a = min(a)
	min_b = min(b)
	for j in range(n):
		count += max(a[j] - min_a, b[j] - min_b)
	print(count)


def gift_fixer():
	t = int(input())
	for i in range(t):
		n = int(input())
		candy = list(map(int, input().split()))
		oranges = list(map(int, input().split()))
		min_candy = candy[0]
		min_oranges = oranges[0]
		moves = 0
		for j in range(n):
			if candy[j] < min_candy:
				min_candy = candy[j]
			if oranges[j] < min_oranges:
				min_oranges = oranges[j]
		for j in range(n - 1, -1, -1):
			if candy[j] > min_candy and oranges[j] > min_oranges:
				if candy[j] - min_candy < oranges[j] - min_oranges:
					candy[j] -= candy[j] - min_candy
					moves += candy[j] - min_candy
				else:
					oranges[j] -= oranges[j] - min_oranges
					moves += oranges[j] - min_oranges
		for j in range(n - 1, -1, -1):
			if oranges[j] > min_oranges:
				moves += oranges[j] - min_oranges
			if candy[j] > min_candy:
				moves += candy[j] - min_candy
		print(moves)
gift_fixer()


T = int(input())
for t in range(T):
	N = input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for (ai, bi) in zip(a, b):
		ans += max(ai - amin, bi - bmin)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	brr = [int(i) for i in input().split()]
	mina = min(arr)
	minb = min(brr)
	ans = 0
	for i in range(n):
		if arr[i] - mina < brr[i] - minb:
			ans += arr[i] - mina
			arr[i] -= mina
			if brr[i] > minb:
				brr[i] -= arr[i]
			ans += brr[i] - minb
		else:
			ans += brr[i] - minb
			brr[i] -= minb
			if arr[i] > mina:
				arr[i] -= brr[i]
			ans += arr[i] - mina
	print(ans)


import math
for test in range(int(input())):
	n = int(input())
	A = list(map(int, input('').split()))
	B = list(map(int, input('').split()))
	mini_a = min(A)
	mini_b = min(B)
	ans = 0
	for i in range(n - 1, -1, -1):
		ans += max(A[i] - mini_a, B[i] - mini_b)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = min(a)
	j = min(b)
	count = 0
	for i in range(n):
		if a[i] > k and b[i] > j:
			count += max(a[i] - k, b[i] - j)
		elif a[i] > k and b[i] == j:
			count += abs(a[i] - k)
		elif a[i] == k and b[i] > j:
			count += abs(b[i] - j)
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	ma = 10000000000.0
	mb = 1610
	ma = min(a)
	mb = min(b)
	c = 0
	for j in range(n):
		c += max(a[j] - ma, b[j] - mb)
	print(c)


T = int(input())
for i in range(T):
	n = int(input())
	C = list(map(int, input().split()))
	G = list(map(int, input().split()))
	minC = C[0]
	minG = G[0]
	for i in range(n):
		minC = min(minC, C[i])
		minG = min(minG, G[i])
	nomov = 0
	for i in range(n):
		nomov += max(C[i] - minC, G[i] - minG)
	print(nomov)


import math
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(' ')]
	ma = min(a)
	mb = min(b)
	rounds = 0
	for i in range(len(a)):
		aka = a[i] - ma
		akb = b[i] - mb
		rounds += max(aka, akb)
	print(rounds)


def process():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mintup = (min(a), min(b))
	moves = 0
	for i in range(n):
		(diff1, diff2) = (a[i] - mintup[0], b[i] - mintup[1])
		common = min(diff1, diff2)
		diff1 -= common
		diff2 -= common
		moves += common
		moves += diff1 + diff2
	return moves
for i in range(int(input())):
	print(process())


import sys

def gifts_fixing(candies, oranges, n):
	i = 0
	(target_c, target_o) = (min(candies), min(oranges))
	ans = 0
	while i < n:
		temp1 = candies[i] - target_c
		temp2 = oranges[i] - target_o
		ans += max(temp1, temp2)
		i += 1
	return ans

def main():
	sys_in = sys.stdin
	sys_out = sys.stdout
	t = int(sys_in.readline())
	for i in range(t):
		n = int(sys_in.readline())
		candies = list(map(int, sys_in.readline().split()))
		oranges = list(map(int, sys_in.readline().split()))
		sys_out.write(f'{gifts_fixing(candies, oranges, n)}\n')
main()


def main(n, a, b):
	ans = 0
	for i in range(n):
		re_a = a[i] - min(a)
		re_b = b[i] - min(b)
		ans += max(re_a, re_b)
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = main(n, a, b)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	mc = min(c)
	mo = min(o)
	count = 0
	for i in range(n):
		if c[i] > mc and o[i] > mo:
			count += min(c[i] - mc, o[i] - mo)
			count += abs(c[i] - mc - (o[i] - mo))
		elif c[i] > mc:
			count += c[i] - mc
		elif o[i] > mo:
			count += o[i] - mo
	print(count)


def scanInt():
	return int(input())

def scanList():
	return [i for i in input().split(' ')]

def scanIntList():
	return [int(i) for i in scanList()]
t = scanInt()
for _ in range(t):
	n = scanInt()
	a = scanIntList()
	b = scanIntList()
	minA = min(a)
	minB = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - minA, b[i] - minB)
	print(ans)


t = int(input())
for k in range(t):
	l = int(input())
	a = input()
	a = [int(e) for e in a.split(' ')]
	b = input()
	b = [int(e) for e in b.split(' ')]
	a_min = min(a)
	b_min = min(b)
	moves = 0
	for i in range(l):
		a_diff = a[i] - a_min
		b_diff = b[i] - b_min
		moves += max(a_diff, b_diff)
	print(moves)


def run():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	answer = 0
	for i in range(n):
		na = a[i] - mina
		nb = b[i] - minb
		answer += max(na, nb)
	print(answer)
t = int(input())
for i in range(t):
	run()


t = int(input(''))
for i in range(0, t):
	n = int(input(''))
	a = list(map(int, input('').strip().split()))
	b = list(map(int, input('').strip().split()))
	t = 0
	for j in range(0, n):
		f = min(a)
		g = min(b)
		t = t + max(a[j] - f, b[j] - g)
	print(t)


def read():
	return list(map(int, input().split()))
for _ in range(int(input())):
	n = int(input())
	(a, b) = (read(), read())
	(res, ma, mb) = (0, min(a), min(b))
	for i in range(n):
		res += max(a[i] - ma, b[i] - mb)
	print(res)


for _ in range(int(input())):
	n = int(input())
	vec1 = list(map(int, input().split()))
	vec2 = list(map(int, input().split()))
	mn1 = min(vec1)
	mn2 = min(vec2)
	ans = 0
	for i in range(n):
		x = vec1[i] - mn1
		y = vec2[i] - mn2
		mn = min(x, y)
		x -= mn
		y -= mn
		ans += mn + x + y
	print(ans)


number_of_tests = int(input())
for i in range(number_of_tests):
	n = int(input())
	total = 0
	candies = [int(i) for i in input().split()]
	oranges = [int(i) for i in input().split()]
	minimum_a = min(candies)
	minimum_b = min(oranges)
	for j in range(n):
		total += abs(candies[j] - minimum_a) + abs(oranges[j] - minimum_b) - min(candies[j] - minimum_a, oranges[j] - minimum_b)
	print(total)


(t, an) = (int(input()), [])
for i in range(t):
	(n, a, b) = (int(input()), [int(j) for j in input().split()], [int(h) for h in input().split()])
	am = min(a)
	bm = min(b)
	an.append(0)
	for e in range(n):
		an[i] += max(a[e] - am, b[e] - bm)
print('\n'.join([str(i) for i in an]))


def func(C, O):
	minC = min(C)
	minO = min(O)
	noMoves = 0
	for i in range(len(C)):
		diffC = C[i] - minC
		diffO = O[i] - minO
		noMoves += abs(diffC - diffO) + min(diffC, diffO)
	return noMoves
testcases = int(input())
for t in range(testcases):
	_ = input()
	C = [int(i) for i in input().split()]
	O = [int(i) for i in input().split()]
	print(func(C, O))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	k = min(a)
	s = min(b)
	ans = 0
	for i in range(n):
		val = 0
		temp = 0
		if a[i] > k:
			val = a[i] - k
		if b[i] > s:
			temp = b[i] - s
		key = max(val, temp)
		ans += key
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minA = min(a)
	minB = min(b)
	moves = 0
	for i in range(n):
		moves += min(a[i] - minA, b[i] - minB) + max(a[i] - minA, b[i] - minB) - min(a[i] - minA, b[i] - minB)
	print(moves)


query = int(input())
for i in range(query):
	size = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	ans = 0
	min1_ = min(arr1)
	min2_ = min(arr2)
	for j in range(size):
		no1 = arr1[j] - min1_
		no2 = arr2[j] - min2_
		ans += max(no1, no2)
	print(ans)


n = int(input())
for i in range(n):
	k = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	m1 = min(l1)
	m2 = min(l2)
	ans = 0
	for i in range(k):
		if l1[i] > m1:
			ans += l1[i] - m1
		if l2[i] > m2:
			ans += l2[i] - m2
		ans -= min(l1[i] - m1, l2[i] - m2)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = 0
	m1 = min(A)
	m2 = min(B)
	for i in range(n):
		(c1, c2) = (0, 0)
		if A[i] != m1:
			c1 += abs(A[i] - m1)
		if B[i] != m2:
			c2 += abs(B[i] - m2)
		ans += max(c1, c2)
	print(ans)


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sum = 0
	y = min(a)
	z = min(b)
	for i in range(n):
		sum += max(a[i] - y, b[i] - z)
	print(sum)
	t = t - 1


n = int(input())
for num in range(n):
	t = int(input())
	count = 0
	candys = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_index_candy = candys.index(min(candys))
	min_index_orange = oranges.index(min(oranges))
	for (orange, candy) in zip(oranges, candys):
		orange_gap = orange - min(oranges)
		candy_gap = candy - min(candys)
		if orange_gap > candy_gap:
			count += orange_gap
		elif candy_gap > orange_gap:
			count += candy_gap
		else:
			count += candy_gap
	print(count)


def solve():
	n = int(input())
	candies = list(map(lambda x: int(x), input().split()))
	oranges = list(map(lambda x: int(x), input().split()))

	def findMin(nums):
		result = float('inf')
		for num in nums:
			result = min(result, num)
		return result
	minCandy = findMin(candies)
	minOrange = findMin(oranges)
	moves = 0
	for i in range(n):
		moves += max(candies[i] - minCandy, oranges[i] - minOrange)
	return moves
n = int(input())
for i in range(n):
	result = solve()
	print(result)


for ii in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	ans = 0
	for i in range(n):
		ans += b[i] - y
		if a[i] - (b[i] - y) > x:
			ans += a[i] - (b[i] - y) - x
	print(ans)


results = []
tests = int(input())
for _x in range(tests):
	n = int(input())
	candies = list((int(item) for item in input().split()))[:n]
	oranges = list((int(item) for item in input().split()))[:n]
	mnc = min(candies)
	mno = min(oranges)
	res = 0
	for x in range(len(candies)):
		res += max(candies[x] - mnc, oranges[x] - mno)
	results.append(res)
print(*results, sep='\n')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	ans = 0
	for i in range(0, n):
		aa = a[i] - am
		bb = b[i] - bm
		ss = abs(aa - bb)
		ans += ss
		mx = max(aa, bb)
		ans += mx - ss
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dable = 0
	min_a = min(a)
	min_b = min(b)
	for i in range(n):
		if a[i] != min_a and b[i] != min_b:
			dable += min(b[i] - min_b, a[i] - min_a)
		else:
			pass
	print(sum(a) - min_a * n + sum(b) - min_b * n - dable)


t = int(input())
for i in range(t):
	n = int(input())
	a_vals = [int(x) for x in input().split()]
	b_vals = [int(x) for x in input().split()]
	(a_min, b_min) = (min(a_vals), min(b_vals))
	moves = 0
	for j in range(n):
		(a_diff, b_diff) = (a_vals[j] - a_min, b_vals[j] - b_min)
		moves += min(a_diff, b_diff) + abs(b_diff - a_diff)
	print(moves)


t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	m = [int(y) for y in input().split()]
	a = min(l)
	b = min(m)
	sumn = 0
	for i in range(n):
		c = l[i] - a
		d = m[i] - b
		sumn += max(c, d)
	print(sumn)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	cnt = 0
	for i in range(n):
		if a[i] > min_a and b[i] > min_b:
			cnt += max(a[i] - min_a, b[i] - min_b)
		elif a[i] > min_a:
			cnt += a[i] - min_a
		else:
			cnt += b[i] - min_b
	print(cnt)


test_cnt = int(input())
tests = []
for _ in range(test_cnt):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	tests.append((n, a, b))
for test in tests:
	n = test[0]
	a = test[1]
	b = test[2]
	min_a = min(a)
	min_b = min(b)
	eat = 0
	for i in range(n):
		a_i = a[i] - min_a
		b_i = b[i] - min_b
		eat += max(a_i, b_i)
	print(eat)


for l in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = 0
	mina = min(a)
	minb = min(b)
	for i in range(n):
		am += max(a[i] - mina, b[i] - minb)
	print(am)


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	sum_c = 0
	sum_o = 0
	min_c = min(c)
	min_o = min(o)
	ans = 0
	for i in range(n):
		ans += max(c[i] - min_c, o[i] - min_o)
	print(ans)


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])
	m1 = min(a)
	m2 = min(b)
	count = 0
	for i in range(n):
		d1 = a[i] - m1
		d2 = b[i] - m2
		d = min(d1, d2)
		a[i] -= d
		b[i] -= d
		count += d
		count += a[i] - m1
		count += b[i] - m2
	print(count)


for _ in range(int(input())):
	n = int(input())
	l = [int(p) for p in input().split()]
	d = [int(p) for p in input().split()]
	c = 0
	minl = min(l)
	mind = min(d)
	for i in range(n):
		c = c + max(l[i] - minl, d[i] - mind)
	print(c)


T = int(input())
for t in range(T):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	mina = 1000000007
	minb = 1000000007
	for i in range(n):
		if a[i] < mina:
			mina = a[i]
		if b[i] < minb:
			minb = b[i]
	res = 0
	for i in range(n):
		res += max(a[i] - mina, b[i] - minb)
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	d1 = 0
	d2 = 0
	total = 0
	for i in range(n):
		d1 = a[i] - min_a
		d2 = b[i] - min_b
		total += max(d1, d2)
	print(total)


test_case = int(input())
while test_case:
	test_case -= 1
	k = int(input())
	first = list(map(int, input().split()))
	second = list(map(int, input().split()))
	firstmin = min(first)
	secondmin = min(second)
	ans = 0
	for idx in range(k):
		delt = first[idx] - firstmin
		ans += delt
		second[idx] = max(second[idx] - delt, secondmin)
	for idx in range(k):
		delt = second[idx] - secondmin
		ans += delt
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	s = 0
	for j in range(n):
		m = min(a[j] - ma, b[j] - mb)
		s += m
		a[j] -= m
		b[j] -= m
		s += b[j] - mb
		s += a[j] - ma
	print(s)


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	count = 0
	for i in range(n):
		d1 = a[i] - ma
		d2 = b[i] - mb
		sf = min(d2, d1)
		count += sf
		d1 -= sf
		d2 -= sf
		count += d1 + d2
	print(count)


def format_input():
	s_input = input()
	return list(map(int, s_input.split()))

def get_min_elem(a, b):
	return (min(a), min(b))

def calculate_moves():
	n = format_input()[0]
	a_list = format_input()
	b_list = format_input()
	(a_min, b_min) = get_min_elem(a_list, b_list)
	ans = 0
	for i in range(n):
		a_diff = a_list[i] - a_min
		b_diff = b_list[i] - b_min
		ans += max(a_diff, b_diff)
	return ans

def main():
	t = format_input()[0]
	for j in range(t):
		moves = calculate_moves()
		print(moves)
	return
main()


for j in range(int(input())):
	n = int(input())
	x = input().split(' ')
	y = input().split(' ')
	b = []
	a = []
	for k in x:
		a.append(int(k))
	for k in y:
		b.append(int(k))
	c = []
	d = []
	for k in a:
		c.append(k - min(a))
	for k in b:
		d.append(k - min(b))
	pocet = 0
	for i in range(n):
		pocet += max(c[i], d[i])
	print(pocet)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr1 = list(map(int, input().split()))
	k = min(arr)
	k1 = min(arr1)
	count = 0
	for i in range(n):
		if arr[i] > k and arr1[i] > k1:
			count += max(arr[i] - k, arr1[i] - k1)
		elif arr[i] > k:
			count += arr[i] - k
		elif arr1[i] > k1:
			count += arr1[i] - k1
	print(count)


n = int(input())
answer = [0] * n
for i in range(n):
	k = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	a1 = min(a)
	b1 = min(b)
	for j in range(k):
		aaa = a[j] - a1
		bbb = b[j] - b1
		answer[i] += min(aaa, bbb)
		a[j] -= min(aaa, bbb)
		b[j] -= min(aaa, bbb)
		answer[i] += a[j] - a1 + b[j] - b1
for i in range(n):
	print(answer[i])


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	cost = 0
	for i in range(n):
		cost += max(a[i] - a_min, b[i] - b_min)
	print(cost)

def main():
	t = int(input())
	while t:
		solve()
		t -= 1
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	am = min(a)
	b = list(map(int, input().split()))
	bm = min(b)
	f = 0
	for i in range(n):
		da = a[i] - am
		db = b[i] - bm
		f += max(da, db)
	print(f)


from collections import defaultdict as dd
from collections import Counter as ctr
from sys import stdin, stdout
from math import log, sqrt
from itertools import permutations
from itertools import combinations
from bisect import bisect_left, insort
for t in range(int(stdin.readline().strip())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	s = 0
	for i in range(n):
		s += max(a[i] - am, b[i] - bm)
	print(s)


for tc in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	k = min(l1)
	p = min(l2)
	moves = 0
	for i in range(n):
		l1[i] -= k
		l2[i] -= p
		moves += max(l1[i], l2[i])
	print(moves)


def gifts(n, c, o):
	mc = min(c)
	mo = min(o)
	m = 0
	for i in range(n):
		if o[i] == mo:
			if c[i] == mc:
				continue
			elif c[i] > mc:
				m += c[i] - mc
		elif o[i] > mo:
			if c[i] == mc:
				m += o[i] - mo
			elif c[i] > mc:
				moreoranges = o[i] - mo
				morecandy = c[i] - mc
				m += max(moreoranges, morecandy)
	return m
t = int(input())
array = []
for i in range(t):
	n = int(input())
	c = list(map(int, input().split(' ')))
	o = list(map(int, input().split(' ')))
	array.append([n, c, o])
for x in array:
	print(gifts(*x))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	newa = list(map(lambda x: x - min(a), a))
	newb = list(map(lambda x: x - min(b), b))
	c = 0
	for i in range(n):
		c += max(newa[i], newb[i])
	print(c)


t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	c = 0
	for i in range(n):
		a1 = a[i] - min_a
		b1 = b[i] - min_b
		d = min(a1, b1)
		a[i] -= d
		b[i] -= d
		c += d
	for i in range(n):
		if a[i] != min_a:
			c += a[i] - min_a
		if b[i] != min_b:
			c += b[i] - min_b
	print(c)


for i in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	d = {}
	min1 = min(arr1)
	min2 = min(arr2)
	farr1 = [0] * n
	farr2 = [0] * n
	for i in range(n):
		farr1[i] = arr1[i] - min1
		farr2[i] = arr2[i] - min2
	ans = []
	for i in range(n):
		ans.append(min(farr1[i], farr2[i]) + abs(farr1[i] - farr2[i]))
	print(sum(ans))


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
for case in range(1, itg() + 1):
	n = itg()
	aa = tuple(mpint())
	bb = tuple(mpint())
	min_a = min(aa)
	min_b = min(bb)
	ans = 0
	for (a, b) in zip(aa, bb):
		ans += max(a - min_a, b - min_b)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(ta, tb) = (min(a), min(b))
	ans = 0
	for i in range(n):
		ax = a[i] - ta
		bx = b[i] - tb
		ans += min(ax, bx) + abs(ax - bx)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	ami = min(ar)
	bmi = min(br)
	ans = 0
	for i in range(n):
		xx = ar[i] - ami
		yy = br[i] - bmi
		ans += max(xx, yy)
	print(ans)


def main(args):
	t = int(input())
	for i in range(t):
		n = int(input())
		arr1 = list(map(int, input().split()))
		arr2 = list(map(int, input().split()))
		m1 = min(arr1)
		m2 = min(arr2)
		ans = 0
		for i in range(len(arr1)):
			ans += max(arr1[i] - m1, arr2[i] - m2)
		print(ans)
import sys
sys.exit(main(sys.argv))


def giftFix(candy, orange):
	listDecrement(candy, min(candy))
	listDecrement(orange, min(orange))
	result = 0
	for counter in range(len(candy)):
		result += max(candy[counter], orange[counter])
	return result

def listDecrement(list1, i):
	for counter in range(len(list1)):
		list1[counter] -= i
	return

def takeInput(List):
	lis = list(map(int, input().split()))
	List.append(lis)

def __main__():
	Allcandy = []
	Allorange = []
	t = int(input())
	for counter in range(t):
		n = int(input())
		takeInput(Allcandy)
		takeInput(Allorange)
	for counter in range(t):
		print(giftFix(Allcandy[counter], Allorange[counter]))
	return
__main__()


t = int(input())
for i in range(t):
	n = int(input())
	arra = list(map(int, input().split()))
	arrb = list(map(int, input().split()))
	mina = min(arra)
	minb = min(arrb)
	count = 0
	for i in range(n):
		count += max(arra[i] - mina, arrb[i] - minb)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	count = 0
	for i in range(n):
		if a[i] - x < b[i] - y:
			temp = a[i] - x
			count += temp + (b[i] - temp - y)
		else:
			temp = b[i] - y
			count += temp + (a[i] - temp - x)
	print(count)


a = []
b = []
k = 0
t = int(input())
for s in range(t):
	n = int(input())
	sa = input().split()
	sb = input().split()
	a = list(map(int, sa))
	b = list(map(int, sb))
	ma = min(a)
	mb = min(b)
	for i in range(n):
		k += max(a[i] - ma, b[i] - mb)
	print(k)
	k = 0
	a = []
	b = []


for _ in range(int(input())):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	minCandy = min(candy)
	minOrange = min(orange)
	count = 0
	for i in range(n):
		count += max(candy[i] - minCandy, orange[i] - minOrange)
	print(count)


t = int(input())
for i in range(t):
	q = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = min(a)
	n = min(b)
	cnt = 0
	for j in range(q):
		c = a[j] - m
		d = b[j] - n
		cnt = cnt + max(c, d)
	print(cnt)


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 = min(A)
	b = min(B)
	res = 0
	for i in range(n):
		if B[i] - b > A[i] - a:
			res += B[i] - b
		else:
			res += A[i] - a
	print(res)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	(minA, minB) = (min(A), min(B))
	ans = 0
	for i in range(n):
		A[i] -= minA
		B[i] -= minB
		ans += max(A[i], B[i])
	print(ans)


from collections import defaultdict, deque
from bisect import bisect_left as lower
import sys

def put():
	return map(int, input().split())
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(put())
	b = list(put())
	(ma, mb) = (min(a), min(b))
	ans = 0
	for i in range(n):
		ans += max(a[i] - ma, b[i] - mb)
	print(ans)


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()]
	lowestNumA = min(a)
	lowestNumB = min(b)
	a = [i - lowestNumA for i in a]
	b = [i - lowestNumB for i in b]
	answer = 0
	for j in range(n):
		answer += max(a[j], b[j])
	print(answer)


n = int(input())
A = [[0] * 3 for i in range(n)]
for i in range(n):
	A[i][0] = int(input())
	A[i][1] = list(map(int, input().split()))
	A[i][2] = list(map(int, input().split()))

def check(A):
	answ = []
	for x in A:
		candys = x[1]
		lemons = x[2]
		min_c = min(candys)
		min_l = min(lemons)
		print(sum([max(candys[i] - min_c, lemons[i] - min_l) for i in range(x[0])]))
check(A)


for _ in range(int(input())):
	n = int(input())
	ls1 = [int(i) for i in input().split()]
	ls2 = [int(i) for i in input().split()]
	minls1 = min(ls1)
	minls2 = min(ls2)
	count = 0
	for i in range(n):
		if ls1[i] == minls1:
			c1 = 0
		else:
			c1 = ls1[i] - minls1
		if ls2[i] == minls2:
			c2 = 0
		else:
			c2 = ls2[i] - minls2
		if c1 == c2:
			count += c1
		else:
			count += max(c1, c2)
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	answer = sum((max(a[i] - ma, b[i] - mb) for i in range(n)))
	print(answer)


n = int(input())

def solve(arr, arr1):
	min1 = min(arr)
	min2 = min(arr1)
	a = [i - min1 for i in arr]
	b = [i - min2 for i in arr1]
	print(sum((i if i > j else j for (i, j) in zip(a, b))))
while n:
	t = int(input())
	arr = list(map(int, input().split()))
	arr1 = list(map(int, input().split()))
	solve(arr, arr1)
	n = n - 1


for _ in range(int(input())):
	n = int(input())
	ni = [_ for _ in map(int, input().split())]
	nj = [_ for _ in map(int, input().split())]
	ans = 0
	mini = min(ni)
	minj = min(nj)
	for (i, j) in zip(ni, nj):
		ans += max(abs(i - mini), abs(j - minj))
	print(ans)


t = int(input())
for i in range(t):
	m = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_candies = min(candies)
	min_orange = min(oranges)
	counter = 0
	for j in range(m):
		dif_candies = candies[j] - min_candies
		diff_oranges = oranges[j] - min_orange
		counter = counter + max([dif_candies, diff_oranges])
	print(counter)


for _ in range(int(input())):
	input()
	(a, b) = (list(map(int, input().split())), list(map(int, input().split())))
	(ma, mb, c, s1, s2) = (min(a), min(b), 0, 0, 0)
	for (i, j) in zip(a, b):
		(d1, d2) = (i - ma, j - mb)
		if d1 > 0 and d2 > 0:
			s1 += d1
			s2 += d2
			c += min(d1, d2)
		elif d1 > 0 and d2 == 0:
			s1 += d1
		else:
			s2 += d2
	print(s1 + s2 - c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mia = min(a)
	mib = min(b)
	ans = 0
	for i in range(len(a)):
		ans += max(a[i] - mia, b[i] - mib)
	print(ans)


test = int(input())

def solve():
	n = int(input())
	arr = [int(i) for i in input().split()]
	arr1 = [int(i) for i in input().split()]
	mini1 = min(arr)
	mini2 = min(arr1)
	count = 0
	for i in range(len(arr)):
		count += min(abs(arr[i] - mini1), abs(arr1[i] - mini2))
		count += abs(abs(arr[i] - mini1) - abs(arr1[i] - mini2))
	print(count)
while test:
	solve()
	test -= 1


t = int(input(''))
a = []
b = []
for i in range(t):
	input('')
	a.append(list(map(int, input().split())))
	b.append(list(map(int, input().split())))
for i in range(t):
	n = len(a[i])
	mina = min(a[i])
	minb = min(b[i])
	sol = 0
	for j in range(n):
		sol += max(a[i][j] - mina, b[i][j] - minb)
	print(sol)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	candy = min(a)
	orange = min(b)
	moves = 0
	for i in range(n):
		if a[i] > candy and b[i] > orange:
			x = min(a[i] - candy, b[i] - orange)
			a[i] -= x
			b[i] -= x
			moves += x
		if a[i] > candy:
			moves += a[i] - candy
			a[i] = candy
		if b[i] > orange:
			moves += b[i] - orange
			b[i] = orange
	print(moves)


for each in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	move = 0
	mina = min(a)
	minb = min(b)
	for i in range(n):
		move += max((a[i] - mina, b[i] - minb))
	print(move)


for test in range(int(input())):
	n = int(input())
	ar1 = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	oran = min(ar1)
	cand = min(ar2)
	ans = 0
	for i in range(n):
		ans += max(ar1[i] - oran, ar2[i] - cand)
	print(ans)


n = int(input())
for i in range(n):
	n1 = int(input())
	candies = [int(n) for n in input().split()]
	oranges = [int(n) for n in input().split()]
	min1 = min(candies)
	min2 = min(oranges)
	count = 0
	candies = list(map(lambda x: x - min1, candies))
	oranges = list(map(lambda x: x - min2, oranges))
	for i in range(n1):
		count += max(candies[i], oranges[i])
	print(count)


t = int(input())
while t:
	n = int(input())
	total = 0
	L1 = list(map(int, input().split()))
	L2 = list(map(int, input().split()))
	a = min(L1)
	b = min(L2)
	i = 0
	while i < n:
		total += max(L1[i] - a, L2[i] - b)
		i += 1
	print(total)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	steps = 0
	mA = min(a)
	mB = min(b)
	for i in range(n):
		if a[i] > mA and b[i] > mB:
			total_required = min(a[i] - mA, b[i] - mB)
			a[i] -= total_required
			b[i] -= total_required
			steps += total_required
		if a[i] > mA:
			total_required = a[i] - mA
			steps += total_required
			a[i] -= total_required
		if b[i] > mB:
			total_required = b[i] - mB
			steps += total_required
			b[i] -= total_required
	print(steps)


import math
num_cases = int(input())
for _ in range(num_cases):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	min_a = 10000000000.0
	min_b = 10000000000.0
	for i in range(n):
		min_a = min(min_a, a[i])
		min_b = min(min_b, b[i])
	moves = 0
	for i in range(n):
		extra_a = a[i] - min_a
		extra_b = b[i] - min_b
		moves += max(extra_b, extra_a)
	print(moves)


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]
	mi = min(a)
	mii = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - mi, b[i] - mii)
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l1 = [int(i) for i in input().split(' ')]
	l2 = [int(i) for i in input().split(' ')]
	k = min(l1)
	z = min(l2)
	ans = 0
	for i in range(n):
		temp1 = abs(k - l1[i])
		temp2 = abs(z - l2[i])
		ans += max(temp1, temp2)
	print(ans)


import math
t = int(input())
for case in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	(mina, minb) = (min(a), min(b))
	res = 0
	for i in range(n):
		decra = a[i] - mina
		decrb = b[i] - minb
		if decra > decrb:
			res += decra
		else:
			res += decrb
	print(res)


T = int(input())
for i in range(T):
	N = int(input())
	Candy = list(map(int, input().split()))
	Oranges = list(map(int, input().split()))
	LCandy = min(Candy)
	LOranges = min(Oranges)
	count = 0
	for k in range(2):
		for j in range(N):
			if Candy[j] > LCandy and Oranges[j] > LOranges:
				M = Candy[j] - LCandy
				O = Oranges[j] - LOranges
				if M < O:
					count += M
					Candy[j] -= M
					Oranges[j] -= M
				else:
					count += O
					Candy[j] -= O
					Oranges[j] -= O
			elif Candy[j] > LCandy:
				count += Candy[j] - LCandy
				Candy[j] = LCandy
			elif Oranges[j] > LOranges:
				count += Oranges[j] - LOranges
				Oranges[j] = LOranges
	print(count)


import math
t = int(input())
for w in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	k1 = min(a)
	k2 = min(b)
	c = 0
	for i in range(n):
		k3 = a[i] - k1
		k4 = b[i] - k2
		c += max(k3, k4)
	print(c)


import sys
import math
from collections import defaultdict, Counter, deque

def solve(test):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		step = min(a[i] - min_a, b[i] - min_b)
		ans += step
		a[i] -= step
		b[i] -= step
		if a[i] == min_a:
			ans += b[i] - min_b
		elif b[i] == min_b:
			ans += a[i] - min_a
	print(ans)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


t = int(input())
sol = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	mna = min(a)
	mnb = min(b)
	for i in range(n):
		if a[i] == mna and b[i] == mnb:
			continue
		x = a[i] - mna
		y = b[i] - mnb
		z = abs(x - y)
		count += z + min(x, y)
	sol.append(count)
for i in sol:
	print(i)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	f = min(a)
	s = min(b)
	count = 0
	for i in range(n):
		a[i] -= f
		b[i] -= s
	for i in range(n):
		count += min(a[i], b[i]) + max(a[i], b[i]) - min(a[i], b[i])
	print(count)


num = int(input())
for i in range(num):
	lenz = int(input())
	arr = input()
	arr = arr.split(' ')
	arr = [int(x) for x in arr]
	minn = min(arr)
	arr2 = input()
	arr2 = arr2.split(' ')
	arr2 = [int(x) for x in arr2]
	minn2 = min(arr2)
	move = 0
	for j in range(lenz):
		move += max(arr[j] - minn, arr2[j] - minn2)
	print(move)


t = int(input())
for _ in range(t):
	n = int(input())
	la = [int(i) for i in input().split()]
	lb = [int(i) for i in input().split()]
	x = min(la)
	y = min(lb)
	cnt = 0
	for i in range(n):
		cnt = cnt + max(abs(la[i] - x), abs(lb[i] - y))
	print(cnt)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = list(set(a))
	b1 = list(set(b))
	s = 0
	if a1 == 1 and b1 == 1:
		print('0')
	else:
		a2 = min(a)
		a3 = min(b)
		for k in range(n):
			a[k] = abs(a[k] - a2)
			b[k] = abs(a3 - b[k])
			s = s + max(a[k], b[k])
	print(s)


t = int(input())
while t > 0:
	(sum, a, b) = (0, 999999999999, 999999999999)
	n1 = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	for i in range(len(A)):
		a = min(a, A[i])
		b = min(b, B[i])
	if len(A) == 1 and len(B) == 1:
		print(0)
	else:
		for i in range(len(A)):
			D = A[i] - a
			D1 = B[i] - b
			sum += max(D, D1)
		print(sum)
	t -= 1


for t in range(int(input())):
	n = int(input())
	alist = list(map(int, input().split()))
	blist = list(map(int, input().split()))
	amin = min(alist)
	bmin = min(blist)
	sum = 0
	for i in range(n):
		arest = alist[i] - amin
		brest = blist[i] - bmin
		sum = sum + max(arest, brest)
	print(sum)


for m in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minA = a[0]
	for i in range(n):
		if a[i] < minA:
			minA = a[i]
	minB = b[0]
	for l in range(n):
		if b[l] < minB:
			minB = b[l]
	steps = 0
	for j in range(n):
		steps += max(a[j] - minA, b[j] - minB)
	print(steps)


def func(t):
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		counter = 0
		for i in range(n):
			counter += max(a[i] - min(a), b[i] - min(b))
		print(counter)
t = int(input())
func(t)


import sys
import math as mt
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	a = I()
	b = I()
	d = min(a)
	e = min(b)
	temp = 0
	for i in range(n):
		if a[i] != d and b[i] != e:
			temp += max(abs(a[i] - d), abs(b[i] - e))
		elif a[i] != d:
			temp += abs(a[i] - d)
		elif b[i] != e:
			temp += abs(b[i] - e)
	print(temp)


def check(cnadies, oranges):
	min_candies = min(candies)
	min_oranges = min(oranges)
	moves = 0
	for i in range(len(candies)):
		removeOranges = oranges[i] - min_oranges
		removeCandies = candies[i] - min_candies
		moves += max(removeCandies, removeOranges)
	return moves
t = int(input())
answers = []
for i in range(t):
	n = int(input())
	candies = [int(x) for x in input().split()]
	oranges = [int(x) for x in input().split()]
	answers.append(check(candies, oranges))
for a in answers:
	print(a)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	candy = min(a)
	orange = min(b)
	count = 0
	for i in range(n):
		count += max(a[i] - candy, b[i] - orange)
	print(count)


t = int(input())
for _ in range(0, t):
	n = int(input())
	aa = [int(i) for i in input().split()]
	bb = [int(i) for i in input().split()]
	(maa, mbb) = (min(aa), min(bb))
	ss = 0
	for i in range(0, n):
		ss += max(aa[i] - maa, bb[i] - mbb)
	print(ss)


import math
import array
t = int(input())
while t > 0:
	k = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	rez = 0
	for i in range(k):
		mina = min(a)
		minb = min(b)
		rez += max(a[i] - mina, b[i] - minb)
	print(rez)
	t -= 1


t = int(input())
while t > 0:
	n = int(input())
	c = [int(i) for i in input().split()]
	o = [int(i) for i in input().split()]
	min_c = min(c)
	min_o = min(o)
	count = 0
	for i in range(n):
		p = c[i] - min_c
		q = o[i] - min_o
		count += max(p, q)
	print(count)
	t -= 1


def fu(a, b, c):
	(d, e) = (min(b), min(c))
	f = 0
	for i in range(a):
		if b[i] != d and c[i] != e:
			if b[i] - d > c[i] - e:
				f += abs(c[i] - e)
				f += abs(b[i] - c[i] + e - d)
			else:
				f += abs(b[i] - d)
				f += abs(c[i] - b[i] + d - e)
		elif b[i] == d and c[i] != e:
			f += abs(c[i] - e)
		else:
			f += abs(b[i] - d)
	return f
for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	print(fu(a, b, c))


t = int(input())
for _ in range(t):
	n = int(input())
	apl = list(map(int, input().split()))
	orn = list(map(int, input().split()))
	(min_apl, min_orn) = (min(apl), min(orn))
	res = 0
	for i in range(n):
		if apl[i] > min_apl and orn[i] > min_orn:
			mv = min(apl[i] - min_apl, orn[i] - min_orn)
			res += mv
			apl[i] -= mv
			orn[i] -= mv
	for i in range(n):
		if apl[i] > min_apl:
			res += apl[i] - min_apl
		if orn[i] > min_orn:
			res += orn[i] - min_orn
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	count = 0
	for i in range(n):
		if a[i] != x and b[i] != y:
			count += max(a[i] - x, b[i] - y)
		elif a[i] == x and b[i] != y:
			count += b[i] - y
		elif a[i] != x and b[i] == y:
			count += a[i] - x
		else:
			count += 0
	print(count)


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	m = [int(x) for x in input().split()]
	x = min(l)
	y = min(m)
	for i in range(n):
		l[i] = l[i] - x
		m[i] = m[i] - y
	ans = 0
	for i in range(n):
		ans += max(l[i], m[i])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))
	numa = list(map(int, input().split()))
	a = min(num)
	b = min(numa)
	ans = 0
	for i in range(n):
		x = num[i] - a
		y = numa[i] - b
		ans += max(x, y)
	print(ans)


def soln():
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	cm = min(candy)
	om = min(orange)
	cdiff = [0] * n
	odiff = [0] * n
	for i in range(n):
		cdiff[i] = candy[i] - cm
		odiff[i] = orange[i] - om
	steps = 0
	for i in range(n):
		m = min(cdiff[i], odiff[i])
		steps += m
		steps += max(cdiff[i], odiff[i]) - m
	return steps
for i in range(int(input())):
	print(soln())


def count_step_candy(ai, bi, min_a, min_b):
	count = 0
	temp_a = ai - min_a
	temp_b = bi - min_b
	if temp_a < temp_b:
		count += temp_b
	else:
		count += temp_a
	return count

def solve_problem(a, b):
	min_a = min(a)
	min_b = min(b)
	count_steps = 0
	for i in range(len(a)):
		count_steps += count_step_candy(a[i], b[i], min_a, min_b)
	return count_steps
n = int(input().strip())
for i in range(n):
	x = input()
	try_time = input().strip().split(' ')
	a = [int(i) for i in try_time]
	try_time = input().strip().split(' ')
	b = [int(i) for i in try_time]
	result = solve_problem(a, b)
	print(result)


t = int(input())
for twst in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	min1 = 1000000000
	min2 = 1000000000
	count = 0
	for i in range(n):
		min1 = min(min1, arr1[i])
		min2 = min(min2, arr2[i])
	for i in range(n):
		d1 = abs(arr1[i] - min1)
		d2 = abs(arr2[i] - min2)
		ans = max(d1, d2)
		count += ans
	print(count)


def f():
	t = int(input())
	for _ in range(t):
		n = int(input())
		moves = 0
		candies = list(map(lambda x: int(x), input().split(' ')))
		oranges = list(map(lambda x: int(x), input().split(' ')))
		(minc, mino) = (min(candies), min(oranges))
		for i in range(len(candies)):
			if candies[i] > minc and oranges[i] > mino:
				dx = min(candies[i] - minc, oranges[i] - mino)
				candies[i] -= dx
				oranges[i] -= dx
				moves += dx
			if candies[i] > minc:
				moves += candies[i] - minc
			if oranges[i] > mino:
				moves += oranges[i] - mino
		print(moves)
f()


test = int(input())
for _ in range(test):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	ans = 0
	m1 = min(arr1)
	m2 = min(arr2)
	for i in range(n):
		d1 = arr1[i] - m1
		d2 = arr2[i] - m2
		ans += abs(d1 - d2) + min(d1, d2)
	print(ans)


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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(a1, b1) = (min(a), min(b))
	ans = 0
	for i in range(n):
		(x, y) = (a[i] - a1, b[i] - b1)
		ans += max(x, y)
	print(ans)


test = int(input())
while test > 0:
	test -= 1
	size = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	mina = min(arr)
	minb = min(brr)
	cost = 0
	for i in range(size):
		cost += max(arr[i] - mina, brr[i] - minb)
	print(cost)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(m1, m2) = (min(a), min(b))
	s = 0
	for i in range(n):
		x = a[i] - m1
		y = b[i] - m2
		s += x + y - min(x, y)
	print(s)


CaseNo = int(input())
for x in range(CaseNo):
	Caselen = int(input())
	StringA = [int(a) for a in input().split()]
	StringB = [int(b) for b in input().split()]
	minSA = min(StringA)
	minSB = min(StringB)
	count = 0
	for y in range(Caselen):
		if StringA[y] == minSA:
			count += StringB[y] - minSB
			StringB[y] = minSB
		elif StringB[y] == minSB:
			count += StringA[y] - minSA
			StringA[y] = minSA
		else:
			DiffA = StringA[y] - minSA
			DiffB = StringB[y] - minSB
			count += min(DiffA, DiffB)
			if DiffA < DiffB:
				StringA[y] = minSA
				count += StringB[y] - minSB - min(DiffA, DiffB)
				StringB[y] = minSB
			else:
				StringB[y] = minSB
				count += StringA[y] - minSA - min(DiffA, DiffB)
				StringA[y] = minSA
	print(count)


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	b = [int(x) for x in stdin.readline().split()]
	c = min(a)
	d = min(b)
	count = 0
	for x in range(n):
		count += max(a[x] - c, b[x] - d)
	stdout.write(str(count) + '\n')


for i in range(int(input())):
	nboxes = input()
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	count = 0
	for i in range(len(A)):
		adiff = A[i] - min(A)
		bdiff = B[i] - min(B)
		count = count + max(adiff, bdiff)
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(ele) for ele in input().split()]
	b = [int(ele) for ele in input().split()]
	mina = min(a)
	minb = min(b)
	minsum = 0
	for i in range(n):
		if b[i] != minb and a[i] != mina:
			m = min(a[i] - mina, b[i] - minb)
			minsum += m
			a[i] -= m
			b[i] -= m
		if a[i] == mina and b[i] != minb:
			minsum += b[i] - minb
		if b[i] == minb and a[i] != mina:
			minsum += a[i] - mina
	print(minsum)


for i in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = min(l1)
	m2 = min(l2)
	c = 0
	for i in range(n):
		s1 = abs(l1[i] - m1)
		s2 = abs(l2[i] - m2)
		c += max(s1, s2)
	print(c)


t = int(input())
for _ in range(t):
	k = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	for i in range(n):
		if a[i] > mina and b[i] > minb:
			minn = min(a[i] - mina, b[i] - minb)
			a[i] = a[i] - minn
			b[i] = b[i] - minn
			k += minn
		if a[i] > mina:
			k += a[i] - mina
		elif b[i] > minb:
			k += b[i] - minb
	print(k)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

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

def S_():
	return input()

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

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

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

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

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

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

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

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

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def Ra():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

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

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
show_flg = True
ans = 0
for _ in range(I()):
	ans = 0
	k = 1
	n = I()
	a = LI()
	b = LI()
	ma = min(a)
	mb = min(b)
	for i in range(n):
		x = a[i] - ma
		y = b[i] - mb
		ans += max(x, y)
	print(ans)


for i in range(int(input())):
	(l1, l2, n) = ([], [], int(input()))
	(l1, l2) = (list(map(int, input().split())), list(map(int, input().split())))
	(k1, k2, ctr) = (min(l1), min(l2), 0)
	for i in range(n):
		(d1, d2) = (l1[i] - k1, l2[i] - k2)
		ctr += max(d1, d2)
	print(ctr)


import sys
import math
mod = 10 ** 9 + 7
inf = float('inf')

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

def LI():
	return list(map(int, sys.stdin.readline().split()))
t = I()
for _ in range(t):
	n = I()
	a = LI()
	b = LI()
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - min_a, b[i] - min_b)
	print(ans)


q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	command = 0
	for i in range(len(a)):
		if a[i] > min_a and b[i] > min_b:
			command = command + min(a[i] - min_a, b[i] - min_b) + abs(a[i] - min_a - (b[i] - min_b))
			continue
		if a[i] > min_a:
			command = command + a[i] - min_a
		if b[i] > min_b:
			command = command + b[i] - min_b
	print(command)


try:
	for test in range(int(input())):
		size = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		i = 0
		no_candies = 0
		mina = min(a)
		minb = min(b)
		while i < len(a):
			no_candies += max(a[i] - mina, b[i] - minb)
			i += 1
		print(no_candies)
except:
	pass


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		a = list(map(int, stdin.readline().split()))
		b = list(map(int, stdin.readline().split()))
		ma = min(a)
		mb = min(b)
		ans = 0
		for i in range(n):
			sa = a[i] - ma
			sb = b[i] - mb
			ms = min(sa, sb)
			ans += ms + sa - ms + sb - ms
		stdout.write(str(ans))
		stdout.write('\n')
	return
main()


for _ in range(int(input())):
	gift = int(input())
	c = list(map(int, input().split()))
	f = list(map(int, input().split()))
	min_c = min(c)
	min_f = min(f)
	turn = 0
	for i in range(0, len(c)):
		turn = turn + max(c[i] - min_c, f[i] - min_f)
	print(turn)


def check(a, b):
	mina = min(a)
	minb = min(b)
	ops = 0
	for (a1, b1) in zip(a, b):
		opsa = a1 - mina
		opsb = b1 - minb
		ops += max(opsa, opsb)
	print(ops)
t = int(input())
for i in range(t):
	c = input()
	a = input().split(' ')
	a = list(map(int, a))
	b = input().split(' ')
	b = list(map(int, b))
	check(a, b)


import sys
import math
from sys import stdin, stdout

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

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

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

def main():
	for t in range(int(input())):
		n = int(input())
		l = get_list()
		k = get_list()
		a = min(l)
		b = min(k)
		f = max(a, b)
		c = 0
		for i in range(n):
			r = l[i] - a
			p = k[i] - b
			d = min(r, p)
			c = c + d
			l[i] = l[i] - d
			k[i] = k[i] - d
			c = c + l[i] - a + k[i] - b
		print(c)
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')
main()


for i in range(int(input())):
	n = int(input())
	a = [int(a) for a in input().split()]
	mna = min(a)
	b = [int(b) for b in input().split()]
	mnb = min(b)
	cnt = 0
	for j in range(n):
		cnt += max(abs(mna - a[j]), abs(mnb - b[j]))
	print(cnt)


for t in range(int(input())):
	x = int(input())
	v = 0
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	c = 0
	p = candies.index(min(candies))
	q = oranges.index(min(oranges))
	l = candies[p]
	m = oranges[q]
	for i in range(x):
		k = candies[i] - l
		o = oranges[i] - m
		v += min(k, o) + (max(k, o) - min(k, o))
	print(v)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	for j in range(n):
		a[j] = a[j] - mina
	for j in range(n):
		b[j] = b[j] - minb
	s = 0
	for j in range(n):
		s = s + max(a[j], b[j])
	print(s)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	n = int(inp())
	a = [int(x) for x in inp().split()]
	b = [int(x) for x in inp().split()]
	minA = min(a)
	minB = min(b)
	ans = 0
	for i in range(n):
		ans += min(a[i] - minA, b[i] - minB) + (max(a[i] - minA, b[i] - minB) - min(a[i] - minA, b[i] - minB))
	print(ans)


num_cases = int(input())
for x in range(num_cases):
	move_counter = 0
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_candy = min(candies)
	min_orange = min(oranges)
	for gift_num in range(n):
		diff_candies = candies[gift_num] - min_candy
		diff_oranges = oranges[gift_num] - min_orange
		if diff_candies > diff_oranges:
			move_counter += diff_candies
		elif diff_oranges > diff_candies:
			move_counter += diff_oranges
		else:
			move_counter += diff_candies
	print(move_counter)


from typing import List

def solve(a: List[int], b: List[int]) -> int:
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(len(a)):
		if a[i] > min_a and b[i] > min_b:
			x = max(a[i] - min_a, b[i] - min_b)
			a[i] -= x
			b[i] -= x
			count += x
	for i in range(len(a)):
		if a[i] > min_a:
			count += a[i] - min_a
		if b[i] > min_b:
			count += b[i] - min_b
	return count
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(' ')]
	print(solve(a, b))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	an = sorted(a)[0]
	bn = sorted(b)[0]
	for i in range(n):
		if b[i] >= a[i]:
			ans += a[i] - an
			b[i] -= a[i] - an
			ans += max(b[i] - bn, 0)
		else:
			ans += b[i] - bn
			a[i] -= b[i] - bn
			ans += max(a[i] - an, 0)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(float, input().split()))
	b = list(map(float, input().split()))
	(am, bm) = (min(a), min(b))
	cnt = 0
	for i in range(n):
		a[i] -= am
		b[i] -= bm
		cnt += max(a[i], b[i])
	print(int(cnt))


k = int(input())
n = []
t = []
o = []
for i in range(k):
	j = int(input())
	p = list(map(int, input().split()))
	q = list(map(int, input().split()))
	t.append(p)
	o.append(q)
	n.append(j)

def cutugogo(t, o, n):
	min1 = min(t)
	min2 = min(o)
	count = 0
	for i in range(n):
		if min1 < t[i] and min2 < o[i]:
			e = t[i] - min1
			u = o[i] - min2
			count += max(e, u)
		elif min1 < t[i] and min2 == o[i]:
			count += t[i] - min1
		elif min1 == t[i] and min2 < o[i]:
			count += o[i] - min2
	return count
for i in range(k):
	r = cutugogo(t[i], o[i], n[i])
	print(r)


t = int(input())
o = [0 for i in range(t + 1)]
for k in range(1, t + 1):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	mina = min(a)
	minb = min(b)
	for i in range(0, n):
		a[i] = a[i] - mina
		b[i] = b[i] - minb
		o[k] = o[k] + abs(a[i] - b[i]) + (a[i] + b[i] - abs(a[i] - b[i])) // 2
for i in range(1, t + 1):
	print(o[i])


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = 0
	for j in range(n):
		while True:
			if a[j] != ma and b[j] != mb:
				m1 = a[j] - ma
				m2 = b[j] - mb
				c += min(m1, m2)
				a[j] -= min(m1, m2)
				b[j] -= min(m1, m2)
			else:
				break
		if a[j] != ma:
			c += a[j] - ma
		if b[j] != mb:
			c += b[j] - mb
	print(c)


import math
import sys
import bisect
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	min1 = min(l1[:])
	min2 = min(l2[:])
	ans = 0
	for i in range(n):
		mini = min(l1[i] - min1, l2[i] - min2)
		maxi = max(l1[i] - min1, l2[i] - min2)
		ans += mini
		maxi = maxi - mini
		ans += maxi
	print(ans)


t = int(input())
f = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	c = min(a)
	d = min(b)
	e = 0
	for j in range(n):
		if a[j] - c >= b[j] - d:
			e = e + (a[j] - c)
		else:
			e = e + (b[j] - d)
	f.append(e)
for i in f:
	print(i)


import sys
tests = int(sys.stdin.readline())

def solve():
	n = int(sys.stdin.readline())
	line = sys.stdin.readline().split(' ')
	c = []
	min_c = 10000000000.0
	for x in line:
		min_c = min(min_c, int(x))
		c.append(int(x))
	line = sys.stdin.readline().split(' ')
	o = []
	min_o = 10000000000.0
	for x in line:
		min_o = min(min_o, int(x))
		o.append(int(x))
	ans = 0
	for i in range(n):
		x = c[i] - min_c
		y = o[i] - min_o
		ans += max(x, y)
	print(ans)
for i in range(tests):
	solve()


T = int(input())
while T > 0:
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	a = min(A)
	b = min(B)
	moves = 0
	for i in range(0, N):
		if A[i] - a == 0:
			moves += B[i] - b
		elif B[i] - b == 0:
			moves += A[i] - a
		else:
			moves += max(A[i] - a, B[i] - b)
	print(moves)
	T -= 1


t = int(input())
while t != 0:
	t = t - 1
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	mina = min(a)
	minb = min(b)
	res = 0
	for i in range(n):
		mint = min(a[i] - mina, b[i] - minb)
		maxt = max(a[i] - mina, b[i] - minb)
		res = res + max(a[i] - mina, b[i] - minb)
	print(res)


for i in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	m = [int(x) for x in input().split()]
	count = 0
	j = 0
	for j in range(n):
		count += max(l[j] - min(l), m[j] - min(m))
	print(count)


n = int(input())
for i in range(n):
	gifts = int(input())
	candies = [int(c) for c in input().split()]
	oranges = [int(o) for o in input().split()]
	min_candies = min(candies)
	min_oranges = min(oranges)
	counter = 0
	for i in range(gifts):
		c_diff = candies[i] - min_candies
		o_diff = oranges[i] - min_oranges
		counter += max(c_diff, o_diff)
	print(counter)


import sys
read = sys.stdin.readline
write = sys.stdout.write
for t in range(int(read())):
	n = int(read())
	a = list(map(int, read().split()))
	b = list(map(int, read().split()))
	min_a = min(a)
	min_b = min(b)
	result = 0
	for i in range(n):
		result += max(a[i] - min_a, b[i] - min_b)
	write('{}\n'.format(result))


def giftsFixing():
	for t in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		b = [int(x) for x in input().split()]
		amin = min(a)
		bmin = min(b)
		c = 0
		for i in range(n):
			diff = a[i] - amin if a[i] - amin >= b[i] - bmin else b[i] - bmin
			c = c + diff
		print(c)
giftsFixing()


n = int(input())
anss = []
for i in range(n):
	k = int(input())
	lst = list(map(int, input().split(' ')))
	lst2 = list(map(int, input().split(' ')))
	min1 = min(lst)
	min2 = min(lst2)
	ans = 0
	for i in range(len(lst)):
		if lst[i] - min1 > 0 and lst2[i] - min2 > 0:
			if lst[i] - min1 >= lst2[i] - min2:
				ans += lst[i] - min1
			else:
				ans += lst2[i] - min2
		elif lst[i] - min1 == 0 and lst2[i] - min2 > 0:
			ans += lst2[i] - min2
		elif lst2[i] - min2 == 0 and lst[i] - min1 > 0:
			ans += lst[i] - min1
	anss.append(ans)
for i in anss:
	print(i)


from functools import reduce

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

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

def transform_function(elem):
	return elem[0] + elem[1] if elem[0] * elem[1] == 0 else max(elem[1], elem[0])

def solve():
	for _ in range(read_int()):
		_ = read_int()
		candies_list = read_int_list()
		oranges_list = read_int_list()
		candies_list = list(map(lambda a, b=min(candies_list): a - b, candies_list))
		oranges_list = list(map(lambda a, b=min(oranges_list): a - b, oranges_list))
		result = reduce(lambda a, b: a + b, list(map(transform_function, list(zip(candies_list, oranges_list)))))
		print(result)
solve()


T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	a = min(A)
	b = min(B)
	ans = 0
	for i in range(N):
		mini = min(A[i] - a, B[i] - b)
		A[i] -= mini
		B[i] -= mini
		ans += mini
	for i in range(N):
		ans += A[i] - a
		ans += B[i] - b
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xA = min(a)
	xB = min(b)
	ans = 0
	for i in range(n):
		p = a[i] - xA
		q = b[i] - xB
		maxi = max(p, q)
		mini = min(p, q)
		ans += maxi - mini
		ans += mini
	print(ans)


def getAns(n, a, b):
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - min_a, b[i] - min_b)
	return ans

def main():
	t = int(input())
	anss = [0] * t
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		anss[i] = getAns(n, a, b)
	for ans in anss:
		print(ans)
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	b = input().split()
	for j in range(n):
		(a[j], b[j]) = (int(a[j]), int(b[j]))
	mina = min(a)
	minb = min(b)
	vys = 0
	for j in range(n):
		prv = a[j] - mina
		dru = b[j] - minb
		vys += max(prv, dru)
	print(vys)


t = int(input())
for i in range(0, t):
	x = int(input())
	li = list(map(int, input().split()))
	li1 = list(map(int, input().split()))
	a = min(li)
	b = min(li1)
	work = 0
	for j in range(0, x):
		ans1 = 0
		ans2 = 0
		if li[j] > a:
			ans1 = li[j] - a
		if li1[j] > b:
			ans2 = li1[j] - b
		work += max(ans1, ans2)
	print(work)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m = min(l1)
	m2 = min(l2)
	sum = num = 0
	for i in range(n):
		sum += max(l1[i] - m, l2[i] - m2)
	print(sum)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 0
	(d1, d2) = (0, 0)
	am = min(a)
	bm = min(b)
	for i in range(n):
		if a[i] == am and b[i] != bm:
			s += b[i] - bm
		elif a[i] != am and b[i] == bm:
			s += a[i] - am
		elif a[i] != am and b[i] != bm:
			d1 = a[i] - am
			d2 = b[i] - bm
			s += d1 + d2 - min(d1, d2)
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	amin = min(a)
	bmin = min(b)
	count = 0
	for (i, j) in zip(a, b):
		count += max(i - amin, j - bmin)
	print(count)


def nod(a, b):
	while a != b:
		(a, b) = (max(a, b), min(a, b))
		if a % b == 0:
			a -= (a // b - 1) * b
		else:
			a -= a // b * b
	return a
for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	res = 0
	(a1, b1) = (min(a), min(b))
	for i in range(n):
		a2 = a[i] - a1
		b2 = b[i] - b1
		res += max(a2, b2)
	print(res)


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()))
	x = 1000000005
	y = 1000000005
	for i in range(n):
		if a[i] < x:
			x = a[i]
		if b[i] < y:
			y = b[i]
	steps = 0
	for i in range(n):
		steps += min(a[i] - x, b[i] - y)
		steps += max(a[i] - x, b[i] - y) - min(a[i] - x, b[i] - y)
	print(steps)


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	b = list(map(int, input().strip().split(' ')))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(0, n):
		if a[i] > amin and b[i] > bmin:
			ans += max(a[i] - amin, b[i] - bmin)
		elif a[i] > amin:
			ans += a[i] - amin
		elif b[i] > bmin:
			ans += b[i] - bmin
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	a = a.strip()
	a = a.split(' ')
	b = input()
	b = b.strip()
	b = b.split(' ')
	a = list(map(int, a))
	b = list(map(int, b))
	min_a = min(a)
	min_b = min(b)
	for j in range(n):
		a[j] = int(a[j]) - int(min_a)
		b[j] = int(b[j]) - int(min_b)
	count = 0
	for k in range(n):
		comm = min(a[k], b[k])
		extra = max(a[k], b[k]) - comm
		count += comm + extra
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	s1 = set(l1)
	s2 = set(l2)
	if len(s1) == 1 and len(s2) == 1:
		print(0)
	else:
		x = min(s1)
		y = min(s2)
		count = 0
		for i in range(n):
			a = l1[i] - x
			b = l2[i] - y
			c = min(a, b)
			d = max(a, b)
			count += c
			e = d - c
			count += e
		print(count)


import itertools
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	x = min(a)
	y = min(b)
	c = 0
	zz = 0
	aa = 0
	bb = 0
	for j in range(n):
		while 1:
			if a[j] > x and b[j] > y:
				aa = a[j] - x
				bb = b[j] - y
				if aa <= bb:
					c = c + aa
					a[j] = a[j] - aa
					b[j] = b[j] - aa
				else:
					c = c + bb
					a[j] = a[j] - bb
					b[j] = b[j] - bb
			elif a[j] > x:
				zz = a[j] - x
				a[j] = a[j] - zz
				c = c + zz
			elif b[j] > y:
				zz = b[j] - y
				b[j] = b[j] - zz
				c = c + zz
			if a[j] == x and b[j] == y:
				break
	print(c)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	(a_sub, b_sub) = ([], [])
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(len(a)):
		a_sub.append(a[i] - min_a)
		b_sub.append(b[i] - min_b)
		count += min(a_sub[i], b_sub[i])
		count += b_sub[i] + a_sub[i] - 2 * min(a_sub[i], b_sub[i])
	ans.append(count)
for i in ans:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	mina = min(l1)
	minb = min(l2)
	ans = 0
	for i in range(n):
		ans += max(l1[i] - mina, l2[i] - minb)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diffa = []
	diffb = []
	ma = min(a)
	mb = min(b)
	for i in range(n):
		diffa.append(a[i] - ma)
		diffb.append(b[i] - mb)
	ans = 0
	for i in range(n):
		ans += max(diffa[i], diffb[i])
	print(ans)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

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

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

def solve():
	n = get_int()
	a = get_list()
	b = get_list()
	ans = 0
	(minia, minib) = (min(a), min(b))
	for i in range(n):
		ans += max(a[i] - minia, b[i] - minib)
	print(ans)

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


t = int(input())

def max(a, b):
	if a >= b:
		return a
	return b
for _ in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	o = list(map(int, input().split()))
	num = 0
	ms = min(s)
	mo = min(o)
	for i in range(0, n):
		x = s[i] - ms
		y = o[i] - mo
		num += max(x, y)
	print(num)


t = int(input())
while t:
	n = int(input())
	candies = list(map(int, input().split(' ')))
	oranges = list(map(int, input().split(' ')))
	solution = 0
	for i in range(0, n):
		t_candies = candies[i] - min(candies)
		t_oranges = oranges[i] - min(oranges)
		solution = solution + max(t_candies, t_oranges)
	print(solution)
	t = t - 1


getlist = lambda : list(map(int, input().split()))

def equalise(ais, bis):
	count = 0
	amin = min(ais)
	bmin = min(bis)
	for i in range(len(ais)):
		common = min([ais[i] - amin, bis[i] - bmin])
		ais[i] -= common
		bis[i] -= common
		asub = ais[i] - amin
		bsub = bis[i] - bmin
		ais[i] -= asub
		bis[i] -= bsub
		count += common + asub + bsub
	return count
t = int(input())
for _ in range(t):
	n = int(input())
	ais = getlist()
	bis = getlist()
	print(equalise(ais, bis))


def main():
	for _ in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		b = [int(y) for y in input().split()]
		ma = min(a)
		mb = min(b)
		c = 0
		for i in range(n):
			c += max(abs(a[i] - ma), abs(b[i] - mb))
		print(c)
main()


(count, output) = (0, [])
for i in range(int(input())):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	(a, b) = (min(candies), min(oranges))
	for j in range(n):
		c = min(candies[j] - a, oranges[j] - b)
		count += c
		if candies[j] - c != a:
			count += candies[j] - c - a
		elif oranges[j] - c != b:
			count += oranges[j] - c - b
	output.append(count)
	count = 0
print(*output, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mi_a = min(a)
	mi_b = min(b)
	c = 0
	for i in range(n):
		diff = a[i] - mi_a
		diff1 = b[i] - mi_b
		m1 = min(diff, diff1)
		m2 = max(diff, diff1) - m1
		c += m1 + m2
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	o = list(map(int, input().split()))
	t = list(map(int, input().split()))
	om = min(o)
	tm = min(t)
	ans = 0
	for i in range(len(o)):
		onediff = o[i] - om
		twodiff = t[i] - tm
		ans += max(onediff, twodiff)
	print(ans)


for i in range(int(input())):
	n = int(input())
	can = list(map(int, input().split()))
	org = list(map(int, input().split()))
	mincan = min(can)
	minorg = min(org)
	canl = []
	orgl = []
	for i in range(n):
		canl.append(abs(can[i] - mincan))
		orgl.append(abs(org[i] - minorg))
	sum = 0
	for i in range(n):
		if canl[i] > orgl[i]:
			sum += canl[i]
		elif orgl[i] > canl[i]:
			sum += orgl[i]
		else:
			sum += canl[i]
	print(sum)


for i in range(int(input())):
	n = int(input())
	h = 0
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ap = min(b)
	sw = min(a)
	for i in range(n):
		h += max(b[i] - ap, a[i] - sw)
	print(h)


t = int(input())
for test_case in range(t):
	n = int(input())
	a = [int(e) for e in input().split()]
	b = [int(e) for e in input().split()]
	min_a = 100000 * 100000
	min_b = 100000 * 100000
	for i in a:
		min_a = min(min_a, i)
	for i in b:
		min_b = min(min_b, i)
	ans = 0
	for i in range(n):
		dif = a[i] - min_a
		ans += dif
		b[i] -= dif
		if b[i] < min_b:
			b[i] = min_b
	for i in range(n):
		ans += b[i] - min_b
	print(ans)


t = int(input())
for it in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	av = min(a)
	bv = min(b)
	ans = 0
	for i in range(n):
		k = min(a[i] - av, b[i] - bv)
		ans += k
		a[i] -= k
		b[i] -= k
		ans += a[i] - av + b[i] - bv
	print(ans)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	araz = 0
	braz = 0
	otv = 0
	for i in range(n):
		araz = a[i] - amin
		braz = b[i] - bmin
		otv += max([araz, braz])
	print(otv)
t = int(input())
for _ in range(t):
	solve()


import math, sys, bisect, heapq
from math import *
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	N = int(input())
	A = alele()
	B = alele()
	mini1 = 10000000000.0
	mini2 = 10000000000.0
	for (i, j) in zip(A, B):
		mini1 = min(i, mini1)
		mini2 = min(j, mini2)
	Ans = 0
	for (i, j) in zip(A, B):
		if i > mini1 and j > mini2:
			z1 = i - mini1
			z2 = j - mini2
			z3 = min(z1, z2)
			Ans += z3
			i -= z3
			j -= z3
		Ans += i - mini1
		Ans += j - mini2
	print(Ans)


for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	x1 = min(x)
	y1 = min(y)
	count = 0
	for j in range(n):
		x2 = x[j] - x1
		y2 = y[j] - y1
		if abs(y2) != y2 and abs(x2) != x2:
			continue
		elif x2 > 0 and y2 > 0:
			count += max(x2, y2)
		else:
			count += max(x2, y2)
	print(count)


t = int(input())

def sol():
	s = 0
	n = int(input())
	a0 = input()
	b0 = input()
	a1 = a0.split(' ')
	b1 = b0.split(' ')
	a = [int(k) for k in a1]
	b = [int(c) for c in b1]
	for i in range(n):
		s += max(a[i] - min(a), b[i] - min(b))
	print(s)
for j in range(t):
	sol()


T = int(input())
while T != 0:
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	b = list(map(int, input().strip().split()))[:n]
	gifta = min(a)
	giftb = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - gifta, b[i] - giftb)
	print(ans)
	T -= 1


t = int(input())
for i in range(t):
	n = int(input())
	numbers = list(map(int, input().split()))
	numbers2 = list(map(int, input().split()))
	(a, b) = (min(numbers), min(numbers2))
	s = 0
	for j in range(n):
		d1 = numbers[j] - a
		d2 = numbers2[j] - b
		s += abs(d1 - d2)
		s += min(d1, d2)
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().split()))
	list2 = list(map(int, input().split()))
	a = min(list1)
	b = min(list2)
	res = 0
	for i in range(n):
		c = list1[i] - a
		o = list2[i] - b
		if c == 0:
			res += o
		elif o == 0:
			res += c
		elif o <= c:
			res += c - o
			res += o
		else:
			res += o - c
			res += c
	print(res)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	minl = min(l)
	minm = min(m)
	c = 0
	for (i, j) in zip(range(n), range(n)):
		c += max(l[i] - minl, m[j] - minm)
	print(c)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = min(l1)
	m2 = min(l2)
	count = 0
	for i in range(len(l1)):
		if l1[i] >= m1 and l2[i] >= m2:
			count += max(l1[i] - m1, l2[i] - m2)
		elif l1[i] > m1 and l2[i] == m2:
			count += l1[i] - m1
		elif l1[i] == m1 and l2[i] > m2:
			count += l2[i] - m2
	print(count)


for _ in range(int(input())):
	am = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aMin = min(a)
	bMin = min(b)
	t = 0
	for i in range(am):
		t += max(a[i] - aMin, b[i] - bMin)
	print(t)


def solve(N, A, B):
	min_candies = min(A)
	min_oranges = min(B)
	moves = 0
	for i in range(N):
		curr_candies = A[i] - min_candies
		curr_oranges = B[i] - min_oranges
		moves += min(curr_candies, curr_oranges)
		moves += max(curr_candies, curr_oranges) - min(curr_candies, curr_oranges)
	return moves

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		ans = solve(N, A, B)
		print(ans)
main()


import sys
input = sys.stdin.readline

def main(n, a, b):
	min1 = min(a)
	min2 = min(b)
	moves = 0
	for i in range(n):
		a1 = a[i] - min1
		b1 = b[i] - min2
		val = min(a1, b1)
		moves += val
		a1 -= val
		b1 -= val
		if a1 > 0 or b1 > 0:
			moves += max(a1, b1)
	return moves
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(main(n, a, b))


from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()
rli = lambda : map(int, stdin.readline().split())
rlf = lambda : map(float, stdin.readline().split())
(INF, NINF) = (float('inf'), float('-inf'))
MOD = 10 ** 9 + 7

def main():
	T = int(rl())
	for _ in range(T):
		n = int(rl())
		A = list(rli())
		B = list(rli())
		moves = 0
		(minA, minB) = (min(A), min(B))
		for (a, b) in zip(A, B):
			(da, db) = (a - minA, b - minB)
			dd = min(da, db)
			moves += dd
			da -= dd
			db -= dd
			moves += da + db
		print(moves)
	stdout.close()
main()


test = int(input())
for i in range(test):
	size = int(input())
	numberA = [int(i) for i in input().split()]
	numberB = [int(i) for i in input().split()]
	minA = min(numberA)
	minB = min(numberB)
	count = 0
	for i in range(size):
		count += numberA[i] - minA + (numberB[i] - minB) - min(numberA[i] - minA, numberB[i] - minB)
	print(count)


import sys
import math, bisect
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

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

def Neo():
	return list(map(int, input().split()))
for _ in range(int(input())):
	n = int(input())
	C = Neo()
	B = Neo()
	(p, q) = (min(C), min(B))
	Ans = 0
	for (i, j) in zip(C, B):
		Ans += max(i - p, j - q)
	print(Ans)


import math
import sys
from sys import *
import heapq
from collections import deque, defaultdict
from itertools import permutations, combinations, combinations_with_replacement
import random
import os
mod = 10 ** 9 + 7
MAX = sys.maxsize
MIN = -sys.maxsize - 1

def isPrime(n):
	if n > 1:
		for i in range(2, n):
			if n % i == 0:
				return False
		else:
			return True
	else:
		return False

def isPanagram(s):
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	for char in alphabet:
		if char not in s.lower():
			return False
	return True

def power2(n):
	return n and (not n & n - 1)

def diff(list1):
	res = [list1[i + 1] - list1[i] for i in range(len(list1) - 1)]
	return res

def isEqual(list1):
	if len(list1) < 0:
		res = True
	res = all((ele == list1[0] for ele in list1))
	if res:
		return True
	else:
		return False

def checkPali(s):
	ar = [0] * 256
	for i in range(len(s)):
		ar[ord(s[i])] = ar[ord(s[i])] + 1
	odd = 0
	for i in range(256):
		if ar[i] & 1:
			odd += 1
		if odd > 1:
			return False
	return True

def remove_duplicate(list1):
	final_list = list(set(list1))
	return final_list

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ar1 = []
	ar2 = []
	arr = []
	m1 = min(a)
	m2 = min(b)
	for i in range(n):
		ar1.append(a[i] - m1)
		ar2.append(b[i] - m2)
	for i in range(n):
		arr.append(max(ar1[i], ar2[i]))
	return sum(arr)
t = int(stdin.readline().strip())
for i in range(t):
	result = solve()
	stdout.write(str(result) + '\n')


t = int(input())
for _ in range(0, t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	a = min(A)
	b = min(B)
	c = 0
	for i in range(0, n):
		if A[i] != a and B[i] != b:
			x = min(A[i] - a, B[i] - b)
			A[i] -= x
			B[i] -= x
			c += x
	for i in range(0, n):
		if A[i] != a:
			x = A[i] - a
			A[i] -= x
			c += x
		if B[i] != b:
			x = B[i] - b
			B[i] -= x
			c += x
	print(c)


for _ in range(int(input())):
	input()
	data1 = list(map(int, input().split()))
	data2 = list(map(int, input().split()))
	m1 = min(data1)
	m2 = min(data2)
	print(sum((max(v1 - m1, v2 - m2) for (v1, v2) in zip(data1, data2))))


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().rstrip().split()))
	o = list(map(int, input().rstrip().split()))
	ci = min(c)
	oi = min(o)
	count = 0
	for i in range(n):
		count += max(c[i] - ci, o[i] - oi)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_equal = min(a)
	b_equal = min(b)
	res = 0
	for i in range(n):
		a1 = a[i] - a_equal
		b1 = b[i] - b_equal
		res += max(a1, b1)
	print(res)


def solve():
	n = int(input())
	candies = [int(i) for i in input().split()]
	oranges = [int(i) for i in input().split()]
	(a, b) = (min(candies), min(oranges))
	cnt = 0
	for i in range(n):
		cnt += max(candies[i] - a, oranges[i] - b)
	print(cnt)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	ans = 0
	mn1 = min(arr1)
	mn2 = min(arr2)
	for i in range(n):
		n1 = arr1[i] - mn1
		n2 = arr2[i] - mn2
		ans += min(n1, n2)
		ans += max(n1, n2) - min(n1, n2)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	o = min(b)
	diff = []
	for i in range(len(a)):
		if a[i] == c and b[i] == o:
			pass
		elif a[i] > c and b[i] > o:
			y = a[i] - c
			z = b[i] - o
			diff.append(max(y, z))
		elif a[i] > c and b[i] == o:
			diff.append(a[i] - c)
		elif a[i] == c and b[i] > o:
			diff.append(b[i] - o)
	print(sum(diff))


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()]
	amin = min(a)
	bmin = min(b)
	c = 0
	for i in range(n):
		flag = 0
		x = 0
		y = 0
		if a[i] != amin:
			flag = 1
			x = a[i] - amin
			a[i] = amin
		if b[i] != bmin:
			flag = 1
			y = b[i] - bmin
			b[i] = bmin
		if flag == 1:
			c += max(x, y)
	print(c)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minA = min(a)
	minB = min(b)
	moves = 0
	for i in range(n):
		aLeft = a[i] - minA
		bLeft = b[i] - minB
		m = min(aLeft, bLeft)
		moves += m
		aLeft -= m
		bLeft -= m
		moves += aLeft
		moves += bLeft
	print(moves)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = m2 = 99999999999
	for i in range(n):
		m1 = min(l1[i], m1)
		m2 = min(l2[i], m2)
	c = 0
	for i in range(n):
		if l1[i] > m1 and l2[i] > m2:
			k = min(l2[i] - m2, l1[i] - m1)
			c += k
			c += l1[i] - k - m1
			c += l2[i] - k - m2
		elif l1[i] > m1:
			c += l1[i] - m1
		elif l2[i] > m2:
			c += l2[i] - m2
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minb = min(b)
	mina = min(a)
	count = 0
	for i in range(n):
		first = a[i] - mina
		second = b[i] - minb
		count += max(first, second)
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	arrn = list(map(int, input().split()))
	arrm = list(map(int, input().split()))
	q = min(arrn)
	w = min(arrm)
	s = 0
	for i in range(n):
		qq = arrn[i] - q
		ww = arrm[i] - w
		s += min(qq, ww) + abs(qq - ww)
	print(s)


n = int(input())
for i in range(n):
	t = input()
	C1 = input().split()
	C2 = []
	for a in C1:
		C2.append(int(a))
	Or1 = input().split()
	Or2 = []
	for b in Or1:
		Or2.append(int(b))
	minC = min(C2)
	minOr = min(Or2)
	steps = 0
	for i in range(0, len(C2)):
		toReduceC = C2[i] - minC
		toReduceOr = Or2[i] - minOr
		if toReduceC > 0 and toReduceOr > 0:
			if toReduceC > toReduceOr:
				C2[i] -= toReduceOr
				Or2[i] -= toReduceOr
				toReduceC -= toReduceOr
				steps += toReduceOr
				toReduceOr = 0
			else:
				C2[i] -= toReduceC
				Or2[i] -= toReduceC
				toReduceOr -= toReduceC
				steps += toReduceC
				toReduceC = 0
	for i in range(0, len(C2)):
		if C2[i] > minC:
			difC = C2[i] - minC
			C2[i] -= difC
			steps += difC
	for i in range(0, len(C2)):
		if Or2[i] > minOr:
			difOr = Or2[i] - minOr
			Or2[i] -= difOr
			steps += difOr
	print(steps)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().strip().split(' ')))
	ll = list(map(int, input().strip().split(' ')))
	o = min(l)
	c = min(ll)
	count = 0
	for i in range(n):
		if l[i] != o and ll[i] != c:
			q = abs(l[i] - o)
			w = abs(ll[i] - c)
			count = count + max(q, w)
		elif l[i] != o:
			count = count + abs(l[i] - o)
		elif ll[i] != c:
			count = count + abs(ll[i] - c)
	print(count)


t = int(input())
while t:
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_orange = min(oranges)
	min_candy = min(candies)
	cnt = 0
	for (candy, orange) in zip(candies, oranges):
		cnt += max(candy - min_candy, orange - min_orange)
	print(cnt)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	amin = min(ar)
	bmin = min(br)
	ans = 0
	for i in range(n):
		ans = ans + max(ar[i] - amin, br[i] - bmin)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	app = list(map(int, input().split()))
	org = list(map(int, input().split()))
	count = 0
	minapp = min(app)
	minorg = min(org)
	for i in range(n):
		if app[i] > minapp and org[i] > minorg:
			if app[i] - minapp > org[i] - minorg:
				temp = org[i] - minorg
				count += temp
				org[i] -= temp
				app[i] -= temp
				temp = 0
				count += app[i] - minapp
				app[i] -= app[i] - minapp
			else:
				temp = app[i] - minapp
				count += temp
				app[i] -= temp
				org[i] -= temp
				temp = 0
				count += org[i] - minorg
				org[i] -= org[i] - minorg
		if org[i] > minorg:
			temp = org[i] - minorg
			count += temp
			app[i] -= temp
			temp = 0
		if app[i] > minapp:
			temp = app[i] - minapp
			count += temp
			org[i] -= temp
			temp = 0
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [] * n
	b = [] * n
	s = 0
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ma = min(a)
	mb = min(b)
	for i in range(n):
		q = a[i] - ma
		w = b[i] - mb
		s += max(q, w)
	print(s)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	lst1 = [int(i) for i in input().split(' ')]
	lst2 = [int(i) for i in input().split(' ')]
	moves = 0
	m1 = min(lst1)
	m2 = min(lst2)
	for i in range(0, len(lst1)):
		a1 = lst1[i] - m1
		a2 = lst2[i] - m2
		moves = moves + max(a1, a2)
	print(moves)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	moves = 0
	(l_g, l_c) = (min(a), min(b))
	for i in range(n):
		moves += max(a[i] - l_g, b[i] - l_c)
	print(moves)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	moves = 0
	for i in range(n):
		moves += max(a[i] - mina, b[i] - minb)
	print(moves)


n = int(input())
for ni in range(n):
	moves = 0
	m = int(input())
	t1 = [int(z) for z in input().split()]
	t2 = [int(z) for z in input().split()]
	small1 = min(t1)
	small2 = min(t2)
	t1 = [x - small1 for x in t1]
	t2 = [x - small2 for x in t2]
	for i in range(m):
		if t1[i] > t2[i]:
			moves = moves + t1[i]
		else:
			moves = moves + t2[i]
	print(moves)


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()))
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		x1 = a[i] - ma
		x2 = b[i] - mb
		c += max(x1, x2)
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	(m1, m2, k) = (min(a), min(b), 0)
	for i in range(n):
		(t1, t2) = (a[i] - m1, b[i] - m2)
		k += max(t1, t2)
	print(k)


for i in range(int(input())):
	n = int(input())
	a = [int(ai) for ai in input().split()]
	b = [int(bi) for bi in input().split()]
	(min_a, min_b) = (min(a), min(b))
	a = [ai - min_a for ai in a]
	b = [bi - min_b for bi in b]
	ans = 0
	for i in range(n):
		min_i = min((a[i], b[i]))
		ans += min_i
		(a[i], b[i]) = (a[i] - min_i, b[i] - min_i)
	print(ans + sum(a) + sum(b))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = 10 ** 9 + 1
	minb = 10 ** 9 + 1
	for i in range(n):
		if a[i] < mina:
			mina = a[i]
		if b[i] < minb:
			minb = b[i]
	op = 0
	for i in range(n):
		opa = a[i] - mina
		opb = b[i] - minb
		op += max(opa, opb)
	print(op)


t = int(input())
for i in range(0, t):
	n = int(input())
	candy = input().split()
	orange = input().split()
	for i in range(n):
		candy[i] = int(candy[i])
		orange[i] = int(orange[i])
	mc = min(candy)
	mo = min(orange)
	ans = 0
	for i in range(0, n):
		dc = candy[i] - mc
		do = orange[i] - mo
		ans += min(dc, do)
		ans += abs(dc - do)
	print(ans)


def func(a: list, b: list) -> int:
	move = 0
	mina = min(a)
	minb = min(b)
	for i in range(len(a)):
		move += max(a[i] - mina, b[i] - minb)
	return move
T = int(input())
moveList = list()
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	moveList.append(func(a, b))
for m in moveList:
	print(m)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	a = min(l1)
	b = min(l2)
	su = 0
	for i in range(n):
		t2 = max(abs(l1[i] - a), abs(l2[i] - b))
		su += t2
	print(su)


for _ in range(int(input())):
	n = int(input())
	can = list(map(int, input().split()))
	org = list(map(int, input().split()))
	min_can = min(can)
	min_org = min(org)
	count = 0
	for i in range(n):
		can_dif = can[i] - min_can
		org_dif = org[i] - min_org
		count += min(can_dif, org_dif)
		count += max(can_dif, org_dif) - min(can_dif, org_dif)
	print(count)


t = int(input())
res = [0 for i in range(t)]
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res_a = [0 for j in range(n)]
	res_b = [0 for j in range(n)]
	smallest_a = min(a)
	smallest_b = min(b)
	for j in range(n):
		if a[j] > smallest_a:
			res_a[j] = a[j] - smallest_a
	for j in range(n):
		if b[j] > smallest_b:
			res_b[j] = b[j] - smallest_b
	for j in range(n):
		if res_a[j] > res_b[j]:
			res[i] += res_b[j]
			res_a[j] -= res_b[j]
			res_b[j] = 0
		elif res_b[j] > res_a[j]:
			res[i] += res_a[j]
			res_b[j] -= res_a[j]
			res_a[j] = 0
		else:
			res[i] += res_a[j]
			res_a[j] = 0
			res_b[j] = 0
	res[i] = res[i] + sum(res_a) + sum(res_b)
for i in range(t):
	print(res[i])


def main():
	Tquery = int(input())
	for _ in range(Tquery):
		N = int(input())
		A = [int(i) for i in input().split()]
		B = [int(i) for i in input().split()]
		ans = 0
		minA = min(A)
		minB = min(B)
		for i in range(N):
			need = max(A[i] - minA, B[i] - minB)
			ans += need
		print(ans)
main()


t = int(input())
for i in range(t):
	n = int(input())
	list1 = list(map(int, input().split()))
	list2 = list(map(int, input().split()))
	count = 0
	for i in range(n):
		if list1[i] != min(list1) and list2[i] != min(list2):
			a = list1[i] - min(list1)
			b = list2[i] - min(list2)
			count = count + max(a, b)
		elif list1[i] != min(list1):
			a = list1[i] - min(list1)
			count = count + a
		elif list2[i] != min(list2):
			b = list2[i] - min(list2)
			count += b
	print(count)


for _ in range(int(input())):
	n = int(input())
	lc = [int(x) for x in input().split()]
	lo = [int(x) for x in input().split()]
	c_min = min(lc)
	o_min = min(lo)
	cnt = 0
	for i in range(n):
		if lc[i] != c_min and lo[i] == o_min:
			cnt += lc[i] - c_min
		elif lc[i] == c_min and lo[i] != o_min:
			cnt += lo[i] - o_min
		else:
			k = min(lc[i] - c_min, lo[i] - o_min)
			cnt += k
			lc[i] -= k
			lo[i] -= k
			if lc[i] != c_min:
				cnt += lc[i] - c_min
			if lo[i] != o_min:
				cnt += lo[i] - o_min
	print(cnt)


test = int(input())
while test > 0:
	test = test - 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		if a[i] != ma or b[i] != mb:
			if a[i] - ma > b[i] - mb:
				c = c + (a[i] - ma)
			else:
				c = c + (b[i] - mb)
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	target_a = min(a)
	target_b = min(b)
	cnt = 0
	for i in range(n):
		temp_a = a[i] - target_a
		temp_b = b[i] - target_b
		cnt += max(temp_a, temp_b)
	print(cnt)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	d = min(b)
	ans = 0
	for i in range(n):
		x = a[i] - c
		y = b[i] - d
		e = min(x, y)
		ans += e
		x -= e
		y -= e
		ans += x + y
	print(ans)


def minNum(casea: [int], caseb: [int]) -> int:
	a = min(casea)
	b = min(caseb)
	return sum([max(casea[i] - a, caseb[i] - b) for i in range(len(casea))])
n = int(input())
tcases = []
for i in range(n):
	num = int(input())
	casea = [int(_) for _ in input().split()]
	caseb = [int(_) for _ in input().split()]
	tcases.append([casea, caseb])
for case in tcases:
	print(minNum(case[0], case[1]))


def gifts_fixing_base(a, b, n):
	min_a = min(a)
	min_b = min(b)
	total_num = 0
	for i in range(n):
		if a[i] == min_a:
			total_num += b[i] - min_b
		elif b[i] == min_b:
			total_num += a[i] - min_a
		else:
			res_1 = a[i] - min_a
			res_2 = b[i] - min_b
			total_num += max(res_1, res_2)
	return total_num
t = int(input())
for _ in range(t):
	n = int(input())
	input_numbers_a = [int(x) for x in input().split()]
	input_numbers_b = [int(x) for x in input().split()]
	print(gifts_fixing_base(input_numbers_a, input_numbers_b, n))


def main():
	amount_of_tests = int(input())
	for _ in range(amount_of_tests):
		n = int(input())
		candies = [int(i) for i in input().split()]
		oranges = [int(i) for i in input().split()]
		min_candy = min(candies)
		min_orange = min(oranges)
		ts = []
		for (c, o) in zip(candies, oranges):
			to = o - min_orange
			tc = c - min_candy
			ts.append(max(to, tc))
		print(sum(ts))
main()


t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	mnc = float('inf')
	mno = float('inf')
	for j in range(n):
		mnc = min(mnc, c[j])
		mno = min(mno, o[j])
	count = 0
	for j in range(n):
		if c[j] > mnc and o[j] > mno:
			mn = min(c[j] - mnc, o[j] - mno)
			count += mn
			c[j] -= mn
			o[j] -= mn
		if c[j] > mnc:
			count += c[j] - mnc
		if o[j] > mno:
			count += o[j] - mno
	print(count)


for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		ai = a[i] - mina
		bi = b[i] - minb
		c = max(ai, bi)
		ans += c
	print(ans)


for i in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	a = 0
	lm = min(l)
	mm = min(m)
	for i in range(0, n):
		u = abs(l[i] - lm)
		v = abs(m[i] - mm)
		a += max(u, v)
	print(a)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minia = min(a)
	minib = min(b)
	amove = []
	bmove = []
	common = []
	for i in range(n):
		amove.append(a[i] - minia)
	for j in range(n):
		bmove.append(b[j] - minib)
	for k in range(n):
		common.append(min(amove[k], bmove[k]))
	ans = sum(amove) + sum(bmove) - sum(common)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	x = min(a)
	y = min(b)
	c = 0
	d = 0
	for i in range(n):
		if a[i] != x and b[i] != y:
			t = a[i] - x
			v = b[i] - y
			c = c + max(t, v)
		elif a[i] != x and b[i] == y:
			c = c + (a[i] - x)
		elif a[i] == x and b[i] != y:
			c = c + (b[i] - y)
	print(c)


def isEqual(arr):
	for i in range(1, len(arr)):
		if arr[i] != arr[i - 1]:
			return False
	return True

def Solve(arr, brr):
	leastA = min(arr)
	leastB = min(brr)
	count = 0
	N = len(arr)
	for i in range(N):
		sub = min(arr[i] - leastA, brr[i] - leastB)
		arr[i] -= sub
		brr[i] -= sub
		count += sub
	if not isEqual(arr):
		for i in range(N):
			sub = arr[i] - leastA
			arr[i] -= sub
			count += sub
	if not isEqual(brr):
		for i in range(N):
			sub = brr[i] - leastB
			brr[i] -= sub
			count += sub
	return count
tc = int(input())
for _ in range(tc):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	print(Solve(arr, brr))


for _ in range(int(input())):
	(n, a, b) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
	(a_, b_) = (min(a), min(b))
	print(sum((max(a[i] - a_, b[i] - b_) for i in range(n))))


def solve(a, b, n):
	ha = [0] * (n + 1)
	hb = [0] * (n + 1)
	min_a = min(a)
	min_b = min(b)
	moves = 0
	for i in range(n):
		ha[i] = a[i] - min_a
		hb[i] = b[i] - min_b
	for i in range(n):
		moves += max(ha[i], hb[i])
	return moves
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(a, b, n))


T = int(input())
for t in range(T):
	N = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m_a = min(a)
	m_b = min(b)
	tot = 0
	for n in range(N):
		tot = tot + max(a[n] - m_a, b[n] - m_b)
	print(tot)


for _ in range(int(input())):
	n = int(input())
	cand = list((int(i) for i in input().split()))
	oran = list((int(i) for i in input().split()))
	(cnt1, cnt2, tot) = (0, 0, 0)
	(mn1, mn2) = (min(cand), min(oran))
	for i in range(n):
		cnt1 = cand[i] - mn1
		cnt2 = oran[i] - mn2
		tot += max(cnt1, cnt2)
	print(tot)


for _ in range(int(input())):
	n = int(input())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	a = min(a1)
	b = min(b1)
	c = 0
	for i in range(len(a1)):
		if a1[i] > a and b1[i] > b:
			k = min(a1[i] - a, b1[i] - b)
			c += k
			a1[i] -= k
			b1[i] -= k
			if a1[i] != a:
				c += a1[i] - a
			elif b1[i] != b:
				c += b1[i] - b
		elif a1[i] > a and b1[i] == b:
			c += a1[i] - a
		elif b1[i] > b and a1[i] == a:
			c += b1[i] - b
	print(c)


t = int(input())
for j in range(t):
	s = 0
	a = int(input())
	b = input().split(' ')
	b = [int(x) for x in b]
	c = input().split(' ')
	c = [int(x) for x in c]
	cm = min(c)
	bm = min(b)
	for i in range(a):
		b1 = b[i] - bm
		c1 = c[i] - cm
		s += max(b1, c1)
	print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mi_a = min(a)
	mi_b = min(b)
	tem_a = []
	tem_b = []
	for i in a:
		tem_a.append(i - mi_a)
	for j in b:
		tem_b.append(j - mi_b)
	ans = 0
	for i in range(n):
		ans += max(tem_a[i], tem_b[i])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(x, y) = (min(a), min(b))
	c = 0
	for i in range(n):
		s1 = a[i] - x
		s2 = b[i] - y
		c += max(s1, s2)
	print(c)


T = int(input())
for i in range(T):
	N = int(input())
	candies = [int(j) for j in input().split()]
	oranges = [int(j) for j in input().split()]
	min_candies = min(candies)
	min_oranges = min(oranges)
	answer = 0
	for j in range(len(candies)):
		delta_candies = candies[j] - min_candies
		delta_oranges = oranges[j] - min_oranges
		if delta_candies > delta_oranges:
			answer = answer + delta_candies
		else:
			answer = answer + delta_oranges
	print(answer)


t = int(input())
for i in range(t):
	ans = 0
	b = int(input())
	r = input().split()
	f = input().split()
	m = []
	a = []
	for j in range(len(r)):
		m.append(int(r[j]))
		a.append(int(f[j]))
	t = min(m)
	k = min(a)
	for h in range(b):
		l = m[h] - t
		s = a[h] - k
		ans += min(l, s)
		ans += max(l, s) - min(l, s)
	print(ans)


for _ in range(int(input())):
	N = int(input())
	orange = [int(x) for x in input().split()]
	candy = [int(x) for x in input().split()]
	min_orange = min(orange)
	min_candy = min(candy)
	counter = 0
	for i in range(N):
		if orange[i] != min_orange and candy[i] != min_candy:
			minimum = min(orange[i] - min_orange, candy[i] - min_candy)
			orange[i] -= minimum
			candy[i] -= minimum
			counter += minimum
		if orange[i] != min_orange:
			counter += orange[i] - min_orange
			orange[i] -= orange[i] - min_orange
		if candy[i] != min_candy:
			counter += candy[i] - min_candy
			candy[i] -= candy[i] - min_candy
	print(counter)


def cost(a, b, a_min, b_min):
	diff_a = a - a_min
	diff_b = b - b_min
	diff_max = max(diff_a, diff_b)
	return diff_max
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	ans = 0
	for i in range(0, n):
		ans += cost(a[i], b[i], a_min, b_min)
	print(ans)


for _ in range(int(input())):
	t = 0
	a = int(input())
	b = list((int(x) for x in input().split()))
	c = list((int(x) for x in input().split()))
	(bmin, cmin) = (min(b), min(c))
	for i in range(a):
		t += max(b[i] - bmin, c[i] - cmin)
	print(t)


from math import *
from collections import *
from random import *
from decimal import Decimal
from bisect import *
import sys
input = sys.stdin.readline

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

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

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

def st():
	return input().rstrip('\n')
t = inp()
while t:
	t -= 1
	n = inp()
	a = lis()
	b = lis()
	(x, y) = (min(a), min(b))
	tot = 0
	for i in range(n):
		r1 = a[i] - x
		r2 = b[i] - y
		tot += min(r1, r2)
		z = min(r1, r2)
		r1 -= z
		r2 -= z
		tot += r1 + r2
	print(tot)


t = int(input())
for test in range(t):
	arr_len = int(input())
	ai = input().split(' ')
	bi = input().split(' ')
	ai = [int(i) for i in ai]
	bi = [int(i) for i in bi]
	mina = min(ai)
	minb = min(bi)
	a_next = [i - mina for i in ai]
	b_next = [j - minb for j in bi]
	total = [max(i, j) for (i, j) in zip(a_next, b_next)]
	print(sum(total))


import sys
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(x, y) = (min(a), min(b))
	ans = 0
	for i in range(len(a)):
		ans += max(a[i] - x, b[i] - y)
	print(str(ans))
	t = t - 1


t = int(input())
while t > 0:
	n = int(input())
	l1 = list(map(int, input().strip().split()))
	l2 = list(map(int, input().strip().split()))
	a1 = 0
	a2 = 0
	z = 0
	f = 0
	maxi = 0
	count = 0
	a1 = min(l1)
	a2 = min(l2)
	for i in range(0, n):
		z = l1[i] - a1
		y = l2[i] - a2
		if z < y:
			count = count + y
		elif z >= y:
			count = count + z
	print(count)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = 0
	ma = min(a)
	mb = min(b)
	for i in range(n):
		if a[i] > ma and b[i] > mb:
			acnt = a[i] - ma
			bcnt = b[i] - mb
			if acnt > bcnt:
				cnt += acnt
			else:
				cnt += bcnt
		elif a[i] > ma:
			acnt = a[i] - ma
			cnt += acnt
		elif b[i] > mb:
			bcnt = b[i] - mb
			cnt += bcnt
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	candList = list(map(int, input().split()))
	oranList = list(map(int, input().split()))
	minCand = min(candList)
	minOran = min(oranList)
	out = 0
	for i in range(n):
		if candList[i] > minCand and oranList[i] > minOran:
			if candList[i] - minCand == oranList[i] - minOran:
				out += candList[i] - minCand
			elif candList[i] - minCand > oranList[i] - minOran:
				out += candList[i] - minCand
			elif candList[i] - minCand < oranList[i] - minOran:
				out += oranList[i] - minOran
		elif candList[i] > minCand:
			out += candList[i] - minCand
		elif oranList[i] > minOran:
			out += oranList[i] - minOran
	print(out)


for _ in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = 0
	c1 = 0
	c2 = 0
	combo = 0
	sing = 0
	x = min(a)
	y = min(b)
	for i in range(0, n):
		a[i] -= x
		b[i] -= y
	for i in range(0, n):
		if a[i] > b[i]:
			combo += b[i]
			a[i] -= b[i]
			b[i] = 0
		elif b[i] > a[i]:
			combo += a[i]
			b[i] -= a[i]
			a[i] = 0
		elif b[i] == a[i]:
			combo += a[i]
			a[i] = 0
			b[i] = 0
	for i in range(0, n):
		c1 += a[i]
		c2 += b[i]
	sing = c1 + c2
	m = combo + sing
	print(m)


def ip():
	return int(input())

def lip():
	return list(map(int, input().split()))
t = ip()
while t:
	t -= 1
	n = ip()
	arr = lip()
	lst = lip()
	a = min(arr)
	b = min(lst)
	count = 0
	for i in range(n):
		count += max(arr[i] - a, lst[i] - b)
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	al = list(map(int, input().split()))
	bl = list(map(int, input().split()))
	ta = min(al)
	tb = min(bl)
	ans = 0
	for i in range(n):
		ca = abs(al[i] - ta)
		cb = abs(bl[i] - tb)
		ans += max(ca, cb)
	print(ans)


t = int(input())
for j in range(t):
	n = int(input())
	lista = list(map(int, input().split(' ')))
	listb = list(map(int, input().split(' ')))
	h = min(lista)
	k = min(listb)
	sum = 0
	for i in range(n):
		if lista[i] != h and listb[i] != k:
			sum += max(lista[i] - h, listb[i] - k)
		elif lista[i] != h:
			sum += lista[i] - h
		elif listb[i] != k:
			sum += listb[i] - k
	print(sum)


import sys
import math
from collections import Counter
import heapq
try:
	for _ in range(int(input())):
		n = int(input())
		a = [int(i) for i in input().split()]
		b = [int(i) for i in input().split()]
		ans = 0
		mna = min(a)
		mnb = min(b)
		for i in range(n):
			ans += max(a[i] - mna, b[i] - mnb)
		if ans == 0:
			print(0)
		else:
			print(ans)
except EOFError as e:
	print(e)


M = lambda : list(map(int, input().split()))
for i in range(int(input())):
	n = int(input())
	ans = 0
	a = M()
	b = M()
	ans += sum([max(b[i] - min(b), a[i] - min(a)) for i in range(n)])
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(n):
		if a[i] != ma and b[i] != mb:
			temp_a = a[i] - ma
			temp_b = b[i] - mb
			m = min(temp_a, temp_b)
			c = c + m
			a[i] = a[i] - m
			b[i] = b[i] - m
		if a[i] == ma and b[i] != mb or (a[i] != ma and b[i] == mb):
			if a[i] == ma:
				c = c + (b[i] - mb)
				b[i] = mb
			else:
				c = c + (a[i] - ma)
				a[i] = ma
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cand = min(a)
	orange = min(b)
	tot = 0
	for i in range(n):
		tot += max(a[i] - cand, b[i] - orange)
	print(tot)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	co = 0
	for i in range(n):
		ka = abs(a[i] - ma)
		kb = abs(b[i] - mb)
		co += min(ka, kb) + abs(ka - kb)
	print(co)


for _ in range(int(input())):
	n = int(input())
	candy = list(map(int, input().strip().split()))
	orange = list(map(int, input().strip().split()))
	(min_candy, min_orange) = (min(candy), min(orange))
	result = 0
	for i in range(n):
		result += candy[i] - min_candy if candy[i] - min_candy > orange[i] - min_orange else orange[i] - min_orange
	print(result)


t = int(input())
while t > 0:
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(y) for y in input().split()]
	count = 0
	for i in range(n):
		m = a[i] - min(a)
		n = b[i] - min(b)
		count += max(m, n)
	print(count)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	d = min(b)
	ans = 0
	for i in range(n):
		ans1 = a[i] - c
		ans2 = b[i] - d
		ans += min(ans1, ans2) + max(ans1, ans2) - min(ans1, ans2)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	ans = min(a)
	count = min(b)
	total = 0
	for i in range(n):
		ans1 = a[i] - ans
		count1 = b[i] - count
		total += max(ans1, count1)
	print(total)


t = int(input())
for _ in range(t):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	bottleneck_candy = min(candy)
	bottleneck_orange = min(orange)
	moves = 0
	for (c, o) in zip(candy, orange):
		moves += max(c - bottleneck_candy, o - bottleneck_orange)
	print(moves)


testcase = int(input())
while testcase >= 1:
	n = int(input())
	candies = [int(i) for i in input().split()]
	oranges = [int(i) for i in input().split()]
	min_candy = min(candies)
	min_orange = min(oranges)
	total_moves = 0
	for i in range(n):
		total_moves += max(candies[i] - min_candy, oranges[i] - min_orange)
	print(total_moves)
	testcase -= 1


def a():
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	if n == 1:
		return 0
	moves = 0
	amin = min(a)
	bmin = min(b)
	for i in range(n):
		atemp = a[i]
		btemp = b[i]
		am1 = atemp - amin
		bm1 = btemp - bmin
		mm = min(am1, bm1)
		moves += mm
		moves += max(am1, bm1) - mm
	return moves
t = int(input())
for i in range(t):
	g = a()
	print(g)


for t in range(int(input())):
	n = int(input())
	apple = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	min_apple = min(apple)
	min_orange = min(orange)
	count = 0
	for i in range(n):
		if apple[i] != min_apple or orange[i] != min_orange:
			while apple[i] > min_apple and orange[i] > min_orange:
				diff_apple = apple[i] - min_apple
				diff_orange = orange[i] - min_orange
				min_diff = min(diff_orange, diff_apple)
				apple[i] = apple[i] - min_diff
				orange[i] = orange[i] - min_diff
				count = count + min_diff
			while apple[i] > min_apple:
				diff_apple = apple[i] - min_apple
				apple[i] = apple[i] - diff_apple
				count = count + diff_apple
			while orange[i] > min_orange:
				diff_orange = orange[i] - min_orange
				orange[i] = orange[i] - diff_orange
				count = count + diff_orange
	print(count)


from math import log2

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

def readWord():
	return next(reader)

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

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

def readLine():
	return input()

def solve(n):
	return n
t = readInt()
for _ in range(0, t):
	n = readInt()
	a = [readInt() for _ in range(0, n)]
	b = [readInt() for _ in range(0, n)]
	minA = min(a)
	minB = min(b)
	res = 0
	for (v1, v2) in zip(a, b):
		add = min(v1 - minA, v2 - minB)
		res += add + max(v1 - minA - add, v2 - minB - add)
	print(res)


t = int(input())
while t > 0:
	n = int(input())
	candies = list(map(int, input().strip().split()))
	oranges = list(map(int, input().strip().split()))
	minCandies = min(candies)
	minOranges = min(oranges)
	totalMoves = 0
	for (candy, orange) in zip(candies, oranges):
		movesRequiredToReduceCandy = candy - minCandies
		movesRequiredToReduceOrange = orange - minOranges
		commonMoves = min(movesRequiredToReduceCandy, movesRequiredToReduceOrange)
		extraMoves = movesRequiredToReduceCandy - commonMoves
		extraMoves += movesRequiredToReduceOrange - commonMoves
		totalMoves += commonMoves + extraMoves
	print(totalMoves)
	t -= 1


import sys
sys.setrecursionlimit(2 ** 20)
I = sys.stdin.readline
pr = sys.stdout.write

def solve():
	n = int(I())
	a = [*map(int, I().split())]
	b = [*map(int, I().split())]
	(ma, mb) = (min(a), min(b))
	s = 0
	for (x, y) in zip(a, b):
		s += max(x - ma, y - mb)
	pr(f'{s}\n')

def main():
	for _ in range(int(I())):
		solve()
main()


n = int(input())
for i in range(n):
	t = int(input())
	c = list(map(int, input().split()))
	d = list(map(int, input().split()))
	g = min(c)
	h = min(d)
	su = 0
	for j in range(t):
		if c[j] > g and d[j] > h:
			r = c[j] - g
			s = d[j] - h
			su = su + min(r, s)
			su = su + max(r, s) - min(r, s)
		else:
			if c[j] > g:
				su = su + c[j] - g
			if d[j] > h:
				su = su + d[j] - h
	print(su)


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()]
	t1 = min(a)
	t2 = min(b)
	a = [i - t1 for i in a]
	b = [i - t2 for i in b]
	pr = []
	for i in range(len(a)):
		pr.append(max(a[i], b[i]))
	print(sum(pr))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	A = min(a)
	B = min(b)
	for j in range(n):
		ans += max(a[j] - A, b[j] - B)
	print(ans)


t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = a[0]
	minb = b[0]
	for i in range(n):
		if mina > a[i]:
			mina = a[i]
		if minb > b[i]:
			minb = b[i]
	w = 0
	for i in range(n):
		if a[i] > mina and b[i] > minb:
			x = min(a[i] - mina, b[i] - minb)
			w = w + x
			a[i] = a[i] - x
			b[i] = b[i] - x
		if a[i] > mina:
			w = w + (a[i] - mina)
		if b[i] > minb:
			w = w + (b[i] - minb)
	print(w)


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
t = int(input())
for i in range(t):
	n = int(input())
	a = lnii()
	b = lnii()
	a_min = min(a)
	b_min = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - a_min, b[i] - b_min)
	print(ans)


f = lambda : list(map(int, input().split()))
for i in range(int(input())):
	n = int(input())
	c = f()
	o = f()
	ans = 0
	for (a, b) in zip(c, o):
		ans += max(a - min(c), b - min(o))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(z) for z in input().split()]
	b = [int(z) for z in input().split()]
	x = min(a)
	y = min(b)
	res = 0
	for i in range(0, n):
		s1 = a[i] - x
		s2 = b[i] - y
		w = min(s1, s2)
		res += w
		s1 = s1 - w
		s2 = s2 - w
		res += s1 + s2
	print(res)


T = int(input())
for i in range(T):
	r = int(input())
	str1 = input()
	str2 = input()
	l1 = list(map(lambda st: int(st), str1.strip().split()))
	l2 = list(map(lambda st: int(st), str2.strip().split()))
	min1 = min(l1)
	min2 = min(l2)
	count = 0
	for j in range(r):
		if l1[j] > min1 and l2[j] > min2:
			if l1[j] - min1 > l2[j] - min2:
				count += l1[j] - min1
			else:
				count += l2[j] - min2
		elif l1[j] > min1:
			count += l1[j] - min1
		elif l2[j] > min2:
			count += l2[j] - min2
	print(count)


import sys
input = sys.stdin.buffer.readline

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

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	n = int(input())
	a = I()
	b = I()
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		diffa = a[i] - mina
		diffb = b[i] - minb
		ans += min(diffa, diffb)
		mini = min(diffa, diffb)
		diffb -= mini
		diffa -= mini
		ans += diffb + diffa
	print(ans)


import math
for _ in range(int(input())):
	l = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	c = 0
	min1 = min(l1)
	min2 = min(l2)
	for i in range(l):
		c = c + max(abs(min1 - l1[i]), abs(min2 - l2[i]))
	print(c)


t_case = int(input())
for _ in range(t_case):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	sa = min(arr)
	sb = min(brr)
	move = 0
	for i in range(n):
		if arr[i] > sa and brr[i] > sb:
			t1 = arr[i] - sa
			t2 = brr[i] - sb
			arr[i] -= min(t1, t2)
			brr[i] -= min(t1, t2)
			move += min(t1, t2)
			move += arr[i] - sa
			move += brr[i] - sb
		elif arr[i] > sa and brr[i] == sb:
			move += arr[i] - sa
		else:
			move += brr[i] - sb
	print(move)


import heapq as hq
from heapq import heappop, heappush
from collections import deque, defaultdict

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

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

def insr():
	s = input()
	return list(s[:len(s)])

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

def subset_sum_count(arr, n, sum):
	dp = [[0 for _ in range(sum + 1)] for _ in range(n + 1)]
	for i in range(n + 1):
		for j in range(sum + 1):
			if j == 0:
				dp[i][j] = 1
			elif arr[i - 1] <= j:
				dp[i][j] = dp[i - 1][j - arr[i - 1]] + dp[i - 1][j]
			else:
				dp[i][j] = dp[i - 1][j]
	return dp[n][sum]

def prefix(a):
	pre = []
	pre.append(a[0])
	for i in range(1, len(a)):
		pre.append(pre[i - 1] + a[i])
	return pre

def binary_search(func, lo, hi, abs_prec=1e-07):
	while abs(hi - lo) > abs_prec:
		mi = lo + (hi - lo) / 2
		if func(mi):
			hi = mi
		else:
			lo = mi
	return (lo + hi) / 2

def ternary_search(func, lo, hi, abs_prec=1e-07):
	while abs(hi - lo) > abs_prec:
		lo_third = lo + (hi - lo) / 3
		hi_third = hi - (hi - lo) / 3
		if func(lo_third) < func(hi_third):
			lo = lo_third
		else:
			hi = hi_third
	return (lo + hi) / 2

def discrete_binary_search(func, lo, hi):
	while lo < hi:
		mi = lo + (hi - lo) // 2
		if func(mi):
			hi = mi
		else:
			lo = mi + 1
	return lo

def discrete_ternary_search(func, lo, hi):
	while lo <= hi:
		lo_third = lo + (hi - lo) // 3
		hi_third = lo + (hi - lo) // 3 + (1 if 0 < hi - lo < 3 else (hi - lo) // 3)
		if func(lo_third) < func(hi_third):
			lo = lo_third + 1
		else:
			hi = hi_third - 1
	return lo
	return -1

def right_rotate(a, s):
	return a[s:] + a[:s]

def dec_to_bin(x):
	return int(bin(x)[2:])

def str_to_integer_list(n):
	a = []
	for i in range(len(n)):
		a.append(int(n[i]))
	return a

def list_to_str(l):
	s = ''
	for i in l:
		s += str(i)
	return s

def dijkstra(s, N, E):
	visited = set()
	dist = {}
	for i in range(1, N + 1):
		dist[i] = 1 << 29
	queue = [(dist[i], i) for i in range(1, N + 1)]
	hq.heappush(queue, (0, s))
	dist[s] = 0
	while queue:
		(d, u) = hq.heappop(queue)
		if u in visited:
			continue
		for t in E[u]:
			(v, r) = t
			if dist[v] > d + r:
				dist[v] = d + r
				hq.heappush(queue, (dist[v], v))
		visited.add(u)
	return dist

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def dijkstra(n, graph, start):
	(dist, parents) = ([float('inf')] * n, [-1] * n)
	dist[start] = 0
	queue = [(0, start)]
	while queue:
		(path_len, v) = heappop(queue)
		if path_len == dist[v]:
			for (w, edge_len) in graph[v]:
				if edge_len + path_len < dist[w]:
					(dist[w], parents[w]) = (edge_len + path_len, v)
					heappush(queue, (edge_len + path_len, w))
	return (dist, parents)

def path(start, end, parent):
	path = [end]
	while path[-1] != start:
		path.append(parent[path[-1]])
	path.reverse()
	return path

def bfs(graph, start, goal):
	if start == goal:
		return [start]
	visited = {start}
	queue = deque([(start, [])])
	while queue:
		(current, path) = queue.popleft()
		visited.add(current)
		for neighbor in graph[current]:
			if neighbor == goal:
				return path + [current, neighbor]
			if neighbor in visited:
				continue
			queue.append((neighbor, path + [current]))
			visited.add(neighbor)
	return None
import os
import sys
from io import BytesIO, IOBase

def DecimalToBinary(n):

	def helper(n):
		if n == 0:
			return ''
		else:
			if n % 2 == 1:
				binaryDigit = '1'
			else:
				binaryDigit = '0'
			return helper(n // 2) + binaryDigit
	if n == 0:
		result = '0'
	else:
		result = helper(n)
	return result

def p(board):
	for i in range(8):
		s = ''
		for j in range(8):
			s += board[i][j]
		print(s)

def binaryToDecimal(n):
	return int(n, 2)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def solve(a, b):
	x = DecimalToBinary(a)
	y = DecimalToBinary(b)
	z = x + y
	l = y + x
	r = binaryToDecimal(z) - binaryToDecimal(l)
	return r

def main():
	for _ in range(inp()):
		n = inp()
		a = inlt()
		b = inlt()
		a1 = min(a)
		b1 = min(b)
		s = 0
		for i in range(n):
			s += max(a[i] - a1, b[i] - b1)
		print(s)
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 read_arr():
	return [int(x) for x in input().split()]
N_SETS = int(input())
for i in range(N_SETS):
	n_pairs = int(input())
	bs = read_arr()
	cs = read_arr()
	m = min(min(bs), min(cs))
	min_bs = min(bs)
	min_cs = min(cs)
	bs = [x - min_bs for x in bs]
	cs = [x - min_cs for x in cs]
	res = 0
	for (b, c) in zip(bs, cs):
		res += max(b, c)
	print(res)


from sys import stdin, stdout
T = int(stdin.readline())
for _ in range(T):
	N = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	b = [int(x) for x in stdin.readline().split()]
	amn = min(a)
	bmn = min(b)
	ans = 0
	for i in range(N):
		ans += max(a[i] - amn, b[i] - bmn)
	print(ans)


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min1 = min(a)
	min2 = min(b)
	ans = 0
	for i in range(n):
		moves1 = a[i] - min1
		moves2 = b[i] - min2
		ans += max(moves1, moves2)
	print(ans)


def cal(a, b, t1, t2):
	ans = 0
	ans += a - t1
	ans += b - t2
	ans = ans - min(a - t1, b - t2)
	return ans
import math
t = int(input())
for j in range(t):
	n = int(input())
	a = [int(i) for i in input().strip().split()]
	b = [int(i) for i in input().strip().split()]
	t1 = min(a)
	t2 = min(b)
	ans = 0
	for i in range(len(a)):
		ans += cal(a[i], b[i], t1, t2)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(_) for _ in input().split()]
	b = [int(_) for _ in input().split()]
	min_a = min(a)
	min_b = min(b)
	res = 0
	for (x, y) in zip(a, b):
		res += max(x - min_a, y - min_b)
	print(res)


t = int(input())
for _ in range(t):
	ans = 0
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	min_a = min(a)
	min_b = min(b)
	for i in range(n):
		if a[i] > min_a and b[i] > min_b:
			cur = min(a[i] - min_a, b[i] - min_b)
			ans += cur
			ans += a[i] - cur - min_a + b[i] - cur - min_b
		elif a[i] > min_a:
			ans += a[i] - min_a
		elif b[i] > min_b:
			ans += b[i] - min_b
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = input()
	l1 = l1.split(' ')
	l1 = [int(i) for i in l1]
	l2 = input()
	l2 = l2.split(' ')
	l2 = [int(i) for i in l2]
	a_min = min(l1)
	b_min = min(l2)
	count = 0
	for j in range(n):
		x = l1[j] - a_min
		y = l2[j] - b_min
		if x > y:
			count = count + x
		else:
			count = count + y
	print(count)


for u in range(int(input())):
	n = int(input())
	x = [int(w) for w in input().split()]
	y = [int(w) for w in input().split()]
	a = min(x)
	b = min(y)
	ans = 0
	for i in range(n):
		ans += max(x[i] - a, y[i] - b)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		if a[i] > amin:
			tempa = a[i] - amin
		else:
			tempa = 0
		if b[i] > bmin:
			tempb = b[i] - bmin
		else:
			tempb = 0
		mini = min(tempa, tempb)
		ans += tempa + tempb - mini
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	al = list(map(int, input().split()))
	bl = list(map(int, input().split()))
	amin = min(al)
	bmin = min(bl)
	s = 0
	aml = [x - amin for x in al]
	bml = [x - bmin for x in bl]
	for j in range(n):
		s += max([aml[j], bml[j]])
	print(s)


def ans(a, b):
	ans = 0
	mina = min(a)
	minb = min(b)
	z = list(zip(a, b))
	for i in z:
		m = i[0] - mina
		n = i[1] - minb
		ans += max(m, n)
	return ans
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(ans(a, b))


import sys
input = sys.stdin.readline
T = int(input())
for testcase in range(T):
	n = int(input())
	a = tuple(map(int, input().split()))
	b = tuple(map(int, input().split()))
	(A, B) = (min(a), min(b))
	res = 0
	for i in range(n):
		da = a[i] - A
		db = b[i] - B
		if da < db:
			(da, db) = (db, da)
		res += da
	print(res)


z = int(input())
for i in range(z):
	n = int(input())
	a = []
	b = []
	input1 = input().split()
	input2 = input().split()
	for i in input1:
		if i.isnumeric():
			a.append(int(i))
	for i in input2:
		if i.isnumeric():
			b.append(int(i))
	candy = a.copy()
	orange = b.copy()
	a.sort()
	b.sort()
	minc = a[0]
	mino = b[0]
	count = 0
	for i in range(n):
		if candy[i] > minc and orange[i] > mino:
			if candy[i] - minc > orange[i] - mino:
				diff = candy[i] - minc
			else:
				diff = orange[i] - mino
			candy[i] = candy[i] - diff
			orange[i] = orange[i] - diff
			count += diff
		if candy[i] > minc:
			diff = candy[i] - minc
			count += candy[i] - minc
		elif orange[i] > mino:
			diff = orange[i] - mino
			count += orange[i] - mino
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(a_e, b_e) = (min(a), min(b))
	summ = 0
	for i in range(n):
		summ += max(a[i] - a_e, b[i] - b_e)
	print(summ)


n = int(input())
for i in range(n):
	ans = 0
	x = int(input())
	seq1 = input()
	A = seq1.split()
	candies = [int(a) for a in A]
	seq2 = input()
	A = seq2.split()
	orange = [int(a) for a in A]
	min_can = min(candies)
	min_ora = min(orange)
	for count in range(x):
		add = max(candies[count] - min_can, orange[count] - min_ora)
		ans += add
	print(ans)


for _ in range(int(input())):
	n = int(input())
	moves = 0
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	(a1, b1) = (min(a), min(b))
	for i in range(n):
		temp = 0
		if a[i] > a1:
			temp += a[i] - a1
			moves += temp
		if b[i] > b1:
			if b[i] - b1 > temp:
				moves += b[i] - b1 - temp
			else:
				moves += 0
	print(moves)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

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

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	bb = [int(a) for a in inputi().split()]
	maa = min(aa)
	mbb = min(bb)
	ae = [a - maa for a in aa]
	be = [b - mbb for b in bb]
	print(sum(map(max, ae, be)))

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


def calc(a, b):
	ma = min(a)
	mb = min(b)
	n = len(a)
	return sum([max(a[i] - ma, b[i] - mb) for i in range(n)])
T = int(input())
for t in range(T):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	assert len(a) == n == len(b)
	r = calc(a, b)
	print(r)


import sys
from collections import defaultdict
mod = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 8)
INF = float('inf')

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

def inpl():
	return list(map(int, sys.stdin.readline().split()))
t = inp()
for _ in range(t):
	n = inp()
	a = inpl()
	b = inpl()
	am = min(a)
	bm = min(b)
	res = 0
	for i in range(n):
		res += max(a[i] - am, b[i] - bm)
	print(res)


n = int(input())
for i in range(n):
	x = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	m1 = min(l)
	m2 = min(l1)
	c = 0
	for j in range(x):
		if l[j] == m1 and l1[j] == m2:
			c += 0
		elif l[j] == m1:
			c += l1[j] - m2
		elif l1[j] == m2:
			c += l[j] - m1
		else:
			v1 = l[j] - m1
			v2 = l1[j] - m2
			c += min(v1, v2)
			c += abs(v1 - v2)
	print(c)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	a = min(l1)
	b = min(l2)
	ans = 0
	for i in range(n):
		if l1[i] > a and l2[i] > b:
			s = l1[i] - a
			s1 = l2[i] - b
			ans += max(s, s1)
		elif l1[i] > a and l2[i] == b:
			ans += l1[i] - a
		elif l1[i] == a and l2[i] > b:
			ans += l2[i] - b
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = sum(a) - n * min(a) + sum(b) - n * min(b)
	c = 0
	for i in range(n):
		c += min(a[i] - min(a), b[i] - min(b))
	print(x - c)


t = int(input())
for i in range(t):
	n = int(input())
	a = input().replace('(', '').replace(')', '').replace(',', '').split()
	a = list(map(int, a))
	b = input().replace('(', '').replace(')', '').replace(',', '').split()
	b = list(map(int, b))
	gifts = [[a[i], b[i]] for i in range(n)]
	count = 0
	for gift in gifts:
		count += max(gift[0] - min(a), gift[1] - min(b))
	print(count)


for _ in range(int(input())):
	N = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = min(l1)
	m2 = min(l2)
	c = 0
	for i in range(N):
		if l1[i] != m1 and l2[i] != m2:
			a = l1[i] - m1
			b = l2[i] - m2
			c += max(a, b)
		elif l1[i] != m1:
			c += l1[i] - m1
		elif l2[i] != m2:
			c += l2[i] - m2
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	t1 = min(a)
	t2 = min(b)
	c = 0
	for i in range(n):
		t3 = a[i] - t1
		t4 = b[i] - t2
		c += max(t3, t4)
	print(c)


t = int(input())
for y in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	tot = 0
	for x in range(n):
		difA = a[x] - amin
		difB = b[x] - bmin
		if difA == difB:
			dif = difA
		elif difA > difB:
			dif = difA
		else:
			dif = difB
		tot += dif
	print(tot)


import math

def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))[:n]
	b = list(map(int, input().split()))[:n]
	x = min(a)
	y = min(b)
	(s1, s2) = (0, 0)
	count = 0
	for i in range(n):
		if a[i] == x and b[i] == y:
			continue
		elif b[i] == y and a[i] != x:
			count += a[i] - x
		elif b[i] != y and a[i] == x:
			count += b[i] - y
		elif b[i] != y and a[i] != x:
			s1 = a[i] - x
			s2 = b[i] - y
			if s1 == s2:
				count += s1
			elif s1 > s2:
				count += s2
				count += s1 - s2
			elif s2 > s1:
				count += s1
				count += s2 - s1
	print(count)


test_cases = int(input())
for e in range(test_cases):
	gifts = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	a = min(candy)
	b = min(orange)
	ans = 0
	for i in range(gifts):
		ans += max(candy[i] - a, orange[i] - b)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	m1 = min(l1)
	m2 = min(l2)
	ans = 0
	for i in range(n):
		d1 = l1[i] - m1
		d2 = l2[i] - m2
		common_moves = min(d1, d2)
		ans += common_moves + (max(d1, d2) - common_moves)
	print(ans)


def solve(a, b, n):
	lowA = min(a)
	lowB = min(b)
	ops = 0
	for i in range(n):
		if a[i] > lowA and b[i] > lowB:
			if a[i] - lowA < b[i] - lowB:
				diff = a[i] - lowA
			else:
				diff = b[i] - lowB
			ops += diff
			a[i] -= diff
			b[i] -= diff
	for i in range(n):
		if a[i] > lowA:
			ops += a[i] - lowA
		if b[i] > lowB:
			ops += b[i] - lowB
	print(ops)
t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solve(a, b, n)


def giftsFixing(length, a, b):
	if length == 0 or length == 1:
		return 0
	targetA = sorted(a)[0]
	targetB = sorted(b)[0]
	moves = 0
	for i in range(length):
		diffA = a[i] - targetA
		diffB = b[i] - targetB
		if diffA > diffB:
			moves += diffA
		else:
			moves += diffB
	return moves
for i in range(int(input())):
	length = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	print(giftsFixing(length, a, b))


import bisect
import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

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

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

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	for _ in range(iin()):
		n = iin()
		a = ain()
		b = ain()
		amin = min(a)
		bmin = min(b)
		ans = 0
		for i in range(n):
			am = a[i] - amin
			bm = b[i] - bmin
			ans += max(am, bm)
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	counter = 0
	mincandy = min(candy)
	minorange = min(orange)
	for i in range(n):
		counter += max(candy[i] - mincandy, orange[i] - minorange)
	print(counter)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	c = 0
	for i in range(n):
		if a[i] > am and b[i] > bm:
			a1 = abs(a[i] - am)
			b1 = abs(b[i] - bm)
			if a1 < b1:
				a[i] -= a1
				b[i] -= a1
				c += a1
			else:
				a[i] -= b1
				b[i] -= b1
				c += b1
		if a[i] != am:
			d = abs(a[i] - am)
			a[i] -= d
			c += d
		if b[i] != bm:
			d = abs(b[i] - bm)
			b[i] -= d
			c += d
	print(c)


t = int(input())
for j in range(t):
	n = int(input())
	list1 = list(map(int, input().split(' ')))
	list2 = list(map(int, input().split(' ')))
	min1 = min(list1)
	min2 = min(list2)
	sum1 = 0
	for (i, j) in zip(list1, list2):
		sum1 += max(i - min1, j - min2)
	print(sum1)


for t in range(int(input())):
	n = int(input())
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(n):
		d_a = a[i] - min_a
		d_b = b[i] - min_b
		count += max(d_a, d_b)
	print(count)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if a[i] == min(a) and b[i] != min(b):
			ans += b[i] - min(b)
		elif a[i] != min(a) and b[i] == min(b):
			ans += a[i] - min(a)
		else:
			ans += max(a[i] - min(a), b[i] - min(b))
	print(ans)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minA = min(a)
	minB = min(b)
	ans = sum([max(a[i] - minA, b[i] - minB) for i in range(n)])
	print(ans)
t = int(input())
for _ in range(t):
	solve()


nCases = int(input())
for _ in range(nCases):
	nBags = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	minA = min(a)
	minB = min(b)
	moves = 0
	for i in range(nBags):
		moveA = a[i] - minA
		moveB = b[i] - minB
		moves += max(moveA, moveB)
	print(moves)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 30
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input().rstrip())
	a = list(map(int, input().rstrip().split(' ')))
	b = list(map(int, input().rstrip().split(' ')))
	min_a = min(a)
	min_b = min(b)
	t = 0
	for i in range(n):
		t += max(a[i] - min_a, b[i] - min_b)
	print(t)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	m = 0
	for i in range(len(a)):
		if a[i] == am and b[i] > bm:
			m += b[i] - bm
		elif a[i] > am and b[i] == bm:
			m += a[i] - am
		else:
			d = a[i] - am
			h = b[i] - bm
			m += min(d, h) + abs(d - h)
	print(m)


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	ans = 0
	for i in range(n):
		if a[i] == m1:
			ans += b[i] - m2
		elif b[i] == m2:
			ans += a[i] - m1
		elif a[i] - m1 < b[i] - m2:
			ans += a[i] - m1
			b[i] -= a[i] - m1
			ans += b[i] - m2
		else:
			ans += b[i] - m2
			a[i] -= b[i] - m2
			ans += a[i] - m1
	print(ans)


x = int(input())
for i in range(0, x):
	n = int(input())
	m = list(map(int, input().split()))[:n]
	ar = list(map(int, input().split()))[:n]
	d = min(m)
	g = min(ar)
	s = 0
	for j in range(0, n):
		s = s + max(m[j] - d, ar[j] - g)
	print(s)


t = int(input())
for i in range(t):
	n = int(input())
	a_s = list(map(int, input().split()))
	b_s = list(map(int, input().split()))
	min_a = min(a_s)
	min_b = min(b_s)
	count = 0
	for j in range(n):
		a_dif = a_s[j] - min_a
		b_dif = b_s[j] - min_b
		count += max(a_dif, b_dif)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	s = 0
	for i in range(n):
		s += max(abs(a[i] - a1), abs(b[i] - b1))
	print(s)


def solve():
	n = int(input())
	arr = [int(v) for v in input().split()]
	brr = [int(v) for v in input().split()]
	am = min(arr)
	bm = min(brr)
	moves = 0
	for i in range(n):
		tog = min(arr[i] - am, brr[i] - bm)
		moves += tog
		arr[i] -= tog
		brr[i] -= tog
		moves += arr[i] - am + brr[i] - bm
	print(moves)
t = int(input())
for _ in range(t):
	solve()


n = int(input())
kk = []
for i in range(n):
	nn = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ans = 0
	mina = min(a)
	minb = min(b)
	for j in range(nn):
		if a[j] == mina and b[j] != minb:
			ans += b[j] - minb
		elif a[j] != mina and b[j] == minb:
			ans += a[j] - mina
		elif a[j] != mina and b[j] != minb:
			minraz = min(a[j] - mina, b[j] - minb)
			ans += minraz
			a[j] -= minraz
			b[j] -= minraz
			if a[j] != mina:
				ans += a[j] - mina
			if b[j] != minb:
				ans += b[j] - minb
	kk.append(ans)
for i in kk:
	print(i)


t = int(input())

def fun(n, a, b):
	ans = 0
	a1 = min(a)
	b1 = min(b)
	for i in range(n):
		k1 = a[i] - a1
		k2 = b[i] - b1
		ans += min(k1, k2)
		k = max(k1, k2)
		k3 = min(k1, k2)
		ans += k - k3
	print(ans)
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	fun(n, a, b)


for j in range(int(input())):
	n = int(input())
	l = [int(j) for j in input().split()]
	l1 = [int(j) for j in input().split()]
	ans = 0
	a = min(l)
	b = min(l1)
	for i in range(n):
		ans += max(l[i] - a, l1[i] - b)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	cnt = 0
	for i in range(n):
		if a[i] - a_min < b[i] - b_min:
			cnt += a[i] - a_min
			b[i] -= a[i] - a_min
			cnt += b[i] - b_min
		elif a[i] - a_min > b[i] - b_min:
			cnt += b[i] - b_min
			a[i] -= b[i] - b_min
			cnt += a[i] - a_min
		else:
			cnt += b[i] - b_min
			a[i] -= b[i] - b_min
			b[i] -= b[i] - b_min
	print(cnt)


def f():
	n = int(input())
	va = list(map(int, input().split()))
	vb = list(map(int, input().split()))
	(xa, xb) = (min(va), min(vb))
	ms = 0
	for i in range(n):
		da = va[i] - xa
		db = vb[i] - xb
		if da == 0:
			ms += db
		elif db == 0:
			ms += da
		else:
			mn = min(da, db)
			ms += mn
			da -= mn
			db -= mn
			ms += da + db
	return ms
t = int(input())
for _ in range(t):
	print(f())


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	p = min(arr)
	q = min(brr)
	(a, b, c) = (0, 0, 0)
	count = 0
	for i in range(n):
		if arr[i] != p and brr[i] != q:
			a = arr[i] - p
			b = brr[i] - q
			count += max(a, b)
		elif arr[i] != p:
			count += arr[i] - p
		else:
			count += brr[i] - q
	print(count)


t = int(input())
for i in range(t):
	q = 0
	n = int(input())
	candyArr = list(map(int, input().split()))
	orangeArr = list(map(int, input().split()))
	candyMin = min(candyArr)
	orangeMin = min(orangeArr)
	skokaJrat = 0
	for j in range(n):
		candyArr[j] = candyArr[j] - candyMin
		orangeArr[j] = orangeArr[j] - orangeMin
		if orangeArr[j] > candyArr[j]:
			skokaJrat += orangeArr[j]
		else:
			skokaJrat += candyArr[j]
	print(skokaJrat)


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	minc = min(c)
	mino = min(o)
	ans = 0
	for i in range(n):
		ec = c[i] - minc
		eo = o[i] - mino
		extra = abs(ec - eo)
		ans += extra
		common = 0
		if ec > eo:
			common = ec - extra
		else:
			common = eo - extra
		ans += common
	print(ans)


tests = int(input())
for i in range(tests):
	count = 0
	length = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	min1 = min(l1)
	min2 = min(l2)
	for i in range(length):
		l1[i] -= min1
	for i in range(length):
		l2[i] -= min2
	for i in range(length):
		value = min(l1[i], l2[i])
		count += min(l1[i], l2[i])
		l1[i] -= min(l1[i], l2[i])
		l2[i] -= value
	count += sum(l1)
	count += sum(l2)
	print(count)


output_list = []
cases = int(input())
for i in range(cases):
	garbage = int(input())
	sum = 0
	candiA = [int(x) for x in input().split(' ')]
	candiB = [int(x) for x in input().split(' ')]
	AerGoal = min(candiA)
	BerGoal = min(candiB)
	for i in range(garbage):
		differen1 = candiA[i] - AerGoal
		differen2 = candiB[i] - BerGoal
		sum += max(differen1, differen2)
	output_list.append(sum)
print('\n'.join((str(x) for x in output_list)))


def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = len(li) - 1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def mex(li):
	check = [0] * 1001
	for i in li:
		check[i] += 1
	for i in range(len(check)):
		if check[i] == 0:
			return i

def sumdigits(n):
	ans = 0
	while n != 0:
		ans += n % 10
		n //= 10
	return ans

def product(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def maxpower(n, k):
	cnt = 0
	while n > 1:
		cnt += 1
		n //= k
	return cnt

def knapsack(li, sumi, s, n, dp):
	if s == sumi // 2:
		return 1
	elif n == 0:
		return 0
	elif dp[n][s] != -1:
		return dp[n][s]
	else:
		if li[n - 1] <= s:
			dp[n][s] = knapsack(li, sumi, s - li[n - 1], n - 1, dp) or knapsack(li, sumi, s, n - 1, dp)
		else:
			dp[n][s] = knapsack(li, sumi, s, n - 1, dp)
		return dp[n][s]

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum
from math import *
from collections import deque
max_steps = 100005
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - amin, b[i] - bmin)
	print(ans)


a = int(input())
for i in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	c1 = list(map(int, input().split()))
	g = 0
	g1 = 0
	g = min(c)
	g1 = min(c1)
	ch = 0
	for i in range(b):
		if c[i] > g:
			ch += max(c[i] - g, c1[i] - g1)
		else:
			ch += c1[i] - g1
	print(ch)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(ma, mb) = (min(a), min(b))
	c = 0
	for i in range(n):
		x = sorted([a[i] - ma, b[i] - mb])
		c += x[1]
	print(c)


import random

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		k1 = a[i] - amin
		k2 = b[i] - bmin
		ans += max(k1, k2)
	print(ans)


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()]
	n_a = min(a)
	n_b = min(b)
	moves = 0
	for j in range(n):
		d_a = a[j] - n_a
		d_b = b[j] - n_b
		moves += max(d_a, d_b)
	print(moves)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a0 = min(a)
	b0 = min(b)
	ans = 0
	for i in range(len(a)):
		ai = a[i]
		bi = b[i]
		k = min(ai - a0, bi - b0)
		ans += k
		ans += ai - a0 - k
		ans += bi - b0 - k
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minA = min(a)
	minB = min(b)
	ans = 0
	for i in range(n):
		tempA = a[i] - minA
		tempB = b[i] - minB
		ans += max(tempA, tempB)
	print(ans)


def solve(a, b):
	(a_min, b_min) = (min(a), min(b))
	a_b = zip(a, b)
	r = 0
	for n in a_b:
		(a_i, b_i) = n
		d1 = a_i - a_min
		d2 = b_i - b_min
		r += max(d1, d2)
	return r
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(a, b))


import sys
INP = lambda : sys.stdin.readline().strip()
INT = lambda : int(INP())
MAP = lambda : map(int, INP().split())
ARR = lambda : [int(i) for i in INP().split()]

def JOIN(arr, x=' '):
	return x.join([str(i) for i in arr])

def EXIT(x='NO'):
	print(x)
	exit()
for _ in range(INT()):
	n = INT()
	arr = ARR()
	brr = ARR()
	(a, b) = (min(arr), min(brr))
	ans = 0
	for i in range(n):
		ans += max(arr[i] - a, brr[i] - b)
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	x = min(a)
	y = min(b)
	a1 = [abs(a[i] - x) for i in range(n)]
	b1 = [abs(b[i] - y) for i in range(n)]
	a1 = [max(a1[i], b1[i]) for i in range(n)]
	print(sum(a1))


import math
t = int(input())
for z in range(0, t):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	minc = min(candy)
	mino = min(orange)
	count = 0
	for i in range(0, n):
		count = count + max(candy[i] - minc, orange[i] - mino)
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	ans = 0
	for g in range(n):
		if a[g] - a_min > b[g] - b_min:
			ans += a[g] - a_min
		else:
			ans += b[g] - b_min
	print(ans)


from sys import stdin
from math import ceil, gcd

def func():
	return
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	ans = 0
	x = min(a)
	y = min(b)
	for i in range(n):
		(l, r) = (a[i] - x, b[i] - y)
		ans += max(l, r)
	print(ans)


cases = int(input())
for i in range(cases):
	lenth = int(input())
	orange = list(map(int, input().split()))
	candy = list(map(int, input().split()))
	total = 0
	random = 0
	first = min(orange)
	second = min(candy)
	for j in range(lenth):
		orange[j] -= first
	for j in range(0, lenth):
		candy[j] -= second
	for j in range(0, lenth):
		if orange[j] and candy[j] > 0:
			random = min(orange[j], candy[j])
			total += random
			orange[j] -= random
			candy[j] -= random
	for j in range(0, lenth):
		total = total + orange[j] + candy[j]
	print(total)


min_a = 1000000001
min_b = 1000000001
a = []
b = []
res = 0
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	for i in range(0, n):
		if b[i] > min_b and a[i] > min_a:
			aux = min(b[i] - min_b, a[i] - min_a)
			res += aux
			a[i] -= aux
			b[i] -= aux
	for i in range(0, n):
		if b[i] > min_b:
			res += b[i] - min_b
		if a[i] > min_a:
			res += a[i] - min_a
	print(res)
	res = 0
	min_a = 1000000001
	min_b = 1000000001


from sys import stdin, stdout
from collections import Counter
input = stdin.readline

def write(n, sep='\n'):
	stdout.write(str(n))
	stdout.write(sep)

def gil():
	return list(map(int, input().split()))
for _t in range(int(input())):
	n = int(input())
	a = gil()
	b = gil()
	i = 0
	ma = min(a)
	mb = min(b)
	c = 0
	while i < n:
		x = a[i] - ma
		y = b[i] - mb
		c += max(x, y, 0)
		i += 1
	print(c)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin, stdout
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math
import math
import time
from queue import Queue

def seive(n):
	l = [True]
	l = l * (n + 1)
	for i in range(2, int(sqrt(n)) + 1):
		if l[i] == True:
			val = i * i
			while val < len(l):
				l[val] = False
				val += i
	prime = []
	for i in range(2, len(l)):
		if l[i] == True:
			prime.append(i)
	return prime

def dp(l, i, n, val, ans):
	if i >= n or val < 0:
		return 1000000
	elif val == 0:
		return 0
	else:
		if ans[i] == 1000000:
			ans[i] = min(min(1 + dp(l, i + 1, n, val - l[i], ans), 1 + dp(l, i, n, val - l[i], ans)), dp(l, i + 1, n, val, ans))
		return ans[i]
from queue import Queue

def factors(n):
	l = []
	for i in range(1, int(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 check1(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v -= 1

def check2(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v += 1

def up(n):
	j = n - 1
	while j > 0:
		if n % j == 0:
			break
		j -= 1
	return j

def fac(n):
	c = 1
	i = 1
	while i <= n:
		c *= i
		i += 1
	return c

def check_happy(n):
	ss = set()
	print(n)
	while n != 1:
		val = n
		s = 0
		print(val)
		while val != 0:
			s += (val % 10) ** 2
			val = val // 10
		print(val)
		print('hi')
		if val in ss:
			return False
		else:
			n = val
			ss.add(n)
	return True

def update(a, b):
	c = 1
	val = a
	while a < b:
		print(c, a)
		c += c
		a += a
	print(1)
	while a > b:
		print()
		a -= val
		c -= 1
	return c
import random as rand

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
from itertools import permutations

def insertion_sort(arr):
	for i in range(len(arr)):
		j = i
		while j > 0:
			if arr[j] < arr[j - 1]:
				temp = arr[j]
				arr[j] = arr[j - 1]
				arr[j - 1] = temp
			j -= 1
	return arr

def quick_sort(arr, low, high):
	i = low
	j = high
	while i < j:
		if arr[i] > arr[low] and arr[j] < arr[low]:
			temp = arr[i]
			arr[i] = arr[j]
			arr[j] = arr[i]
			i += 1
			j -= 1
		elif arr[i] <= arr[low]:
			i += 1
		elif arr[j] >= arr[low]:
			j -= 1
	print(i, j)
	toto = arr[j]
	arr[j] = arr[low]
	arr[low] = toto
	return j

def dodo(arr, low, high):
	if low < high:
		val = quick_sort(arr, low, high)
		dodo(arr, low, val - 1)
		dodo(arr, val + 1, high)

def dp(arr, c, n, k, z, ans):
	if k == 0:
		return ans
	elif c == 0:
		return dp(arr, c + 1, n, k - 1, z, ans + arr[c + 1])
	elif c == n - 1:
		if z == 0:
			return 0
		else:
			return dp(arr, c - 1, n, k - 1, z - 1, ans + arr[c - 1])
	elif z == 0:
		return dp(arr, c + 1, n, k - 1, z, ans + arr[c + 1])
	else:
		return max(dp(arr, c + 1, n, k - 1, z, ans + arr[c + 1]), dp(arr, c - 1, n, k - 1, z - 1, ans + arr[c - 1]))
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	orange = list(map(int, stdin.readline().split(' ')))
	candy = list(map(int, stdin.readline().split(' ')))
	min_orange = min(orange)
	min_candy = min(candy)
	ans = 0
	for j in range(n):
		val1 = orange[j] - min_orange
		val2 = candy[j] - min_candy
		if val1 == val2:
			ans += val1
		elif val1 < val2:
			ans += val1 + (val2 - val1)
		else:
			ans += val2 + (val1 - val2)
	print(ans)


n = int(input())
for _ in range(n):
	a = int(input())
	lis = list(map(int, input().split()))
	lis2 = list(map(int, input().split()))
	if a == 1:
		print(0)
	else:
		p = min(lis)
		q = min(lis2)
		s = 0
		for i in range(a):
			s += max(lis[i] - p, lis2[i] - q)
		print(s)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	dia = {}
	c = 0
	for i in range(len(a)):
		if a[i] == ma:
			continue
		else:
			dia[i] = a[i] - ma
			c = c + a[i] - ma
	for i in range(len(b)):
		if b[i] == mb:
			continue
		else:
			t = b[i] - mb
			if i in dia:
				if t <= dia[i]:
					continue
				elif t > dia[i]:
					c = c - dia[i] + t
			else:
				c = c + t
	print(c)


t = int(input())
for T in range(t):
	n = int(input())
	x1 = input()
	a = []
	x2 = input()
	b = []
	a = x1.split(' ')
	b = x2.split(' ')
	for i in range(n):
		a[i] = int(a[i])
		b[i] = int(b[i])
	(m1, m2) = (a[0], b[0])
	(pos1, pos2) = (0, 0)
	for i in range(1, n):
		if a[i] < m1:
			m1 = a[i]
			pos1 = i
		if b[i] < m2:
			m2 = b[i]
			pos2 = i
	ans = 0
	for i in range(n):
		if i != pos1 and i != pos2:
			ans += max(a[i] - m1, b[i] - m2)
			continue
		if i != pos1:
			ans += a[i] - m1
		if i != pos2:
			ans += b[i] - m2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	t1 = min(a)
	t2 = min(b)
	moves = 0
	for i in range(n):
		a1 = a[i] - t1
		b1 = b[i] - t2
		moves = moves + max(a1, b1)
	print(moves)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	min_1 = min(a)
	min_2 = min(b)
	for j in range(n):
		a[j] -= min_1
		b[j] -= min_2
		if a[j] > b[j]:
			ans += b[j]
		else:
			ans += a[j]
		ans += abs(a[j] - b[j])
	print(ans)


testCases = int(input())
while testCases > 0:
	a = int(input())
	candieList = [int(i) for i in input().split()]
	orangeList = [int(i) for i in input().split()]
	cmin = min(candieList)
	omin = min(orangeList)
	tot_count = 0
	for i in range(a):
		diff1 = candieList[i] - cmin
		diff2 = orangeList[i] - omin
		tot_count += max(diff1, diff2)
	print(tot_count)
	testCases -= 1


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = input().split()
	for i in range(0, n):
		a[i] = int(a[i])
	b = input().split()
	for i in range(0, n):
		b[i] = int(b[i])
	m1 = min(a)
	m2 = min(b)
	ans = 0
	for i in range(0, n):
		ob = min(a[i] - m1, b[i] - m2)
		ans += a[i] - m1 - ob + (b[i] - m2)
	print(ans)


t = int(input())
for i in range(1, t + 1):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	k = min(a)
	d = min(b)
	s = 0
	for i in range(n):
		if a[i] - k > b[i] - d:
			s += a[i] - k
		else:
			s += b[i] - d
	print(s)


t = int(input())
for i in range(t):
	n = int(input())
	candies = [int(f) for f in input().split()]
	oranges = [int(g) for g in input().split()]
	minCan = min(candies)
	minOrn = min(oranges)
	count = 0
	for j in range(len(candies)):
		if candies[j] != minCan and oranges[j] != minOrn:
			m = min(candies[j] - minCan, oranges[j] - minOrn)
			candies[j] -= m
			oranges[j] -= m
			count += m
		elif candies[j] == minCan:
			m = oranges[j] - minOrn
			oranges[j] = minOrn
			count += m
		elif oranges[j] == minOrn:
			m = candies[j] - minCan
			candies[j] = minCan
			count += m
	for j in range(len(candies)):
		if candies[j] != minCan:
			count += candies[j] - minCan
			candies[j] = minCan
		if oranges[j] != minOrn:
			count += oranges[j] - minOrn
			oranges[j] = minOrn
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	mna = min(a)
	mnb = min(b)
	cnt = 0
	for i in range(n):
		da = a[i] - mna
		db = b[i] - mnb
		cnt += max(da, db)
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	a = []
	b = []
	s = 0
	for i in range(n):
		a.append(abs(l1[i] - min(l1)))
		b.append(abs(l2[i] - min(l2)))
	for j in range(n):
		s += min(a[j], b[j]) + abs(a[j] - b[j])
	print(s)


def solve(n, a, b):
	(ma, mb) = (min(a), min(b))
	sol = 0
	for i in range(n):
		da = a[i] - ma
		db = b[i] - mb
		sol += max(da, db)
	return sol
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(n, a, b))


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	(*b,) = map(int, input().split())
	(t1, t2) = (min(a), min(b))
	res = 0
	for i in range(n):
		res += max(a[i] - t1, b[i] - t2)
	print(res)


def solve(n, a, b):
	(ma, mb) = (min(a), min(b))
	ans = 0
	for i in range(n):
		(da, db) = (a[i] - ma, b[i] - mb)
		r = min(da, db)
		ans += r + (da - r) + (db - r)
	return ans
t = int(input())
for dum in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = solve(n, a, b)
	print(res)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 1000000007

def value():
	return tuple(map(int, input().split()))

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = array()
	b = array()
	minA = min(a)
	minB = min(b)
	ans = 0
	for i in range(n):
		need1 = a[i] - minA
		need2 = b[i] - minB
		ans += abs(need1 - need2) + min(need2, need1)
	print(ans)


num_cases = int(input())
for x in range(num_cases):
	move_counter = 0
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_candy = min(candies)
	min_orange = min(oranges)
	for gift_num in range(n):
		diff_candies = candies[gift_num] - min_candy
		diff_oranges = oranges[gift_num] - min_orange
		move_counter += max(diff_candies, diff_oranges)
	print(move_counter)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	d = min(b)
	moves = 0
	for i in range(n):
		ab = a[i] - c
		cd = b[i] - d
		if ab > cd:
			ab -= cd
			moves += cd
			moves += ab
		else:
			cd -= ab
			moves += ab
			moves += cd
	print(moves)


for j in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	mi1 = min(b)
	mi2 = min(c)
	tot = 0
	for j in range(len(b)):
		va1 = b[j] - mi1
		va2 = c[j] - mi2
		tot += max(va1, va2)
	print(tot)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = []
	for i in range(n):
		a[i] -= ma
		b[i] -= mb
	for i in range(n):
		if a[i] == b[i]:
			c.append(a[i])
		else:
			c.append(max(a[i], b[i]))
	print(sum(c))


for i in range(int(input())):
	n = int(input())
	lst1 = list(map(int, input().split(' ')))
	lst2 = list(map(int, input().split(' ')))
	a = min(lst1)
	b = min(lst2)
	sum = 0
	for i in range(n):
		sum += max(lst1[i] - a, lst2[i] - b)
	print(sum)


for ii in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(asm, bsm, ans) = (min(a), min(b), 0)
	for jj in range(n):
		ad = a[jj] - asm
		bd = b[jj] - bsm
		ans += max(ad, bd)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mi1 = min(a)
	mi2 = min(b)
	su1 = 0
	for i in range(n):
		su1 += max(a[i] - mi1, b[i] - mi2)
	print(su1)


def check(arrayList1, arrayList2):
	move = 0
	minList1 = min(arrayList1)
	minList2 = min(arrayList2)
	for item in range(0, len(arrayList1)):
		move1 = arrayList1[item] - minList1
		move2 = arrayList2[item] - minList2
		if move1 >= move2:
			move += move1 - move2 + move2
		else:
			move += move2 - move1 + move1
	print(move)
t = int(input())
for i in range(0, t):
	n = int(input())
	lists1 = list((int(num) for num in input().strip().split()))[:n]
	lists2 = list((int(num) for num in input().strip().split()))[:n]
	check(lists1, lists2)


testcases = int(input())
for testcase in range(testcases):
	n = int(input())
	arr1 = []
	arr2 = []
	temparr = input()
	temparr = temparr.split()
	for i in temparr:
		arr1.append(int(i))
	min1 = min(arr1)
	temparr = input()
	temparr = temparr.split()
	for i in temparr:
		arr2.append(int(i))
	min2 = min(arr2)
	total = 0
	for i in range(n):
		cur1 = arr1[i]
		cur2 = arr2[i]
		diff1 = cur1 - min1
		diff2 = cur2 - min2
		total += max(diff1, diff2)
	print(total)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans1 = min(a)
	ans2 = min(b)
	ans3 = min(ans1, ans2)
	ans = 0
	for i in range(n):
		if a[i] == ans1:
			if b[i] == ans2:
				continue
			else:
				ans += b[i] - ans2
		elif a[i] != ans1:
			if b[i] == ans2:
				ans += a[i] - ans1
			else:
				can_do = min(b[i] - ans2, a[i] - ans1)
				a[i] -= can_do
				b[i] -= can_do
				ans += can_do
				if a[i] != ans1:
					ans += a[i] - ans1
				if b[i] != ans2:
					ans += b[i] - ans2
	print(ans)


def solve():
	move = 0
	gifts = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	min_candy = min(candy)
	min_orange = min(orange)
	for g in range(gifts):
		while candy[g] != min_candy or orange[g] != min_orange:
			if candy[g] > min_candy and orange[g] > min_orange:
				c_diff = candy[g] - min_candy
				o_diff = orange[g] - min_orange
				if c_diff > o_diff:
					move += o_diff
					candy[g] -= o_diff
					orange[g] = min_orange
				elif c_diff < o_diff:
					move += c_diff
					candy[g] = min_candy
					orange[g] -= c_diff
				else:
					move += c_diff
					candy[g] = min_candy
					orange[g] = min_orange
			elif candy[g] > min_candy:
				move += candy[g] - min_candy
				candy[g] = min_candy
			elif orange[g] > min_orange:
				move += orange[g] - min_orange
				orange[g] = min_orange
	return move
t = int(input())
k = 0
while k < t:
	print(solve())
	k += 1


def solution(a, b):
	z = min(a)
	y = min(b)
	c = 0
	for i in range(len(a)):
		c += max(a[i] - z, b[i] - y)
	print(c)
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solution(a, b)


def moves(initial, final):
	d1 = initial[0] - final[0]
	d2 = initial[1] - final[1]
	return max(d1, d2)

def orange_candy(n, c, o):
	mnc = min(c)
	mno = min(o)
	final = (mnc, mno)
	total_moves = 0
	for i in range(n):
		total_moves += moves((c[i], o[i]), final)
	return total_moves
t = int(input())
for _ in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	print(orange_candy(n, c, o))


T = int(input())
for I in range(0, T):
	N = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	X = min(A)
	Y = min(B)
	Z = 0
	for I in range(0, N):
		Z += max(A[I] - X, B[I] - Y)
	print(Z)


x = int(input())
li = []
for i in range(x):
	m = int(input())
	ans = 0
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	(x1, x2) = (min(li1), min(li2))
	for j in range(m):
		a1 = li1[j] - x1
		a2 = li2[j] - x2
		ans += max(a1, a2)
	li.append(ans)
for i in range(x):
	print(li[i])


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	aList = list(map(int, input().split()))
	bList = list(map(int, input().split()))
	mina = min(aList)
	minb = min(bList)
	for i in range(n):
		aList[i] -= mina
	for i in range(n):
		bList[i] -= minb
	ans = 0
	for i in range(n):
		if aList[i] == 0:
			if bList[i] == 0:
				pass
			else:
				ans += bList[i]
		elif bList[i] == 0:
			ans += aList[i]
		elif aList[i] > bList[i]:
			diff = aList[i] - bList[i]
			ans += bList[i]
			ans += diff
		else:
			diff = bList[i] - aList[i]
			ans += aList[i]
			ans += diff
	print(ans)


for gg in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	brr = [int(i) for i in input().split()]
	am = min(arr)
	bm = min(brr)
	ans = 0
	for i in range(n):
		ans += max(arr[i] - am, brr[i] - bm)
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	ans = 0
	for i in range(n):
		if a[i] == x and b[i] == y:
			continue
		l1 = a[i] - x
		l2 = b[i] - y
		ans += a[i] - x + b[i] - y
		if a[i] == x or b[i] == y:
			continue
		ans -= min(l1, l2)
	print(ans)


import math

def b(candies, oranges):
	(min_c, min_o) = (math.inf, math.inf)
	for (c, o) in zip(candies, oranges):
		min_c = min(min_c, c)
		min_o = min(min_o, o)
	n_moves = 0
	for (c, o) in zip(candies, oranges):
		c_diff = c - min_c
		o_diff = o - min_o
		a = max(c_diff, o_diff)
		n_moves += a
	return n_moves
for i in range(int(input())):
	input()
	c = [int(e) for e in input().split()]
	o = [int(e) for e in input().split()]
	print(b(c, o))


t = int(input())
ans = []

def solve(a, b, n):
	amin = min(a)
	bmin = min(b)
	for l in range(n):
		a[l] = a[l] - amin
	for l in range(n):
		b[l] = b[l] - bmin
	answer = 0
	for j in range(n):
		answer += max(a[j], b[j])
	return answer
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ans.append(solve(a, b, n))
for a in ans:
	print(a)


test = int(input())
while test:
	fsOne = []
	fsTwo = []
	n = int(input())
	nums1 = list(map(int, input().split()))
	nums2 = list(map(int, input().split()))
	min1 = min(nums1)
	min2 = min(nums2)
	for i in range(n):
		num = abs(nums1[i] - min1)
		fsOne.append(num)
		num = abs(nums2[i] - min2)
		fsTwo.append(num)
	count = 0
	for i in range(n):
		count += max(fsOne[i], fsTwo[i])
	print(count)
	test -= 1


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

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

def stin():
	return input()

def spin():
	return map(int, stin().split())

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

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

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

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

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
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	n = inin()
	a = lin()
	b = lin()
	mina = min(a)
	minb = min(b)
	(da, db, c) = (0, 0, 0)
	for i in range(n):
		da = int(math.fabs(mina - a[i]))
		db = int(math.fabs(minb - b[i]))
		c += max(da, db)
	print(c)


tests = int(input())
for test in range(tests):
	per_round = [0, 0]
	size = input()
	candy = input()
	orange = input()
	candy = candy.split(' ')
	orange = orange.split(' ')
	candies = list(map(int, candy))
	oranges = list(map(int, orange))
	values = zip(candies, oranges)
	min_candy = min(candies)
	min_orange = min(oranges)
	epoch = 0
	for (ele1, ele2) in values:
		if ele1 != min_candy:
			per_round[0] = per_round[0] + ele1 - min_candy
		if ele2 != min_orange:
			per_round[1] = per_round[1] + ele2 - min_orange
		epoch = epoch + max(per_round[0], per_round[1])
		per_round[0] = 0
		per_round[1] = 0
	print(epoch)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr1 = list(map(int, input().split()))
	ma = min(arr)
	mb = min(arr1)
	m = min(ma, mb)
	c = 0
	for i in range(n):
		c += max(arr[i] - ma, arr1[i] - mb)
	print(c)


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	ans = 0
	for (x, y) in zip(a, b):
		mi = min(x - a1, y - b1)
		x -= mi
		y -= mi
		ans += mi + x - a1 + y - b1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	c = 0
	for i in range(n):
		d1 = a[i] - a1
		d2 = b[i] - b1
		c += min(d1, d2) + abs(d1 - d2)
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	min_a = min(a)
	min_b = min(b)
	a = [i - min_a for i in a]
	b = [i - min_b for i in b]
	counter = 0
	for ind in range(len(a)):
		counter += max(a[ind], b[ind])
	print(counter)


import sys, math
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	bm = min(b)
	am = min(a)
	total = 0
	for i in range(n):
		tb = b[i] - bm
		ta = a[i] - am
		total += max(tb, ta)
	print(total)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	moves = 0
	amin = min(a)
	bmin = min(b)
	for j in range(n):
		moves += max(a[j] - amin, b[j] - bmin)
	print(moves)


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	z = min(a)
	y = min(b)
	count = 0
	for i in range(0, len(a)):
		if z == a[i] or y == b[i]:
			if z == a[i]:
				count = count + (b[i] - y)
			else:
				count = count + (a[i] - z)
		elif abs(a[i] - z) < abs(b[i] - y):
			count = count + abs(a[i] - z)
			b[i] = b[i] - abs(a[i] - z)
			count = count + (b[i] - y)
		else:
			count = count + abs(b[i] - y)
			a[i] = a[i] - abs(b[i] - y)
			count = count + (a[i] - z)
	print(count)


for Testcases in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	(res, m1, m2) = (0, min(A), min(B))
	for i in range(n):
		(c1, c2) = (0, 0)
		if A[i] != m1:
			c1 += abs(A[i] - m1)
		if B[i] != m2:
			c2 += abs(B[i] - m2)
		res += max(c1, c2)
	print(res)


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	m_a = min(a)
	m_b = min(b)
	res = 0
	for i in range(n):
		res += max(a[i] - m_a, b[i] - m_b)
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mna = min(a)
	mnb = min(b)
	ans = 0
	for i in range(n):
		ea = a[i] - mna
		eb = b[i] - mnb
		ans += min(ea, eb)
		a[i] -= min(ea, eb)
		b[i] -= min(ea, eb)
		ans += a[i] - mna
		ans += b[i] - mnb
	print(ans)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

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

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

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
from fractions import Fraction
INF = float('inf')
mod = int(1000000000.0) + 7
for t in range(int(data())):
	n = int(data())
	a = mdata()
	b = mdata()
	(a1, b1) = (min(a), min(b))
	ans = 0
	for i in range(n):
		ans += max(a[i] - a1, b[i] - b1)
	print(ans)


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	ans = 0
	for i in range(n):
		k = min(a[i] - am, b[i] - bm)
		ans += k
		a[i] -= k
		b[i] -= k
		ans += a[i] - am
		ans += b[i] - bm
	stdout.write(str(ans) + '\n')


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
for case in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	a_moves = [x - min(a) for x in a]
	b_moves = [x - min(b) for x in b]
	moves = [max(x, y) for (x, y) in zip(a_moves, b_moves)]
	print(sum(moves))


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	mina = min(A)
	minb = min(B)
	ansa = 0
	for i in range(N):
		ansa += max(A[i] - mina, B[i] - minb)
	print(ansa)


t = int(input())
import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))
while t > 0:
	n = int(input())
	a = get_array()
	b = get_array()
	a_min = min(a)
	b_min = min(b)
	count = 0
	for i in range(n):
		increment = max(a[i] - a_min, b[i] - b_min)
		if increment > 0:
			count += increment
	print(count)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	x = min(l)
	x1 = min(l1)
	s = 0
	for i in range(len(l)):
		if l[i] - x == 0:
			s = s + l1[i] - x1
		elif l1[i] - x1 == 0:
			s = s + l[i] - x
		else:
			s = s + max(l[i] - x, l1[i] - x1)
	print(s)


for _ in range(int(input())):
	lens = int(input())
	aarr = [int(x) for x in input().split()]
	barr = [int(x) for x in input().split()]
	mina = min(aarr)
	minb = min(barr)
	answ = sum([max(abs(aarr[i] - mina), abs(barr[i] - minb)) for i in range(lens)])
	print(answ)


for i in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	mina = min(ar)
	minb = min(br)
	sm = 0
	for i in range(n):
		sm += max(ar[i] - mina, br[i] - minb)
	print(sm)


for _ in range(int(input())):
	n = int(input())
	ls1 = list(map(int, input().split()))
	ls2 = list(map(int, input().split()))
	min1 = ls1[0]
	min2 = ls2[0]
	sm = 0
	for i in range(1, n):
		if ls1[i] < min1:
			min1 = ls1[i]
		if ls2[i] < min2:
			min2 = ls2[i]
	for i in range(n):
		df1 = abs(ls1[i] - min1)
		df2 = abs(ls2[i] - min2)
		if df1 == df2:
			sm = sm + df1
		elif df1 > df2:
			sm = sm + (df1 - df2) + df2
		else:
			sm = sm + (df2 - df1) + df1
	print(sm)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	ans = 0
	for i in range(n):
		(cnt1, cnt2) = (a[i] - a1, b[i] - b1)
		ans += max(cnt1, cnt2)
	print(ans)


for i in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	x = min(c)
	y = min(o)
	s = 0
	for i in range(n):
		s += max(c[i] - x, o[i] - y)
	print(s)


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()]
	(minA, minB) = (min(a), min(b))
	result = 0
	for i in range(n):
		result += max(a[i] - minA, b[i] - minB)
	print(result)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	min_a = min(a)
	min_b = min(b)
	count = 0
	for i in range(n):
		t1 = a[i] - min_a
		t2 = b[i] - min_b
		count += max(t1, t2)
	print(count)


import sys
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	n = int(input())
	l1 = L()
	l2 = L()
	m1 = min(l1)
	m2 = min(l2)
	s = 0
	for i in range(n):
		s += max(l1[i] - m1, l2[i] - m2)
	print(s)


def number_of_moves(candies, oranges):
	min_candy = min(candies)
	min_orange = min(oranges)
	moves = 0
	for i in range(len(candies)):
		moves_candy = candies[i] - min_candy
		moves_orange = oranges[i] - min_orange
		moves += max(moves_candy, moves_orange)
	return moves
t = int(input())
for _ in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	assert n == len(candies)
	print(number_of_moves(candies, oranges))


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()]
	(s1, s2) = (10000000001, 10000000001)
	cost = 0
	for i in range(n):
		s1 = min(s1, a[i])
	for i in range(n):
		s2 = min(s2, b[i])
	for i in range(n):
		if a[i] != s1 and b[i] != s2:
			c1 = abs(s1 - a[i])
			c2 = abs(s2 - b[i])
			if c1 == c2:
				cost += c1
			elif c1 > c2:
				cost += c1
			else:
				cost += c2
		elif a[i] == s1 and b[i] != s2:
			c2 = abs(s2 - b[i])
			cost += c2
		elif a[i] != s1 and b[i] == s2:
			c1 = abs(s1 - a[i])
			cost += c1
	print(cost)


tot = int(input().strip())
while tot > 0:
	n = int(input().strip())
	a = [int(x) for x in input().strip().split(' ')]
	b = [int(x) for x in input().strip().split(' ')]
	tot -= 1
	cnt = 0
	ma = min(a)
	mb = min(b)
	for i in range(0, n):
		em = max(a[i] - ma, b[i] - mb)
		cnt += em
	print(cnt)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	c_min = min(c)
	o_min = min(o)
	moves = 0
	for i in range(n):
		c_sum = 0
		o_sum = 0
		c_sum += c[i] - c_min
		o_sum += o[i] - o_min
		moves += max(c_sum, o_sum)
	print(moves)


for I in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mincan = min(a)
	minor = min(b)
	result = 0
	for i in range(n):
		candiff = abs(mincan - a[i])
		ordiff = abs(minor - b[i])
		temp = min(candiff, ordiff)
		temp += max(candiff, ordiff) - temp
		result += temp
	print(result)


for i in range(int(input())):
	le = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	knt = 0
	x = min(l1)
	y = min(l2)
	l1n = [a - x for a in l1]
	l2n = [a - y for a in l2]
	for i in range(le):
		if l1n[i] > 0 and l2n[i] > 0:
			knt += max(l1n[i], l2n[i])
		elif l1n[i] > 0:
			knt += l1n[i]
		else:
			knt += l2n[i]
	print(knt)


for _ in range(int(input())):
	n = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	count = 0
	cmin = min(candy)
	omin = min(orange)
	for i in range(n):
		count += max(abs(candy[i] - cmin), abs(orange[i] - omin))
	print(count)


mod = 10 ** 9 + 7

def solve():
	n = int(input())
	ans = 0
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mn_a = min(a)
	mn_b = min(b)
	for i in range(n):
		ans += max(a[i] - mn_a, b[i] - mn_b)
	print(ans)
t = 1
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	steps = 0
	for j in range(n):
		if a[j] - a1 > b[j] - b1:
			steps += a[j] - a1
		else:
			steps += b[j] - b1
	print(steps)


def gifts(n, a, b):
	k1 = min(a)
	k2 = min(b)
	c = 0
	for i in range(0, n):
		if a[i] != k1 and b[i] != k2:
			res = a[i] - k1
			a[i] -= res
			res1 = b[i] - k2
			b[i] -= res1
			c += max(res, res1)
		elif a[i] != k1:
			res = a[i] - k1
			a[i] -= res
			c += res
		elif b[i] != k2:
			res1 = b[i] - k2
			b[i] -= res1
			c += res1
	return c
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(gifts(n, a, b))


def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	(ans, mna, mnb) = (0, min(a), min(b))
	for i in range(n):
		ans += max(a[i] - mna, b[i] - mnb)
	print(ans)
t = int(input())
while t:
	t -= 1
	solve()


def min_moves(n, a, b):
	if n == 1:
		return 0
	if a == [a[0]] * n and b == [b[0]] * n:
		return 0
	x = min(a)
	y = min(b)
	moves = 0
	for i in range(n):
		t1 = a[i] - x
		t2 = b[i] - y
		moves += max(t1, t2)
	return moves
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(min_moves(n, a, b))


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()]
	ans1 = min(a)
	ans2 = min(b)
	ans = 0
	for e in range(n):
		val1 = a[e] - ans1
		val2 = b[e] - ans2
		ans += max(val1, val2)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	lc = list(map(int, input().split()))
	lo = list(map(int, input().split()))
	mc = min(lc)
	mo = min(lo)
	count = 0
	for j in range(n):
		a = lc[j] - mc
		b = lo[j] - mo
		count += max(a, b)
	print(count)


def main(arr1, arr2):
	min1 = min(arr1)
	min2 = min(arr2)
	count = 0
	for i in range(len(arr1)):
		count += max([arr1[i] - min1, arr2[i] - min2])
	return count
t = int(input())
for p in range(t):
	n = int(input())
	l1 = list(map(int, str(input()).split()))
	l2 = list(map(int, str(input()).split()))
	print(main(l1, l2))


def sol():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	(v1, v2, z, cnt) = (0, 0, 0, 0)
	for i in range(n):
		if a[i] > x and b[i] > y:
			v1 = a[i] - x
			v2 = b[i] - y
			z = min(v1, v2)
			a[i] -= z
			b[i] -= z
			cnt += z
		if a[i] > x:
			v1 = a[i] - x
			a[i] -= v1
			cnt += v1
		if b[i] > y:
			v2 = b[i] - y
			b[i] -= v2
			cnt += v2
	print(cnt)
try:
	for _ in range(int(input())):
		sol()
except:
	pass


test_cases = int(input())
candies_operations = 0
oranges_operations = 0
for _ in range(test_cases):
	gifts = int(input())
	candies = [int(x) for x in input().split()]
	oranges = [int(x) for x in input().split()]
	min_candies = min(candies)
	min_oranges = min(oranges)
	moves = 0
	for i in range(gifts):
		candies_operations = candies[i] - min_candies
		oranges_operations = oranges[i] - min_oranges
		if candies_operations > oranges_operations:
			moves += candies_operations
		elif candies_operations < oranges_operations:
			moves += oranges_operations
		else:
			moves += candies_operations
	print(moves)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import deque
from heapq import heappush, heappop
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
t = ip()
for _ in range(t):
	n = ip()
	a = list(inp())
	b = list(inp())
	ta = min(a)
	tb = min(b)
	a = [i - ta for i in a]
	b = [i - tb for i in b]
	ans = 0
	for i in range(n):
		if a[i] > b[i]:
			ans += b[i]
			a[i] -= b[i]
			b[i] = 0
		else:
			ans += a[i]
			b[i] -= a[i]
			a[i] = 0
	ans += sum(a) + sum(b)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	candy = []
	orange = []
	tt = []
	for j in range(n):
		candy.append(a[j] - ma)
		orange.append(b[j] - mb)
	for j in range(n):
		tt.append(max(candy[j], orange[j]))
	print(sum(tt))


def Steps(a, b):
	steps = 0
	min_a = min(a)
	min_b = min(b)
	for i in range(len(a)):
		eat_a = a[i] - min_a
		eat_b = b[i] - min_b
		steps += max(eat_a, eat_b)
	return steps
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(Steps(a, b))


tc = int(input())
for t in range(tc):
	count = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = list()
	mina = min(a)
	minb = min(b)
	for i in range(n):
		l.append({'c': a[i], 'd': b[i]})
	i = 0
	while i < n:
		if l[i]['c'] > mina and l[i]['d'] > minb:
			count += max(l[i]['c'] - mina, l[i]['d'] - minb)
		elif l[i]['c'] > mina and l[i]['d'] == minb:
			count += l[i]['c'] - mina
		elif l[i]['c'] == mina and l[i]['d'] > minb:
			count += l[i]['d'] - minb
		i += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	moves = 0
	for i in range(n):
		mva = a[i] - mina if a[i] > mina else 0
		mvb = b[i] - minb if b[i] > minb else 0
		mv = min(mva, mvb)
		mv = mv + mva - mv + mvb - mv
		moves += mv
	print(moves)


test = int(input())
for i in range(0, test):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = min(l1)
	m2 = min(l2)
	sum1 = 0
	for j in range(0, n):
		t1 = l1[j] - m1
		t2 = l2[j] - m2
		temp = max(t1, t2)
		sum1 = sum1 + temp
	print(sum1)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	i = 0
	for j in range(n):
		if a[j] - a1 == 1:
			if b[j] - b1 == 1:
				i += 1
			elif b[j] - b1 > 1:
				i = i + b[j] - b1
			elif b[j] == b1:
				i += 1
		elif a[j] == a1:
			if b[j] - b1 > 1:
				i = i + b[j] - b1
			elif b[j] - b1 == 1:
				i += 1
			elif b[j] == b1:
				pass
		elif a[j] - a1 > 1:
			if b[j] == b1:
				i = i + a[j] - a1
			elif b[j] - b1 == 1:
				i = i + a[j] - a1
			elif b[j] - b1 > 1:
				a2 = a[j] - a1
				b2 = b[j] - b1
				if a2 > b2:
					i = i + a2
				elif b2 > a2:
					i = i + b2
				else:
					i = i + b2
	print(i)


t = int(input())
listLAST = []
for i in range(0, t):
	move = 0
	n = int(input())
	list1 = [int(j) for j in input().split(' ')]
	list2 = [int(j) for j in input().split(' ')]
	x1 = min(list1)
	x2 = min(list2)
	for j in range(0, n):
		if list1[j] - x1 > list2[j] - x2:
			move += list1[j] - x1
		elif list2[j] - x2 > list1[j] - x1:
			move += list2[j] - x2
		elif list1[j] == x1 and list2[j] > x2:
			move += list2[j] - x2
		elif list2[j] == x2 and list1[j] > x1:
			move += list1[j] - x1
		elif list1[j] - x1 == list2[j] - x2:
			move += list1[j] - x1
	listLAST.append(move)
	list1.clear()
	list2.clear()
for i in listLAST:
	print(i)


t = int(input())
for x in range(t):
	n = int(input())
	ar1 = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	min1 = min(ar1)
	min2 = min(ar2)
	ans = 0
	for i in range(n):
		mx = max(ar1[i] - min1, ar2[i] - min2)
		ans += mx
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	ma = min(a)
	mb = min(b)
	for i in range(n):
		a[i] = a[i] - ma
		b[i] = b[i] - mb
	cnt = 0
	for i in range(n):
		if b[i] == 0 and a[i] == 0:
			pass
		elif b[i] == 0 and a[i] != 0:
			cnt += a[i]
		elif a[i] == 0 and b[i] != 0:
			cnt += b[i]
		else:
			x = min(a[i], b[i])
			cnt += x
			a[i] = a[i] - x
			b[i] = b[i] - x
			cnt += b[i] + a[i]
	print(cnt)


def sovle(a, b):
	mina = min(a)
	minb = min(b)
	rslt = 0
	for i in range(len(a)):
		rslt += min(a[i] - mina, b[i] - minb) + abs(a[i] - mina - b[i] + minb)
	return rslt
t = int(input())
while t:
	n = input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(sovle(a, b))
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(el) for el in input().split()]
	b = [int(el) for el in input().split()]
	mina = min(a)
	minb = min(b)
	k = 0
	for i in range(n):
		k += max(a[i] - mina, b[i] - minb)
	print(k)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		min_a = min(a)
		min_b = min(b)
		tot = 0
		for i in range(n):
			red_a = a[i] - min_a
			red_b = b[i] - min_b
			tot += min(red_a, red_b) + abs(red_a - red_b)
		print(tot)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	smx = min(x)
	smy = min(y)
	steps = sum(x) + sum(y) - smx * len(x) - smy * len(y)
	for i in range(n):
		if x[i] != smx and y[i] != smy:
			if x[i] - smx < y[i] - smy:
				steps -= x[i] - smx
			else:
				steps -= y[i] - smy
	print(steps)


cases = int(input())
for i in range(cases):
	n = int(input())
	candy = input().split(' ')
	orange = input().split(' ')
	arrc = []
	arro = []
	for a in candy:
		arrc.append(int(a))
	for b in orange:
		arro.append(int(b))
	moves = 0
	mic = min(arrc)
	mio = min(arro)
	for j in range(n):
		candy = arrc[j]
		orange = arro[j]
		if candy > mic and orange > mio:
			d1 = candy - mic
			d2 = orange - mio
			moves += max(d1, d2)
		elif candy > mic:
			moves += candy - mic
		elif orange > mio:
			moves += orange - mio
	print(moves)


t = input()
t = int(t)
for i in range(t):
	n = input()
	n = int(n)
	arr = list(map(int, input().rstrip().split()))
	brr = list(map(int, input().rstrip().split()))
	a = min(arr)
	b = min(brr)
	count = 0
	for i in range(n):
		s = abs(arr[i] - a)
		c = abs(brr[i] - b)
		d = max(s, c)
		count = count + d
	print(count)


t = int(input())
from math import *
from sys import *
from math import *

def f(arr, k, x):
	count = 0
	for il in arr:
		count += il // x
	if count >= k:
		return True
	else:
		return False
for ip in range(t):
	n = int(input())
	brr = [int(x) for x in input().strip().split()]
	arr = [int(x) for x in input().strip().split()]
	tx = min(brr)
	tq = min(arr)
	count = 0
	for il in range(n):
		count += max(arr[il] - tq, brr[il] - tx)
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	x = min(A)
	y = min(B)
	for i in range(len(A)):
		A[i] -= x
		B[i] -= y
	res = 0
	for i in range(len(A)):
		res += max(A[i], B[i])
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(za, zb) = (min(a), min(b))
	for i in range(n):
		a[i] -= za
		b[i] -= zb
	c = 0
	for i in range(n):
		c += abs(a[i] - b[i])
		c += min(a[i], b[i])
	print(c)


from sys import stdin, exit, setrecursionlimit
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()
for _ in range(int(input())):
	n = int(input())
	a = lmi()
	b = lmi()
	x = min(a)
	y = min(b)
	ans = 0
	for i in range(n):
		tmp = min(a[i] - x, b[i] - y)
		tmp2 = max(a[i] - x, b[i] - y) - tmp
		ans += tmp + tmp2
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	Amin = min(A)
	Bmin = min(B)
	res = 0
	for i in range(n):
		res += max(A[i] - Amin, B[i] - Bmin)
	print(res)


def solve(c, o, n):
	c_min = min(c)
	o_min = min(o)
	count = 0
	for i in range(n):
		count += max(c[i] - c_min, o[i] - o_min)
	print(count)
for _ in range(int(input())):
	n = int(input())
	candies = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	solve(candies, orange, n)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ai = min(a)
	bi = min(b)
	cnt = 0
	for i in range(n):
		cnt += max(b[i] - bi, a[i] - ai)
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	a = list((int(num) for num in input().split()))
	b = list((int(num) for num in input().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for z in range(n):
		if a[z] > amin and b[z] > bmin:
			ans += max(a[z] - amin, b[z] - bmin)
		elif a[z] > amin:
			ans += a[z] - amin
		elif b[z] > bmin:
			ans += b[z] - bmin
	print(ans)


t = int(input())
while t:
	n = int(input())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		ans += max(a1[i] - min(a1), b1[i] - min(b1))
	print(ans)
	t -= 1


Q = int(input())
for q in range(Q):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	minA = min(A)
	minB = min(B)
	AA = []
	for i in range(N):
		AA.append(A[i] - minA)
	BB = []
	for i in range(N):
		BB.append(B[i] - minB)
	ans = 0
	for i in range(N):
		ans += max(AA[i], BB[i])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	al = list(map(int, input().split()))
	bl = list(map(int, input().split()))
	ma = min(al)
	mb = min(bl)
	s = 0
	for i in range(n):
		s += max(abs(al[i] - ma), bl[i] - mb)
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	ans = 0
	for i in range(0, n):
		ta = a[i] - ma
		tb = b[i] - mb
		ans += max(ta, tb)
	print(ans)


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n == 1:
		print(0)
	else:
		am = min(a)
		bm = min(b)
		cnt = 0
		for i in range(n):
			if a[i] == am and b[i] == bm:
				cnt = cnt + 0
			elif a[i] > am and b[i] > bm:
				p = a[i] - am
				q = b[i] - bm
				cnt = cnt + max(p, q)
			elif a[i] == am and b[i] > bm:
				cnt = cnt + (b[i] - bm)
			elif a[i] > am and b[i] == bm:
				cnt = cnt + (a[i] - am)
		print(cnt)


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 = min(a)
	B = min(b)
	mov = 0
	for i in range(n):
		d1 = a[i] - A
		d2 = b[i] - B
		if d1 >= d2:
			mov += d1
		else:
			mov += d2
	print(mov)
pass


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = a[0]
	mb = b[0]
	ans = 0
	for i in a:
		ma = min(ma, i)
	for i in b:
		mb = min(mb, i)
	for i in range(n):
		ad = a[i] - ma
		bd = b[i] - mb
		ans += max(ad, bd)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aa = min(a)
	bb = min(b)
	ans = 0
	for i in range(n):
		if a[i] > aa and b[i] > bb:
			pp = min(a[i] - aa, b[i] - bb)
			ans += pp
			a[i] -= pp
			b[i] -= pp
		if a[i] > aa:
			ans += a[i] - aa
			a[i] = aa
		if b[i] > bb:
			ans += b[i] - bb
			b[i] = bb
	print(ans)


t = int(input())
while t != 0:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	sum = 0
	for i in range(n):
		sum = sum + max(a[i] - a1, b[i] - b1)
	print(sum)


t = int(input())
d = {}
for i in range(t):
	n = int(input())
	konf = str(input()).split(' ')
	k = []
	for j in range(len(konf)):
		k.append(int(konf[j]))
	min_k = min(k)
	ap = str(input()).split(' ')
	a = []
	for j in range(len(ap)):
		a.append(int(ap[j]))
	min_a = min(a)
	d[i] = (k, a, min_k, min_a)
for key in d.keys():
	step = 0
	for i in range(len(d[key][0])):
		while d[key][0][i] + d[key][1][i] > d[key][2] + d[key][3] or d[key][0][i] > d[key][2] or d[key][1][i] > d[key][3]:
			if d[key][0][i] + d[key][1][i] > d[key][2] + d[key][3] and d[key][0][i] > d[key][2] and (d[key][1][i] > d[key][3]):
				r1 = d[key][0][i] - d[key][2]
				r2 = d[key][1][i] - d[key][3]
				step += max(r1, r2)
				d[key][0][i] = d[key][2]
				d[key][1][i] = d[key][3]
			if d[key][0][i] + d[key][1][i] > d[key][2] + d[key][3] and d[key][0][i] > d[key][2] and (d[key][1][i] == d[key][3]):
				step += d[key][0][i] - d[key][2]
				d[key][0][i] = d[key][2]
			if d[key][0][i] + d[key][1][i] > d[key][2] + d[key][3] and d[key][0][i] == d[key][2] and (d[key][1][i] > d[key][3]):
				step += d[key][1][i] - d[key][3]
				d[key][1][i] = d[key][3]
	print(step)


for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	mina = min(a)
	minb = min(b)
	ans = 0
	for x in range(n):
		if a[x] != mina and b[x] != minb:
			ans += max(a[x] - mina, b[x] - minb)
		elif a[x] != mina and b[x] == minb:
			ans += a[x] - mina
		elif a[x] == mina and b[x] != minb:
			ans += b[x] - minb
	print(ans)


n = int(input())
while n:
	m = int(input())
	(l1, l2) = ([], [])
	l1 = input().split(' ')
	l2 = input().split(' ')
	l1 = [int(i) for i in l1]
	l2 = [int(i) for i in l2]
	c = 0
	for j in range(0, len(l1)):
		c = c + max(l1[j] - min(l1), l2[j] - min(l2))
	print(c)
	n = n - 1


t = int(input())
while t > 0:
	n = int(input())
	c = list(map(int, input().split()))
	mc = min(c)
	o = list(map(int, input().split()))
	mo = min(o)
	moves = 0
	for i in range(n):
		dc = c[i] - mc
		do = o[i] - mo
		d = max(dc - (dc - do), do - (do - dc))
		moves += d
		dc -= d
		do -= d
		if dc > 0:
			moves += dc
		elif do > 0:
			moves += do
	print(moves)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(mina, minb) = (min(a), min(b))
	moves = 0
	for i in range(n):
		if min(a[i] - mina, b[i] - minb) == a[i] - mina:
			x = a[i] - mina
			y = b[i] - minb
			moves += x + (y - x)
		else:
			x = b[i] - minb
			y = a[i] - mina
			moves += x + (y - x)
	print(moves)


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()]
	mina = min(a)
	minb = min(b)
	c = 0
	if max(a) == mina and max(b) == minb:
		print(0)
	else:
		for i in range(n):
			c += max(a[i] - mina, b[i] - minb)
		print(c)


t = int(input())
count = 0
for _ in range(t):
	listofnum = list()
	n = int(input())
	inp_1 = [int(element) for element in input().split(' ')]
	inp_2 = [int(element) for element in input().split(' ')]
	inp_1_min = min(inp_1)
	inp_2_min = min(inp_2)
	for index in range(n):
		diff_from_min_1 = inp_1[index] - inp_1_min
		diff_from_min_2 = inp_2[index] - inp_2_min
		count += min([diff_from_min_1, diff_from_min_2]) + abs(diff_from_min_2 - diff_from_min_1)
	print(count)
	count = 0


t = int(input())
for i in range(t):
	n = int(input())
	candy = [int(i) for i in input().split()]
	orange = [int(i) for i in input().split()]
	minCandy = min(candy)
	minOrange = min(orange)
	count = 0
	for i in range(n):
		o = 0
		c = 0
		if candy[i] > minCandy:
			o = candy[i] - minCandy
		if orange[i] > minOrange:
			c = orange[i] - minOrange
		if c >= o:
			count = count + c
		else:
			count = count + o
	print(count)


t = int(input())
for _ in range(t):
	size = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	minCandy = min(candies)
	minOranges = min(oranges)
	moves = 0
	for i in range(size):
		diffCandy = candies[i] - minCandy
		diffOranges = oranges[i] - minOranges
		moves += max(diffCandy, diffOranges)
	print(moves)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(x1, y1) = (min(a), min(b))
	p = 0
	for i in range(n):
		p += max(a[i] - x1, b[i] - y1)
	print(p)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(a1, b1) = ([], [])
	x = min(a)
	y = min(b)
	for i in range(n):
		a1.append(a[i] - x)
		b1.append(b[i] - y)
	s = 0
	for i in range(n):
		s = s + max(a1[i], b1[i])
	print(s)


t = int(input())
for k in range(0, t):
	n = int(input())
	a = input()
	b = input()
	a = a.split()
	b = b.split()
	for i in range(0, n):
		a[i] = int(a[i])
		b[i] = int(b[i])
	c = min(a)
	d = min(b)
	count = 0
	for i in range(0, n):
		count = count + max(a[i] - c, b[i] - d)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 0
	h = 0
	c = []
	d = []
	c = sorted(a)
	d = sorted(b)
	p = c[0]
	q = d[0]
	for i in range(n):
		s = max(a[i] - p, b[i] - q)
		h = s + h
	print(h)


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) == n
	assert len(B) == n
	a_min = min(A)
	b_min = min(B)
	cnts = 0
	for (x, y) in zip(A, B):
		cnts += max(x - a_min, y - b_min)
	print(cnts)


n = int(input())
result = []
for i in range(n):
	moves = 0
	leng = int(input())
	oranges = list(map(int, input().split()))
	candies = list(map(int, input().split()))
	minimo_orange = min(oranges)
	minimo_candies = min(candies)
	for i in range(leng):
		while oranges[i] > minimo_orange and candies[i] > minimo_candies:
			oranges_dif = abs(min(oranges) - oranges[i])
			candies_dif = abs(min(candies) - candies[i])
			if oranges_dif > candies_dif:
				jogadas = candies_dif
			elif oranges_dif < candies_dif:
				jogadas = oranges_dif
			else:
				jogadas = oranges_dif
			oranges[i] -= jogadas
			candies[i] -= jogadas
			moves += jogadas
		while oranges[i] > minimo_orange:
			jogadas = abs(min(oranges) - oranges[i])
			oranges[i] -= jogadas
			moves += jogadas
		while candies[i] > minimo_candies:
			jogadas = abs(min(candies) - candies[i])
			candies[i] -= jogadas
			moves += jogadas
	result.append(moves)
for i in result:
	print(i)


ct = int(input())
while ct > 0:
	ct -= 1
	res = 0
	len = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = sorted(a)[0]
	y = sorted(b)[0]
	for i in range(len):
		res += max(a[i] - x, b[i] - y)
	print(res)


def solve(A, B, N):
	mna = min(A)
	mnb = min(B)
	cnt = 0
	for (i, j) in zip(A, B):
		cnt += max(i - mna, j - mnb)
	return cnt
t = int(input())
for i in range(t):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = solve(A, B, N)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	c = 0
	for i in range(n):
		t1 = a[i] - amin
		t2 = b[i] - bmin
		c += max(t1, t2)
	print(c)


t = int(input())
while t:
	n = int(input())
	al = list(map(int, input().split()))
	bl = list(map(int, input().split()))
	a = min(al)
	count = 0
	b = min(bl)
	for i in range(len(al)):
		if al[i] - a > bl[i] - b:
			count += al[i] - a
		else:
			count += bl[i] - b
	print(count)
	t = t - 1


t = int(input())
for _ in range(t):
	input()
	ls_a = list(map(int, input().split()))
	ls_b = list(map(int, input().split()))
	min_a = min(ls_a)
	min_b = min(ls_b)
	sum_ = 0
	for (a, b) in zip(ls_a, ls_b):
		sum_ += max(a - min_a, b - min_b)
	print(sum_)


t = int(input())
for i in range(t):
	ans = 0
	s = int(input())
	arrc = list(map(int, input().split()))
	arro = list(map(int, input().split()))
	minc = min(arrc)
	mino = min(arro)
	for j in range(s):
		a = abs(arrc[j] - minc)
		b = abs(arro[j] - mino)
		ans += max(a, b)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	x = min(a)
	y = min(b)
	count = 0
	for i in range(n):
		if a[i] == x:
			if b[i] == y:
				continue
			else:
				count += b[i] - y
		elif b[i] == y:
			if a[i] == x:
				continue
			else:
				count += a[i] - x
		else:
			l = a[i] - x
			m = b[i] - y
			count += max(l, m)
	print(count)


def ques1(n, a, b):
	count = 0
	mina = min(a)
	minb = min(b)
	for i in range(n):
		if a[i] > mina and b[i] > minb:
			k = max(b[i] - minb, a[i] - mina)
			count += k
		elif a[i] > mina:
			count += a[i] - mina
		elif b[i] > minb:
			count += b[i] - min(b)
	print(count)
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()]
	ans = ques1(n, a, b)
	ans


t = int(input())
for i in range(t):
	n = int(input())
	d1 = list(map(int, input().split()))
	d2 = list(map(int, input().split()))
	m1 = min(d1)
	m2 = min(d2)
	answer = 0
	for j in range(len(d1)):
		answer += max(d1[j] - m1, d2[j] - m2)
	print(answer)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minA = min(a)
	minB = min(b)
	ct = 0
	for i in range(n):
		if a[i] > minA and b[i] > minB:
			if a[i] < b[i]:
				k = a[i] - minA
				a[i] -= k
				b[i] -= k
				ct += k
			else:
				k = b[i] - minB
				a[i] -= k
				b[i] -= k
				ct += k
		if a[i] > minA:
			ct += a[i] - minA
		if b[i] > minB:
			ct += b[i] - minB
	print(ct)


t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sum = 0
	for j in range(0, n):
		sum = sum + (a[j] - min(a)) + (b[j] - min(b))
		if a[j] > min(a) and b[j] > min(b):
			sum = sum - min(a[j] - min(a), b[j] - min(b))
	print(sum)


def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		b = li()
		mina = min(a)
		minb = min(b)
		moves = 0
		for (i, j) in zip(a, b):
			tempa = i - mina
			tempb = j - minb
			if tempa == 0 or tempb == 0:
				moves += abs(tempa - tempb)
			else:
				moves += max(tempa, tempb)
		print(moves)
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
solve()


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = min(a)
	d = min(b)
	s = 0
	for (i, j) in zip(a, b):
		i -= c
		j -= d
		s += max(i, j)
	print(s)
	t -= 1


import sys
from sys import stdin
import math

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

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

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

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

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

def flinput():
	return list(map(int, stdin.readline().strip().split()))
for _ in range(fiinput()):
	n = fiinput()
	list1 = flinput()
	list2 = flinput()
	m1 = min(list1)
	m2 = min(list2)
	c = 0
	for i in range(n):
		list1[i] -= m1
		list2[i] -= m2
		if list1[i] == list2[i]:
			c += list1[i]
		else:
			c += min(list1[i], list2[i])
			c += abs(list1[i] - list2[i])
	print(c)


t = int(input())
while t:
	n = int(input())
	a1 = list(map(int, input().split()))
	b1 = list(map(int, input().split()))
	mina = min(a1)
	minb = min(b1)
	i = 0
	count = 0
	for i in range(n):
		if a1[i] != mina and b1[i] != minb:
			minimum = min(a1[i] - mina, b1[i] - minb)
			count += minimum
			maximum = max(a1[i] - mina, b1[i] - minb)
			count += abs(maximum - minimum)
		elif a1[i] == mina and b1[i] != minb:
			count += b1[i] - minb
		elif a1[i] != mina and b1[i] == minb:
			count += a1[i] - mina
	print(count)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	r = 0
	s = input().split()
	k = 0
	mk = 1000000001
	for i in range(n):
		s[i] = int(s[i])
		if s[i] < mk:
			mk = s[i]
			k = i
	z = input().split()
	q = 0
	aq = 1000000001
	for i in range(n):
		z[i] = int(z[i])
		if z[i] < aq:
			aq = z[i]
			q = i
	for i in range(n):
		if s[i] > mk and z[i] > aq:
			r1 = s[i] - mk
			r2 = z[i] - aq
			r += max(r1, r2)
		elif s[i] > mk:
			r += s[i] - mk
		elif z[i] > aq:
			r += z[i] - aq
	print(r)


t = int(input(''))
for i in range(t):
	n = int(input(''))
	a = list(map(int, input('').split()))
	b = list(map(int, input('').split()))
	steps = 0
	amin = min(a)
	bmin = min(b)
	for i in range(n):
		da = a[i] - amin
		db = b[i] - bmin
		steps += max(da, db)
	print(steps)


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()]
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		temp = min(a[i] - mina, b[i] - minb)
		a[i] -= mina + temp
		b[i] -= minb + temp
		ans += temp + a[i] + b[i]
	print(ans)


import math
import sys
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 = inp()
for t in range(T):
	N = inp()
	A = inlt()
	B = inlt()
	a = min(A)
	b = min(B)
	out = 0
	for n in range(N):
		d1 = A[n] - a
		d2 = B[n] - b
		out += max(d1, d2)
	print(out)


for _ in range(int(input())):
	n = int(input())
	k = 0
	p = list(map(int, input().split()))
	q = list(map(int, input().split()))
	min1 = min(p)
	min2 = min(q)
	p = [i - min1 for i in p]
	q = [i - min2 for i in q]
	for i in range(n):
		k = k + max(p[i], q[i])
	print(k)


def max(a, b):
	if a > b:
		return a
	else:
		return b
t = int(input())
while t > 0:
	n = int(input())
	c = list(map(int, input().strip().split()))
	o = list(map(int, input().strip().split()))
	cl = c[0]
	ol = o[0]
	for i in range(1, len(c)):
		if c[i] < cl:
			cl = c[i]
			ci = i
		if o[i] < ol:
			ol = o[i]
			oi = i
	count = 0
	for i in range(len(c)):
		if c[i] > cl and o[i] > ol:
			count += max(c[i] - cl, o[i] - ol)
		elif c[i] > cl:
			count += c[i] - cl
		elif o[i] > ol:
			count += o[i] - ol
		else:
			continue
	print(count)
	t -= 1


def solve(n, arr1, arr2):
	min1 = min(arr1)
	min2 = min(arr2)
	res = 0
	for i in range(n):
		op1 = arr1[i] - min1
		op2 = arr2[i] - min2
		res += max(op1, op2)
	print(res)
t = int(input())
for i in range(0, t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	solve(n, arr1, arr2)


def main():
	for _ in range(int(input())):
		n = int(input())
		candy = list(map(int, input().split()))
		orange = list(map(int, input().split()))
		min_candy = min(candy)
		min_orange = min(orange)
		c = []
		o = []
		for i in candy:
			dc = i - min_candy
			c.append(dc)
		for j in orange:
			do = j - min_orange
			o.append(do)
		tup = list(zip(c, o))
		sum = 0
		for x in tup:
			sum = sum + max(x)
		print(sum)
main()


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()]
	am = min(a)
	bm = min(b)
	r = 0
	for i in range(n):
		r += max(a[i] - am, b[i] - bm)
	print(r)


import sys
import os.path
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
	sys.stdout = open('out.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	am = min(a)
	b = list(map(int, input().split()))
	bm = min(b)
	ans = 0
	for i in range(n):
		if a[i] != am:
			if b[i] != bm:
				ans += min(b[i] - bm, a[i] - am)
				ans += max(a[i] - am - min(b[i] - bm, a[i] - am), b[i] - bm - min(b[i] - bm, a[i] - am))
			else:
				ans += a[i] - am
		elif b[i] != bm:
			ans += b[i] - bm
	print(ans)


test_case = int(input())
for i in range(test_case):
	n = int(input())
	arr1 = list(map(int, input().split(' ')))
	arr2 = list(map(int, input().split(' ')))
	a = min(arr1)
	b = min(arr2)
	res = 0
	for j in range(n):
		if arr1[j] > a and arr2[j] > b:
			x = abs(arr1[j] - a)
			y = abs(arr2[j] - b)
			if x == y:
				res += x
				arr1[j] = a
				arr2[j] = b
			else:
				z = min(x, y)
				res += z
				arr1[j] = arr1[j] - z
				arr2[j] = arr2[j] - z
		if arr1[j] > a:
			x = arr1[j] - a
			res += x
			arr1[j] = a
		if arr1[j] == a:
			x = arr2[j] - b
			res += x
			arr2[j] = b
	print(res)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math

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

def stringListIn():
	return [x for x in stdin.readline().split()]

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

def stringIn():
	return stdin.readline().strip()
t = intIn()
while t > 0:
	t -= 1
	n = intIn()
	a = listIn()
	b = listIn()
	(m1, m2) = (min(a), min(b))
	ans = 0
	for i in range(n):
		(ai, bi) = (a[i], b[i])
		(d1, d2) = (a[i] - m1, b[i] - m2)
		ans += max(d1, d2)
	print(ans)


for _ in range(int(input())):
	a = int(input())
	n = list(map(int, input().split()))
	m = list(map(int, input().split()))
	x = min(n)
	y = min(m)
	s = len(n)
	ans = 0
	for i in range(s):
		ans += max(n[i] - x, m[i] - y)
	print(ans)


def f():
	int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	am = min(a)
	bm = min(b)
	print(sum([max(a[i] - am, b[i] - bm) for i in range(len(a))]))
n = int(input())
for _ in range(n):
	f()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ami = a[0]
	bmi = b[0]
	for i in range(n):
		ami = min(a[i], ami)
		bmi = min(b[i], bmi)
	ans = 0
	for i in range(n):
		amove = a[i] - ami
		bmove = b[i] - bmi
		ans += max(amove, bmove)
	print(ans)


import sys
DEBUG = False
if DEBUG:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = int(input().strip())
	a = [int(i) for i in input().rstrip().split()]
	b = [int(i) for i in input().rstrip().split()]
	minA = min(a)
	minB = min(b)
	ans = 0
	for i in range(n):
		d1 = a[i] - minA
		d2 = b[i] - minB
		ans = ans + max(d1, d2)
	print(ans)

def main():
	tc = int(input().strip())
	for case in range(tc):
		solve()
main()


t = int(input())
for i in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	total = 0
	for j in range(n):
		diff1 = candies[j] - min(candies)
		diff2 = oranges[j] - min(oranges)
		if diff1 < diff2:
			total += diff1 + diff2 - diff1
		else:
			total += diff2 + diff1 - diff2
	print(total)


from sys import stdin, stdout
tt = int(stdin.readline().strip())
for _ in range(tt):
	n = int(stdin.readline().strip())
	arr = list(map(int, stdin.readline().strip().split()))
	arr2 = list(map(int, stdin.readline().strip().split()))
	min_1 = min(arr)
	min_2 = min(arr2)
	ans = 0
	for i in range(n):
		ans += arr[i] - min_1 + (arr2[i] - min_2) - min(arr[i] - min_1, arr2[i] - min_2)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	tar_a = min(a)
	tar_b = min(b)
	moves = 0
	for i in range(n):
		moves += max(a[i] - tar_a, b[i] - tar_b)
	print(moves)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	move = 0
	for i in range(n):
		if a[i] > a1 and b[i] > b1:
			x = min(a[i] - a1, b[i] - b1)
			a[i] -= x
			b[i] -= x
			move += x
		if a[i] > a1:
			move += a[i] - a1
		if b[i] > b1:
			move += b[i] - b1
	print(move)
	t -= 1


def func(a, b, l):
	ia = min(a)
	ib = min(b)
	for i in range(l):
		a[i] -= ia
		b[i] -= ib
	count = 0
	for j in range(l):
		count += max(a[j], b[j])
	print(count)
tc = int(input())
for i in range(tc):
	l = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	result = func(a, b, l)


for x in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	(i, count) = (0, 0)
	while i < n:
		if a[i] == amin:
			count = b[i] - bmin + count
		elif b[i] == bmin:
			count = a[i] - amin + count
		else:
			c = min(a[i] - amin, b[i] - bmin)
			d = min(a[i], b[i])
			if d == b[i]:
				count = count + b[i] - bmin
				a[i] = a[i] - c
				if a[i] != amin:
					count = count + a[i] - amin
			elif d == a[i]:
				count = count + a[i] - amin
				b[i] = b[i] - c
				if b[i] != amin:
					count = count + b[i] - bmin
		i += 1
	print(count)


while True:
	try:
		for _ in range(int(input())):
			n = int(input())
			a = list(map(int, input().split()))
			b = list(map(int, input().split()))
			mna = min(a)
			mnb = min(b)
			ans = 0
			for i in range(n):
				xa = a[i] - mna
				xb = b[i] - mnb
				mnx = min(xa, xb)
				ans += mnx
				xa -= mnx
				xb -= mnx
				ans += xa + xb
			print(ans)
	except:
		break


t = int(input())
for o in range(0, t):
	n = int(input())
	arr1 = list(map(int, input().split(' ')))
	arr2 = list(map(int, input().split(' ')))
	arr1_min = min(arr1)
	arr2_min = min(arr2)
	moves = 0
	for i in range(0, n):
		arr1_dec_value = arr1[i] - arr1_min
		arr2_dec_value = arr2[i] - arr2_min
		if arr1_dec_value < arr2_dec_value:
			moves += arr2_dec_value
		else:
			moves += arr1_dec_value
	print(moves)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	ans = 0
	for i in range(n):
		tmp = min(a[i] - min_a, b[i] - min_b)
		ans += tmp
		a[i] -= tmp
		b[i] -= tmp
		ans += a[i] - min_a
		ans += b[i] - min_b
	print(ans)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	diff1 = min(a)
	diff2 = min(b)
	temp1 = [0] * n
	temp2 = [0] * n
	for i in range(n):
		temp1[i] = abs(diff1 - a[i])
		temp2[i] = abs(diff2 - b[i])
	ans = 0
	for i in range(n):
		ans += min(temp1[i], temp2[i])
		ans += abs(temp1[i] - temp2[i])
	print(ans)


import math

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = [int(n) for n in input().split()]
		b = [int(n) for n in input().split()]
		mina = min(a)
		minb = min(b)
		ans = 0
		for j in range(n):
			t1 = a[j] - mina
			t2 = b[j] - minb
			t3 = min(t1, t2)
			a[j] -= t3
			b[j] -= t3
			ans += t3
		for j in range(n):
			ans = ans + a[j] - mina + b[j] - minb
		print(ans)
main()


t = int(input())
for i in range(t):
	n = int(input())
	res = 0
	candies = list(map(int, input().split(' ')))
	oranges = list(map(int, input().split(' ')))
	res_candy = min(candies)
	res_orange = min(oranges)
	for j in range(n):
		temp1 = candies[j] - res_candy
		temp2 = oranges[j] - res_orange
		res += max(temp1, temp2)
	print(res)


for _ in range(int(input())):
	x = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mnA = min(a)
	mnB = min(b)
	sum = 0
	for i in range(x):
		sum += max(a[i] - mnA, b[i] - mnB)
	print(sum)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amn = min(a)
	bmn = min(b)
	ans = 0
	for i in range(n):
		ans += a[i] - amn + (b[i] - bmn) - min(a[i] - amn, b[i] - bmn)
	print(ans)


def main():
	t = int(input())
	for i in range(t):
		count = 0
		n = int(input())
		orange = list(map(int, input().split()))
		candy = list(map(int, input().split()))
		minO = min(orange)
		minC = min(candy)
		for i in range(n):
			oi = orange[i]
			ci = candy[i]
			if oi == minO and ci == minC:
				continue
			if oi > minO and ci > minC:
				moc = min(oi - minO, ci - minC)
				oi -= moc
				ci -= moc
				count += moc
			if oi > minO:
				count += oi - minO
				oi -= oi - minO
			if ci > minC:
				count += ci - minC
				ci -= ci - minC
		print(count)
main()


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	(ans, c, x1, x2) = (0, 0, min(a), min(b))
	if len(set(a)) == 1 and len(set(b)) == 1:
		print('0')
		continue
	for (i, j) in zip(a, b):
		(t1, t2) = (i, j)
		if t1 > x1 and t2 > x2:
			c += min(i - x1, j - x2)
		ans += i - x1 + j - x2
	print(ans - c)


t = int(input())
nLst = []
(candies, oranges) = ([], [])
for z in range(t):
	ni = int(input())
	nLst.append(ni)
	candies_i = []
	candies_i = input().split()
	for x in range(ni):
		candies_i[x] = int(candies_i[x])
	oranges_i = []
	oranges_i = input().split()
	for y in range(ni):
		oranges_i[y] = int(oranges_i[y])
	candies.append(candies_i)
	oranges.append(oranges_i)
for i in range(t):
	moves = 0
	min_c = min(candies[i])
	min_o = min(oranges[i])
	if max(candies[i]) == min(candies[i]) and max(oranges[i]) == min(oranges[i]):
		moves = 0
		print(moves)
		continue
	elif max(candies[i]) != min(candies[i]) and max(oranges[i]) != min(oranges[i]):
		for j in range(nLst[i]):
			if candies[i][j] > min_c and oranges[i][j] > min_o:
				change = min(candies[i][j] - min_c, oranges[i][j] - min_o)
				moves += change
				candies[i][j] -= change
				oranges[i][j] -= change
				if candies[i][j] - min_c > 0:
					tmpChange = candies[i][j] - min_c
					moves += tmpChange
					candies[i][j] -= tmpChange
				if oranges[i][j] - min_o > 0:
					tmpChange = oranges[i][j] - min_o
					moves += tmpChange
					oranges[i][j] -= tmpChange
			else:
				tmpDelta = candies[i][j] - min_c
				moves += tmpDelta
				candies[i][j] -= tmpDelta
				tmpDelta = oranges[i][j] - min_o
				moves += tmpDelta
				oranges[i][j] -= tmpDelta
	elif max(oranges[i]) != min(oranges[i]) and max(candies[i]) == min(candies[i]):
		for j in range(nLst[i]):
			tmpDel = oranges[i][j] - min_o
			moves += tmpDel
			oranges[i][j] -= tmpDel
	elif max(candies[i]) != min(candies[i]) and max(oranges[i]) == min(oranges[i]):
		for j in range(nLst[i]):
			tmpD = candies[i][j] - min_c
			moves += tmpD
			candies[i][j] -= tmpD
	else:
		continue
	print(moves)


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - mina, b[i] - min(b))
	print(ans)


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

def solve():
	(n,) = read()
	a = read()
	b = read()
	ma = min(a)
	mb = min(b)
	res = 0
	for i in range(n):
		ca = a[i] - ma
		cb = b[i] - mb
		res += min(ca, cb) + abs(ca - cb)
	print(res)
_ = 1
_ = int(input())
while _:
	solve()
	_ -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	sumo = []
	for j in range(n):
		ajo = a[j] - amin
		bs = b[j] - bmin
		if ajo >= bs:
			sumo.append(ajo)
		else:
			sumo.append(bs)
	print(sum(sumo))


T = int(input())
for _ in range(T):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	(can, ong) = (min(arr1), min(arr2))
	move = 0
	for i in range(n):
		if arr1[i] == can and arr2[i] > ong:
			move += arr2[i] - ong
		elif arr1[i] > can and arr2[i] == ong:
			move += arr1[i] - can
		elif arr1[i] > can and arr2[i] > ong:
			(p, q) = (arr1[i], arr2[i])
			if p - can > q - ong:
				move += q - ong
				p -= q - ong
				q = ong
				move += p - can
			elif p - can < q - ong:
				move += p - can
				q -= p - can
				p = can
				move += q - ong
			else:
				move += p - can
	print(move)


for i in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	l = min(a)
	r = min(b)
	cnt = 0
	for i in range(n):
		if a[i] > l:
			cnt += a[i] - l
			a[i] = a[i] - l
		else:
			a[i] = 0
	for i in range(n):
		if b[i] > r:
			cnt += max(0, b[i] - a[i] - r)
	print(cnt)


n = int(input())
for i in range(n):
	j = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	sum = 0
	for i in range(j):
		sum += max(abs(a[i] - min_a), abs(b[i] - min_b))
	print(sum)


t = int(input())
for i in range(t):
	_ = input()
	[*a] = map(int, input().split())
	[*b] = map(int, input().split())
	ta = min(a)
	tb = min(b)
	print(sum((max(i - ta, j - tb) for (i, j) in zip(a, b))))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	count = 0
	for i in range(n):
		gf = a[i] - a1
		rt = b[i] - b1
		count += min(gf, rt)
		count += max(gf, rt) - min(gf, rt)
	print(count)


num_queries = int(input())
for query in range(num_queries):
	arr_len = int(input())
	candies = [int(x) for x in str(input()).split()]
	oranges = [int(x) for x in str(input()).split()]
	operations_num = 0
	target_candies_num = min(candies)
	target_oranges_num = min(oranges)
	for present_idx in range(len(candies)):
		extra_candies = candies[present_idx] - target_candies_num
		extra_oranges = oranges[present_idx] - target_oranges_num
		double_op_num = min(extra_candies, extra_oranges)
		operations_num += extra_candies + extra_oranges - double_op_num
	print(operations_num)


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	(x_min, y_min) = (min(x), min(y))
	c = 0
	for i in range(n):
		if x[i] > x_min and y[i] > y_min:
			z = min(x[i] - x_min, y[i] - y_min)
			x[i] -= z
			y[i] -= z
			c += x[i] - x_min + y[i] - y_min + z
		else:
			c += x[i] - x_min + y[i] - y_min
	print(c)


def solve(a, b):
	ans = 0
	aS = min(a)
	bS = min(b)
	for i in range(len(a)):
		tempa = a[i] - aS
		tempb = b[i] - bS
		temp = min(tempa, tempb)
		ans += min(tempa, tempb)
		tempa -= temp
		tempb -= temp
		ans += max(tempa, tempb)
	return ans
for _ in range(int(input())):
	_ = input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(a, b))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ta = min(a)
	tb = min(b)
	ans = 0
	for i in range(n):
		(ca, cb) = (a[i] - ta, b[i] - tb)
		ans += min(ca, cb)
		ans += abs(ca - cb)
	print(ans)


nb = int(input())
for k in range(nb):
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	sol = 0
	ma = min(A)
	mb = min(B)
	for k in range(n):
		na = A[k] - ma
		nb = B[k] - mb
		nmove = max([na, nb])
		sol += nmove
	print(sol)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	extra = [0 for x in range(n)]
	x = min(l)
	y = min(m)
	for i in range(n):
		extra[i] = max(l[i] - x, m[i] - y)
	print(sum(extra))


import math

def shrey():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	f = 0
	for i in range(n):
		ans1 = a[i] - m1
		ans2 = b[i] - m2
		if ans1 > ans2:
			c = ans1
		else:
			c = ans2
		f += c
	print(f)
T = input()
T = int(T)
for q in range(1, T + 1):
	shrey()


from sys import stdin
input = stdin.readline

def help():
	n = int(input())
	arr1 = list(map(int, input().split(' ')))
	arr2 = list(map(int, input().split(' ')))
	t1 = min(arr1)
	t2 = min(arr2)
	moves = 0
	for i in range(n):
		d1 = arr1[i] - t1
		d2 = arr2[i] - t2
		moves += max(d1, d2)
	print(moves)
for _ in range(int(input())):
	help()


task_num = int(input().strip())
for task_id in range(task_num):
	gift_num = int(input().strip())
	candies = list(map(int, input().strip().split(' ')))
	oranges = list(map(int, input().strip().split(' ')))
	min_candy = min(candies)
	min_orange = min(oranges)
	moves = 0
	for (candy, orange) in zip(candies, oranges):
		moves += max(candy - min_candy, orange - min_orange)
	print(moves)


for i in range(int(input())):
	moves = 0
	n = int(input())
	a = input()
	b = input()
	a = a.split()
	map_object = map(int, a)
	a = list(map_object)
	b = b.split()
	map_object = map(int, b)
	b = list(map_object)
	for (aItem, bItem) in zip(a, b):
		difA = aItem - min(a)
		difB = bItem - min(b)
		moves += max(difA, difB)
	print(moves)


for j in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	res = 0
	for i in range(n):
		res += max(a[i] - ma, b[i] - mb)
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	count = 0
	i = 0
	mc = min(candies)
	mo = min(oranges)
	for i in range(n):
		a = candies[i] - mc
		b = oranges[i] - mo
		count += max(a, b)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	(p, q) = (min(a), min(b))
	a = [x - p for x in a]
	b = [x - q for x in b]
	print(sum([max(a[i], b[i]) for i in range(n)]))


t = int(input())
for i in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_candy = min(candies)
	min_orange = min(oranges)
	ans = 0
	for l in range(n):
		ans += max(candies[l] - min_candy, oranges[l] - min_orange)
	print(ans)


test = int(input())
for _ in range(test):
	n = int(input())
	arr_a = list(map(int, input().split()))
	arr_b = list(map(int, input().split()))
	min_a = min(arr_a)
	min_b = min(arr_b)
	count = 0
	for (a, b) in zip(arr_a, arr_b):
		(min_, max_) = (0, 0)
		(a, b) = (a - min_a, b - min_b)
		min_ = min(a, b)
		max_ = max(a, b)
		count += min_ + (max_ - min_)
	print(count)


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
import itertools

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

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

def Lstr():
	return list(sys.stdin.readline().strip())

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

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

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

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

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

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def common(l1, l2):
	return set(l1).intersection(l2)

def solution():
	for _ in range(Int()):
		n = Int()
		a = List()
		b = List()
		a1 = min(a)
		b1 = min(b)
		c = 0
		for i in range(n):
			c += max(a[i] - a1, b[i] - b1)
		print(c)
solution()


T = int(input())
for t in range(T):
	n = int(input())
	li1 = list(map(int, input().split()))
	li2 = list(map(int, input().split()))
	a1 = min(li1)
	a2 = min(li2)
	count = 0
	for i in range(n):
		count += max(li1[i] - a1, li2[i] - a2)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	mn_candies = min(a)
	mn_oranges = min(b)
	res = 0
	for i in range(n):
		res += max(a[i] - mn_candies, b[i] - mn_oranges)
	print(res)


t = int(input())
candies = list()
oranges = list()
result = list()
for test_case in range(t):
	n = int(input())
	candies.clear()
	oranges.clear()
	no_of_steps = 0
	candies = input()
	candies = candies.split()
	candies = list(map(int, candies))
	oranges = input()
	oranges = oranges.split()
	oranges = list(map(int, oranges))
	min_candies = min(candies)
	min_oranges = min(oranges)
	for gift in range(n):
		if candies[gift] > min_candies and oranges[gift] > min_oranges:
			if candies[gift] - min_candies < oranges[gift] - min_oranges:
				no_of_steps += oranges[gift] - min_oranges
			else:
				no_of_steps += candies[gift] - min_candies
		elif candies[gift] > min_candies:
			no_of_steps += candies[gift] - min_candies
		else:
			no_of_steps += oranges[gift] - min_oranges
	result.append(no_of_steps)
for res in result:
	print(res)


import math
m = int(input())
for l in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	moves = 0
	for i in range(n):
		a[i] = a[i] - mina
		b[i] = b[i] - minb
		moves += max(a[i], b[i])
	print(moves)


import sys

def solve(CANDIES, ORANGES):
	MC = min(CANDIES)
	MO = min(ORANGES)
	min_moves = 0
	for i in range(len(CANDIES)):
		mi = CANDIES[i]
		mo = ORANGES[i]
		min_moves += max(mi - MC, mo - MO)
	return min_moves
IN = [x.strip() for x in sys.stdin.readlines()]
T = int(IN[0])
cur = 1
for ti in range(T):
	C = [int(x) for x in IN[cur + 1].split(' ')]
	O = [int(x) for x in IN[cur + 2].split(' ')]
	print(solve(C, O))
	cur += 3


import math
import time
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import PriorityQueue
import sys
t = int(input())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		ea = a[i] - amin
		eb = b[i] - bmin
		temp = min(ea, eb)
		ans += temp
		ea -= temp
		eb -= temp
		ans += ea + eb
	print(ans)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mia = min(a)
	mib = min(b)
	cnt = 0
	for i in range(n):
		cnt += max(a[i] - mia, b[i] - mib)
	print(cnt)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = [0 for i in range(n)]
	y = [0 for i in range(n)]
	a_m = min(a)
	b_min = min(b)
	for i in range(n):
		x[i] = a[i] - a_m
		y[i] = b[i] - b_min
	s = 0
	for i in range(n):
		d = abs(x[i] - y[i])
		s += d
		if x[i] > y[i]:
			x[i] -= d
			s += x[i]
		else:
			y[i] -= d
			s += y[i]
	print(s)


def genRemArray(li, n):
	rem = []
	for i in li:
		rem.append(i - n)
	return rem

def main():
	t = int(input())
	for i in range(t):
		gifts = int(input())
		candies = list(map(int, input().split()))
		oranges = list(map(int, input().split()))
		min_c = min(candies)
		min_o = min(oranges)
		rem_c = genRemArray(candies, min_c)
		rem_o = genRemArray(oranges, min_o)
		moves = 0
		for i in range(gifts):
			moves += max(rem_c[i], rem_o[i])
		print(moves)
main()


from sys import stdin
import sys
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		aa = a[i] - amin
		bb = b[i] - bmin
		ans += max(aa, bb)
	print(ans)


n = 0
a = []
b = []

def solve():
	minA = min(a)
	minB = min(b)
	count = 0
	for i in range(n):
		count += max(a[i] - minA, b[i] - minB)
	return count
T = int(input())
for x in range(1, T + 1):
	n = int(input())
	a = [int(n) for n in input().split()]
	b = [int(n) for n in input().split()]
	res = solve()
	print(res)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	a = L()
	b = L()
	x = min(a)
	y = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - x, b[i] - y)
	print(ans)


nnn = int(input())
for _ in range(nnn):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	min_a = min(arr1)
	min_b = min(arr2)
	s = 0
	for i in range(n):
		p = arr1[i] - min_a
		q = arr2[i] - min_b
		s += min(p, q)
		s += abs(p - q)
	print(s)


t = int(input())
for i in range(0, t):
	steps = 0
	n = int(input())
	a = list()
	b = list()
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	sa = min(a)
	sb = min(b)
	for j in range(0, n):
		d1 = a[j] - sa
		d2 = b[j] - sb
		dh = max(d1, d2)
		steps = steps + dh
	print(steps)


def solve(a, b, n):
	ans = 0
	mina = min(a)
	minb = min(b)
	for i in range(n):
		ans += max(a[i] - mina, b[i] - minb)
	return ans
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(a, b, n))


T = int(input())
for _ in range(T):
	N = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	ans = 0
	m1 = min(l1)
	m2 = min(l2)
	for (x, y) in zip(l1, l2):
		ans += max(abs(x - m1), abs(y - m2))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	m1 = min(arr)
	m2 = min(brr)
	res = 0
	for i in range(n):
		cost1 = 0
		cost2 = 0
		if arr[i] > m1:
			cost1 = arr[i] - m1
		if brr[i] > m2:
			cost2 = brr[i] - m2
		res += max(cost1, cost2)
	print(res)


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()]
	o = 0
	for z in range(n):
		if a[z] > min(a) and b[z] > min(b):
			if a[z] - min(a) > b[z] - min(b):
				o += b[z] - min(b)
				o += a[z] - min(a) - (b[z] - min(b))
			elif b[z] - min(b) > a[z] - min(a):
				o += a[z] - min(a)
				o += b[z] - min(b) - (a[z] - min(a))
			else:
				o += a[z] - min(a)
		elif a[z] > min(a):
			o += a[z] - min(a)
		elif b[z] > min(b):
			o += b[z] - min(b)
	print(o)


def calc(n, a, b):
	min_a = min(a)
	a = [x - min_a for x in a]
	min_b = min(b)
	b = [x - min_b for x in b]
	tmp = 0
	for i in range(n):
		tmp += max(a[i], b[i])
	return tmp

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(lambda x: int(x), input().split()))
		b = list(map(lambda x: int(x), input().split()))
		print(calc(n, a, b))
main()


t = int(input())
for j in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	minA = min(A)
	minB = min(B)
	summ = 0
	for i in range(n):
		summ += max(A[i] - minA, B[i] - minB)
	print(summ)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mnc = min(a)
	mno = min(b)
	ans = 0
	for j in range(n):
		tc = a[j] - mnc
		to = b[j] - mno
		if tc > to:
			ans += to + (tc - to)
		else:
			ans += tc + (to - tc)
	print(ans)


test = int(input())
for cases in range(test):
	n = int(input())
	als = list(map(int, input().split()))
	bls = list(map(int, input().split()))
	amin = sorted(als)[0]
	bmin = sorted(bls)[0]
	ans = 0
	for i in range(n):
		ans += max(als[i] - amin, bls[i] - bmin)
	print(ans)


for tc in range(int(input())):
	length = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	moves = 0
	mn_candy = min(candies)
	mn_oranges = min(oranges)
	for x in range(length):
		if candies[x] > mn_candy and oranges[x] > mn_oranges:
			z = min(abs(candies[x] - mn_candy), abs(oranges[x] - mn_oranges))
			candies[x] -= z
			oranges[x] -= z
			moves += z
	for x in candies:
		if x > mn_candy:
			moves += x - mn_candy
	for x in oranges:
		if x > mn_oranges:
			moves += x - mn_oranges
	print(moves)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	c = 0
	if len(list(set(a))) == 1 and len(list(set(b))) == 1:
		print(0)
	else:
		for i in range(n):
			c += max(a[i] - am, b[i] - bm)
		print(c)


t = int(input())
while t:
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	minc = min(c)
	mino = min(o)
	ans = 0
	for i in range(0, n):
		f1 = c[i] - minc
		f2 = o[i] - mino
		if f1 > f2:
			ans = ans + f1
		else:
			ans = ans + f2
	print(ans)
	t = t - 1


from sys import stdin

def moves(arr1, arr2, n):
	minn1 = min(arr1)
	minn2 = min(arr2)
	total = sum(map(lambda i: max(arr1[i] - minn1, arr2[i] - minn2), range(n)))
	print(total)

def solution():
	input = stdin.readline
	t = int(input())
	for i in range(t):
		n = int(input())
		arr1 = [int(x) for x in input().split()]
		arr2 = [int(x) for x in input().split()]
		moves(arr1, arr2, n)
solution()


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(min_a, min_b) = (float('inf'), float('inf'))
	for i in range(n):
		if a[i] < min_a:
			min_a = a[i]
		if b[i] < min_b:
			min_b = b[i]
	moves = 0
	for i in range(n):
		moves += max(a[i] - min_a, b[i] - min_b)
	print(moves)
	t -= 1


def minsteps(m, n, x, y):
	return max(abs(m - x), abs(n - y))

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		(x, y) = (min(a), min(b))
		res = 0
		for i in range(len(a)):
			res += minsteps(a[i], b[i], x, y)
		print(res)
main()


import math
n = int(input())
for i in range(n):
	m = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	e = min(a)
	f = min(b)
	l = []
	s = []
	h = 0
	for j in range(0, len(a)):
		l.append(abs(a[j] - e))
		s.append(abs(b[j] - f))
	for j in range(0, len(l)):
		h = h + max(l[j], s[j])
	print(h)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	num_moves = 0
	for (ai, bi) in zip(a, b):
		num_moves += max(ai - mina, bi - minb)
	print(num_moves)


import math
t = int(input())
for i in range(t):
	n = int(input())
	a = input().split(' ')
	b = input().split(' ')
	k = 0
	for j in range(n):
		a[j] = int(a[j])
		b[j] = int(b[j])
	am = min(a)
	bm = min(b)
	for j in range(n):
		aj = a[j] - am
		bj = b[j] - bm
		k += max(aj, bj)
	print(k)


number = int(input())
for i in range(number):
	gifts = int(input())
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	times = 0
	mincandy = min(candy)
	minorange = min(orange)
	for p in range(gifts):
		times += max(candy[p] - mincandy, orange[p] - minorange)
	print(times)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	counta = 0
	countb = 0
	ans = 0
	for i in range(n):
		counta = a[i] - ma
		countb = b[i] - mb
		ans += min(counta, countb) + max(counta, countb) - min(counta, countb)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	x = min(a)
	y = min(b)
	(diff1, diff2) = ([xx - x for xx in a], [yy - y for yy in b])
	ans = 0
	for i in range(len(diff1)):
		x = min(diff1[i], diff2[i])
		ans = ans + x + (diff1[i] - x) + (diff2[i] - x)
	print(ans)


for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().strip().split()))[:a]
	c = list(map(int, input().strip().split()))[:a]
	count1 = []
	d = min(b)
	for j in range(a):
		count1.append(b[j] - d)
	count2 = []
	e = min(c)
	for k in range(a):
		count2.append(c[k] - e)
	sum = 0
	for l in range(len(count1)):
		if count1[l] >= count2[l]:
			sum += count1[l]
		else:
			sum += count2[l]
	print(int(sum))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p = list(a)
	b = list(map(int, input().split()))
	q = list(b)
	(x, y) = (min(a), min(b))
	c = 0
	for i in range(n):
		if p[i] != min(p) and q[i] != min(q):
			c += min(p[i] - x, q[i] - y)
			a[i] -= min(p[i] - x, q[i] - y)
			b[i] -= min(p[i] - x, q[i] - y)
	print(c + (sum(a) - n * min(a)) + (sum(b) - n * min(b)))


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(' ')))
	c = a.copy()
	d = b.copy()
	c.sort()
	d.sort()
	amin = c[0]
	bmin = d[0]
	moves = 0
	for i in range(n):
		if a[i] > amin and b[i] > bmin:
			x = min(a[i] - amin, b[i] - bmin)
			a[i] -= x
			b[i] -= x
			moves += x
		if a[i] > amin and b[i] == bmin:
			moves += a[i] - amin
			a[i] = amin
		if a[i] == amin and b[i] > bmin:
			moves += b[i] - bmin
			b[i] = bmin
	print(moves)


t = int(input())
while t:
	n = int(input())
	l = [int(x) for x in input().split()]
	m = [int(x) for x in input().split()]
	k = min(l)
	y = min(m)
	c = 0
	for i in range(n):
		if l[i] != k and m[i] != y:
			c += l[i] - k + (m[i] - y) - min(l[i] - k, m[i] - y)
		elif l[i] == k and m[i] != y:
			c += m[i] - y
		elif l[i] != k and m[i] == y:
			c += l[i] - k
	print(c)
	t -= 1


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	x = min(a)
	y = min(b)
	for i in range(n):
		q = a[i] - x
		w = b[i] - y
		t = min(q, w)
		count += t + q - t + w - t
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	l1 = [int(i) for i in input().split()]
	min1 = min(l)
	min2 = min(l1)
	step = 0
	while len(set(l)) != 1 or len(set(l1)) != 1:
		for i in range(n):
			if (l[i] > min1 and l[i] > min2) and l[i] == l1[i] and (min1 == min2):
				step = step + (l[i] - min1)
				l[i] = l[i] - (l[i] - min1)
				l1[i] = l1[i] - (l1[i] - min2)
			if l[i] > min1 and l1[i] > min2:
				check1 = abs(l[i] - min1)
				check2 = abs(l1[i] - min2)
				if check1 > check2:
					l[i] = l[i] - check2
					l1[i] = l1[i] - check2
					step += check2
				else:
					l[i] = l[i] - check1
					l1[i] = l1[i] - check1
					step += check1
			if l[i] > min1 and l1[i] <= min2:
				step = step + (l[i] - min1)
				l[i] = l[i] - (l[i] - min1)
			if l[i] <= min1 and l1[i] > min2:
				step = step + (l1[i] - min2)
				l1[i] = l1[i] - (l1[i] - min2)
	print(step)


t = int(input())
while t:
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	minA = min(a)
	minB = min(b)
	cnt = 0
	for i in range(0, n):
		s = min(a[i] - minA, b[i] - minB)
		a[i] -= s
		b[i] -= s
		cnt += s
		cnt += a[i] - minA
		cnt += b[i] - minB
	print(cnt)
	t -= 1


n = int(input())
for _ in range(n):
	e = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	can = min(c)
	orn = min(o)
	cnt = 0
	i = 0
	while i < len(c):
		if c[i] > can and o[i] > orn:
			x = c[i] - can
			y = o[i] - orn
			m = min(x, y)
			cnt += m
			c[i] -= m
			o[i] -= m
		elif c[i] > can:
			cnt += c[i] - can
			c[i] = can
		elif o[i] > orn:
			cnt += o[i] - orn
			o[i] = orn
		else:
			i += 1
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	(a1, b1) = (min(a), min(b))
	for i in range(n):
		(d1, d2) = (a[i] - a1, b[i] - b1)
		ans += max(d1, d2, 0)
	print(ans)


import math
import sys
import collections
import bisect
from collections import defaultdict
from sys import stdin, stdout
MOD = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 7)

def take_root(num):
	return math.ceil(math.sqrt(num))

def sieve():
	limit = 86028121
	isprime = [1] * 86028122
	isprime[0] = 0
	isprime[1] = 0
	for i in range(2, take_root(limit + 1)):
		if isprime[i] == 1:
			for j in range(i * i, limit + 1, i):
				isprime[j] = 0
	primes = []
	for i in range(limit + 1):
		if isprime[i] == True:
			primes.append(i)
	return primes

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

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

def strinput():
	return input()

def linput():
	return list(map(int, input().split()))
for _ in range(iinput()):
	n = iinput()
	arr = linput()
	brr = linput()
	t1 = min(arr)
	t2 = min(brr)
	summ = 0
	for i in range(n):
		summ += max(abs(t1 - arr[i]), abs(t2 - brr[i]))
	print(summ)


def solve():
	n = int(input())
	l = [int(x) for x in input().split()]
	g = [int(y) for y in input().split()]
	(p, q) = (min(l), min(g))
	ans = 0
	for i in range(n):
		ans += max(l[i] - p, g[i] - q)
	print(ans)
for _ in range(int(input())):
	solve()


for tt in range(int(input())):
	n = int(input())
	c = 0
	a = [int(f) for f in input().split()]
	b = [int(f) for f in input().split()]
	aa = min(a)
	bb = min(b)
	for i in range(n):
		c += max(a[i] - aa, b[i] - bb)
	print(c)


def main():
	t = int(input())
	for i in range(t):
		size = int(input())
		arr1 = input()
		arr2 = input()
		arr1 = [int(i) for i in arr1.split()]
		arr2 = [int(i) for i in arr2.split()]
		min1 = min(arr1)
		min2 = min(arr2)
		count = 0
		for i in range(size):
			count += arr2[i] - min2 if arr1[i] - min1 < arr2[i] - min2 else arr1[i] - min1
		print(count)
main()


T = int(input())
for i in range(T):
	length = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	(minA, minB) = (min(A), min(B))
	for j in range(length):
		A[j] -= minA
		B[j] -= minB
	res = 0
	for j in range(length):
		res += max(A[j], B[j])
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	sa = min(a)
	sb = min(b)
	i = 0
	while i < n:
		count += max(a[i] - sa, b[i] - sb)
		i += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	lc = list(map(int, input().split()))
	lo = list(map(int, input().split()))
	mc = min(lc)
	mo = min(lo)
	count = 0
	for (c, o) in zip(lc, lo):
		count += max(c - mc, o - mo)
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	x = min(l1)
	y = min(l2)
	move = 0
	for j in range(n):
		if l1[j] != x and l2[j] != y:
			t1 = l1[j] - x
			t2 = l2[j] - y
			l1[j] -= min(t1, t2)
			l2[j] -= min(t1, t2)
			move += min(t1, t2)
		if l1[j] != x:
			if x == 1:
				move += l1[j] - 1
				continue
			move += l1[j] - x
		if l2[j] != y:
			if y == 1:
				move += l2[j] - 1
				continue
			move += l2[j] - y
	print(move)


n = int(input())
for i in range(n):
	su = 0
	m = int(input())
	candy = input().split()
	ora = input().split()
	for j in range(m):
		candy[j] = int(candy[j])
		ora[j] = int(ora[j])
	cam = min(candy)
	oram = min(ora)
	for k in range(m):
		l = candy[k] - cam
		o = ora[k] - oram
		su += min(l, o)
		su += max(l, o) - min(l, o)
	print(su)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mna = min(a)
	mnb = min(b)
	ans = 0
	for j in range(n):
		da = a[j] - mna
		db = b[j] - mnb
		ans += max(da, db)
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	ar = list(map(int, input().split()))
	br = list(map(int, input().split()))
	min1 = min(ar)
	min2 = min(br)
	max1 = max(ar)
	max2 = max(br)
	moves1 = []
	moves2 = []
	for i in range(n):
		moves1.append(abs(min1 - ar[i]))
	for i in range(n):
		moves2.append(abs(min2 - br[i]))
	s = 0
	for i in range(n):
		s += min(moves1[i], moves2[i])
		s += abs(max(moves1[i], moves2[i]) - min(moves1[i], moves2[i]))
	print(s)


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		candy = list(map(int, input().split()))
		apple = list(map(int, input().split()))
		min_candy = min(candy)
		min_apple = min(apple)
		res = 0
		for j in range(n):
			res += max(candy[j] - min_candy, apple[j] - min_apple)
		print(res)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minA = min(a)
	minB = min(b)
	moves = 0
	for i in range(n):
		if a[i] == minA or b[i] == minB:
			if a[i] > minA:
				moves += a[i] - minA
			elif b[i] > minB:
				moves += b[i] - minB
		elif a[i] > minA and b[i] > minB:
			mn = min(a[i] - minA, b[i] - minB)
			moves += mn
			if b[i] - mn == minB and a[i] - mn != minA:
				moves += a[i] - mn - minA
			elif b[i] - mn != minB and a[i] - mn == minA:
				moves += b[i] - mn - minB
	print(moves)


import sys
input = lambda : sys.stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	n = INT()
	k = mp()
	l = mp()
	ans = 0
	(mn1, mn2) = (min(k), min(l))
	for i in range(n):
		ans += max(k[i] - mn1, l[i] - mn2)
	print(ans)


def find_no_of_moves(a, b):
	a_min = min(a)
	b_min = min(b)
	moves = 0
	for i in range(len(a)):
		common = min([a[i] - a_min, b[i] - b_min])
		moves += common
		a[i] = a[i] - common
		b[i] = b[i] - common
		moves = moves + (a[i] - a_min)
		moves = moves + (b[i] - b_min)
	return moves
testcases = int(input())
result = []
for i in range(testcases):
	number_of_gifts = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	result = find_no_of_moves(a, b)
	print(result)


t = int(input())
while t != 0:
	n = int(input())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	mina = min(la)
	minb = min(lb)
	ans = 0
	for i in range(n):
		ans += max(la[i] - mina, lb[i] - minb)
	print(ans)
	t -= 1


n = int(input())
for _ in range(n):
	t = int(input())
	mov = 0
	str_a = input()
	str_b = input()
	arr_a = [int(x) for x in str_a.split(' ')]
	arr_b = [int(x) for x in str_b.split(' ')]
	min_a = min(arr_a)
	min_b = min(arr_b)
	for i in range(t):
		crr_a = arr_a[i]
		crr_b = arr_b[i]
		diff_a = crr_a - min_a
		diff_b = crr_b - min_b
		diff = abs(diff_a - diff_b)
		mdif = max(diff_a, diff_b)
		mdif -= diff
		mov += diff
		mov += mdif
	print(mov)


for _ in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	(*b,) = map(int, input().split())
	mn_a = min(a)
	mn_b = min(b)
	cnt = 0
	for i in range(n):
		a_diff = a[i] - mn_a
		b_diff = b[i] - mn_b
		cnt += max(b_diff, a_diff)
	print(cnt)


def ans(n, A, B):
	sum = 0
	a = min(A)
	b = min(B)
	for i in range(n):
		sum += max(A[i] - a, B[i] - b)
	return sum
t = int(input())
L = []
for i in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	L.append(ans(n, A, B))
for l in L:
	print(l)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	b = list(map(int, input().strip().split(' ')))
	u = 0
	aMin = a[0]
	bMin = b[0]
	for i in range(0, len(a), 1):
		if a[i] < aMin:
			aMin = a[i]
	for k in range(0, len(b), 1):
		if b[k] < bMin:
			bMin = b[k]
	for h in range(0, n, 1):
		if a[h] - aMin > b[h] - bMin:
			u += a[h] - aMin
		else:
			u += b[h] - bMin
	print(u)
	t -= 1


def f(a, b, c, d):
	return max(a - c, b - d)
t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = input().split()
	b = input().split()
	for i in range(0, n):
		a[i] = int(a[i])
		b[i] = int(b[i])
	c = min(a)
	d = min(b)
	sum = 0
	for i in range(0, n):
		sum = sum + f(a[i], b[i], c, d)
	print(sum)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	candy = min(arr)
	orange = min(brr)
	ans = 0
	for i in range(n):
		arr[i] = arr[i] - candy
		brr[i] = brr[i] - orange
		ans = ans + min(arr[i], brr[i])
		ans = ans + (arr[i] - min(arr[i], brr[i])) + (brr[i] - min(arr[i], brr[i]))
	print(ans)


n = int(input())
for i in range(n):
	k = int(input())
	t1 = [int(x) for x in input().split()]
	t2 = [int(y) for y in input().split()]
	a = min(t1)
	b = min(t2)
	a1 = sum(t1) - min(t1) * len(t1)
	b1 = sum(t2) - min(t2) * len(t2)
	num = 0
	for q in range(k):
		if t1[q] > a and t2[q] > b:
			c = t1[q] - a
			d = t2[q] - b
			if c >= d:
				num += d
			else:
				num += c
	print(a1 + b1 - num)


def equal_lists(a, b):
	(mina, minb) = (min(a), min(b))
	nb = 0
	for i in range(len(a)):
		delta = 0
		if a[i] != mina and b[i] != minb:
			delta = min(a[i] - mina, b[i] - minb)
			a[i] -= delta
			b[i] -= delta
		nb += delta + b[i] - minb + a[i] - mina
	return nb
nbtests = int(input())
results = []
for _ in range(nbtests):
	arrlen = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(map(int, input().rstrip().split()))
	res = equal_lists(a, b)
	results.append(res)
for res in results:
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	ans = 0
	for i in range(n):
		t1 = a[i] - am
		t2 = b[i] - bm
		t3 = min(t1, t2)
		t1 -= t3
		t2 -= t3
		ans += t3 + t1 + t2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	a = min(candies)
	b = min(oranges)
	moves = 0
	for i in range(n):
		if candies[i] == a and oranges[i] == b:
			continue
		elif candies[i] == a and oranges[i] != b:
			moves += oranges[i] - b
		elif candies[i] != a and oranges[i] == b:
			moves += candies[i] - a
		elif candies[i] != a and oranges[i] != b:
			if oranges[i] - b > candies[i] - a:
				moves += candies[i] - a
				moves += oranges[i] - b - (candies[i] - a)
			elif oranges[i] - b < candies[i] - a:
				moves += oranges[i] - b
				moves += candies[i] - a - (oranges[i] - b)
			elif oranges[i] - b == candies[i] - a:
				moves += oranges[i] - b
	print(moves)


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	for i in range(n):
		a[i] -= mina
	for i in range(n):
		b[i] -= minb
	count = 0
	for i in range(n):
		minab = min(a[i], b[i])
		count += minab
		count += a[i] - minab + (b[i] - minab)
	print(count)


t = int(input())
for t_c in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	min_a = min(a)
	min_b = min(b)
	steps = 0
	for (ca, cb) in zip(a, b):
		if ca - min_a > cb - min_b:
			steps += ca - min_a
		else:
			steps += cb - min_b
	print(steps)


import math

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

def stringlsit():
	return input().split(' ')

def solve():
	n = int(input())
	c = intlist()
	o = intlist()
	mc = min(c)
	mo = min(o)
	ans = 0
	for i in range(n):
		cn = c[i] - mc
		on = o[i] - mo
		ans += max(cn, on)
	return ans
t = input()
for tt in range(int(t)):
	print(solve())


for ad in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		x = a[i]
		y = b[i]
		temp = min(x - mina, y - minb)
		temp += abs(x - mina - y + minb)
		ans += temp
	print(ans)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	n = int(sys.stdin.readline())
	list_a = list(map(int, sys.stdin.readline().split()))
	list_b = list(map(int, sys.stdin.readline().split()))
	key_a = min(list_a)
	key_b = min(list_b)
	res = 0
	for i in range(n):
		a_move = list_a[i] - key_a
		b_move = list_b[i] - key_b
		res += min(a_move, b_move)
		res += abs(a_move - b_move)
	print(res)


x = int(input())
for z in range(x):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	c = 0
	for i in range(n):
		if a[i] - amin > b[i] - bmin:
			c = c + a[i] - amin
		else:
			c = c + b[i] - bmin
	print(c)


import math

def solve(a, b):
	steps = 0
	needAtA = neededAtI(a)
	needAtB = neededAtI(b)
	for i in range(len(needAtA)):
		steps += maxBw(needAtA[i], needAtB[i])
	return steps

def neededAtI(a):
	m = min(a)
	need = []
	for i in range(len(a)):
		need.append(a[i] - m)
	return need

def maxBw(a, b):
	if a > b:
		return a
	return b
t = int(input())
sol = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	sol.append(solve(a, b))
print(*sol, sep='\n')


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	n = sInt()
	a = lInt()
	b = lInt()
	ma = min(a)
	mb = min(b)
	ans = 0
	for i in range(n):
		if a[i] - ma == b[i] - mb:
			ans += a[i] - ma
		elif a[i] - ma > b[i] - mb:
			ans += a[i] - ma
		else:
			ans += b[i] - mb
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	a = input().split(' ')
	b = input().split(' ')
	a = [int(i) for i in a]
	b = [int(i) for i in b]
	b_min = min(b)
	a_min = min(a)
	ans = 0
	for i in a:
		i = int(i)
		a_min = min(i, a_min)
	for i in range(len(a)):
		a[i] = a[i] - a_min
		b[i] = b[i] - b_min
		ans += min(a[i], b[i]) + abs(a[i] - b[i])
	print(ans)
	t -= 1


a = int(input())
for i in range(a):
	b = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	m1 = min(l1)
	m2 = min(l2)
	c = 0
	for i in range(b):
		d1 = l1[i] - m1
		d2 = l2[i] - m2
		c += min(d1, d2) + max(d1, d2) - min(d1, d2)
	print(c)


def submit():
	for _ in range(int(input())):
		input()
		sum = 0
		a = [int(e) for e in input().split()]
		b = [int(e) for e in input().split()]
		lowest_a = min(a)
		lowest_b = min(b)
		for (i, k) in zip(a, b):
			sum += max(i - lowest_a, k - lowest_b)
		print(sum)
submit()


def min(a, b):
	if a < b:
		return a
	return b
for _ in range(int(input())):
	n = int(input())
	ar = input().split()
	br = input().split()
	a = []
	b = []
	for i in range(n):
		a.append(int(ar[i]))
		b.append(int(br[i]))
	min1 = a[0]
	min2 = b[0]
	for i in range(n):
		min1 = min(a[i], min1)
		min2 = min(b[i], min2)
	moves = 0
	for i in range(n):
		if a[i] > min1 and b[i] > min2:
			g = min(a[i] - min1, b[i] - min2)
			moves += g
			a[i] -= g
			b[i] -= g
		if a[i] > min1:
			moves += a[i] - min1
			a[i] = min1
		if b[i] > min2:
			moves += b[i] - min2
			b[i] = min2
	print(moves)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(A, B) = (min(a), min(b))
	c = 0
	for i in range(n):
		if a[i] == A:
			if b[i] != B:
				c = c + (b[i] - B)
		elif b[i] == B:
			if a[i] != A:
				c = c + (a[i] - A)
		else:
			m = a[i] - A
			n = b[i] - B
			c = c + max(m, n)
	print(c)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	brr = list(map(int, input().strip().split()))
	amin = min(arr)
	bmin = min(brr)
	total = 0
	for x in range(n):
		if arr[x] - amin > 0 and brr[x] - bmin > 0:
			z = min(arr[x] - amin, brr[x] - bmin)
			total += z
			arr[x] -= z
			brr[x] -= z
			if arr[x] - amin != 0:
				total += arr[x] - amin
				arr[x] -= arr[x] - amin
			elif brr[x] - bmin != 0:
				total += brr[x] - bmin
				arr[x] -= brr[x] - bmin
		elif arr[x] - amin > 0 and brr[x] - bmin == 0:
			total += arr[x] - amin
			arr[x] = amin
		elif brr[x] - bmin > 0 and arr[x] - amin == 0:
			total += brr[x] - bmin
			brr[x] = bmin
	print(total)


for _ in range(int(input())):
	n = int(input())
	li1 = [int(x) for x in input().split()]
	li2 = [int(x) for x in input().split()]
	mina = min(li1)
	minb = min(li2)
	count = 0
	for i in range(n):
		if li1[i] > mina:
			a = li1[i] - mina
			if li2[i] > minb:
				b = li2[i] - minb
				li1[i] -= min(a, b)
				li2[i] -= min(a, b)
				count += min(a, b)
				if a > b:
					li1[i] -= a - b
					count += a - b
			else:
				li1[i] -= a
				count += a
	for i in range(n):
		if li2[i] > minb:
			b = li2[i] - minb
			li2[i] -= b
			count += b
	print(count)


test = int(input())
for i in range(0, test):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	count = 0
	for (i, j) in zip(a, b):
		if i > mina and j > minb:
			if i < j:
				count = count + (i - mina)
				j = j - (i - mina)
				i = i - (i - mina)
			else:
				count = count + (j - minb)
				i = i - (j - minb)
				j = j - (j - minb)
		if i > mina:
			count = count + (i - mina)
			i = mina
		if j > minb:
			count = count + (j - minb)
			j = minb
	print(count)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	r = 0
	for i in range(n):
		da = a[i] - am
		db = b[i] - bm
		if da > 0 and db > 0:
			x = min(da, db)
			r += da + db - x
		else:
			r += da + db
	print(r)
for i in range(int(input())):
	solve()


x = int(input())
for _ in range(x):
	count = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a1 = min(a)
	b1 = min(b)
	for i in range(n):
		count += max(a[i] - a1, b[i] - b1)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	min_a = min(a)
	min_b = min(b)
	count = 0
	for (i, j) in zip(a, b):
		if i > min_a and j > min_b:
			count += max(i - min_a, j - min_b)
		else:
			if i > min_a:
				count += i - min_a
			if j > min_b:
				count += j - min_b
	print(count)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	n = N()
	a = RLL()
	b = RLL()
	amin = min(a)
	bmin = min(b)
	res = 0
	for i in range(n):
		res += max(a[i] - amin, b[i] - bmin)
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	arr_a = list(map(int, input().split()))
	arr_b = list(map(int, input().split()))
	target_a = min(arr_a)
	target_b = min(arr_b)
	count = 0
	for i in range(n):
		two = 0
		one = 0
		Ai = arr_a[i]
		Bi = arr_b[i]
		while Ai > target_a or Bi > target_b:
			if Ai > target_a and Bi > target_b:
				two = min(Ai - target_a, Bi - target_b)
				count += two
				Ai -= two
				Bi -= two
				one = max(Ai - target_a, Bi - target_b)
				count += one
				(Ai, Bi) = (target_a, target_b)
			elif Ai > target_a:
				one = Ai - target_a
				Ai -= one
				count += one
			elif Bi > target_b:
				one = Bi - target_b
				Bi -= one
				count += one
	print(count)


from collections import defaultdict, deque

def main():
	t = int(input())
	for c in range(t):
		n = int(input())
		ar = list(map(int, input().split(' ')))
		br = list(map(int, input().split(' ')))
		a_min = min(ar)
		b_min = min(br)
		ans = 0
		for i in range(n):
			ans += max(ar[i] - a_min, br[i] - b_min)
		print(ans)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	(p, q) = (min(a), min(b))
	for (x, y) in zip(a, b):
		ans += max(x - p, y - q)
	print(ans)


z = int(input())
s = 0
for x in range(z):
	p = int(input())
	m = list(map(int, input().strip().split()[:p]))
	n = list(map(int, input().strip().split()[:p]))
	l1 = min(m)
	l2 = min(n)
	for y in range(p):
		s = s + max(m[y] - l1, n[y] - l2)
	print(s)
	s = 0


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	c = min(l1)
	cc = min(l2)
	count = 0
	for i in range(n):
		if l1[i] == c or l2[i] == cc:
			if l1[i] == c and l2[i] != cc:
				count += l2[i] - cc
			if l1[i] != c and l2[i] == cc:
				count += l1[i] - c
		else:
			count += max(l1[i] - c, l2[i] - cc)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	count = 0
	for i in range(n):
		p = a[i] - a_min
		q = b[i] - b_min
		count += min(p, q) + abs(p - q)
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr1 = [int(x) for x in input().split()]
	om = min(arr)
	tm = min(arr1)
	ans = 0
	for i in range(len(arr)):
		diff1 = arr[i] - om
		diff2 = arr1[i] - tm
		ans += max(diff1, diff2)
	print(ans)


def solve():
	n = int(input())
	alst = list(map(int, input().split()))
	blst = list(map(int, input().split()))
	a_min = min(alst)
	b_min = min(blst)
	ans = 0
	for (a, b) in zip(alst, blst):
		ans += max(a - a_min, b - b_min)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


import os
from sys import stdin, stdout

def solve(tc):
	n = int(stdin.readline().strip())
	seqA = list(map(int, stdin.readline().split()))
	seqB = list(map(int, stdin.readline().split()))
	minA = int(1000000000.0) + 1
	for num in seqA:
		minA = min(minA, num)
	minB = int(1000000000.0) + 1
	for num in seqB:
		minB = min(minB, num)
	ans = 0
	for i in range(n):
		if seqA[i] == minA:
			ans += seqB[i] - minB
		elif seqB[i] == minB:
			ans += seqA[i] - minA
		else:
			dA = seqA[i] - minA
			dB = seqB[i] - minB
			ans += max(dA, dB)
	print(ans)
tcs = 1
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


for _ in range(int(input())):
	x = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	x1 = min(a)
	x2 = min(b)
	k = 0
	for i in range(x):
		f = a[i] - x1
		f1 = b[i] - x2
		k1 = 0
		if f < f1:
			k1 = f1
		else:
			k1 = f
		k += k1
	print(k)


for x in range(0, int(input())):
	t = 0
	g = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	for y in range(0, g):
		m = c[y] - min(c)
		t += m
		c[y] = min(c)
		if o[y] - m <= min(o):
			o[y] = min(o)
		else:
			o[y] -= m
	for y in range(0, g):
		if o[y] != min(o):
			t += o[y] - min(o)
			o[y] = min(o)
	print(t)


t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	candies = min(a)
	oranges = min(b)
	operations = 0
	for i in range(0, n):
		operations = operations + max(a[i] - candies, b[i] - oranges)
	print(operations)


T = int(input())
for t in range(T):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	mina = min(a)
	minb = min(b)
	moves = 0
	for i in range(n):
		if a[i] > mina and b[i] > minb:
			m = min(a[i] - mina, b[i] - minb)
			a[i] -= m
			b[i] -= m
			moves += m
		if a[i] > mina:
			moves += a[i] - mina
			a[i] = mina
		if b[i] > minb:
			moves += b[i] - minb
			b[i] = minb
	print(moves)


from sys import stdin, stdout
from sys import maxsize
input = stdin.readline

def solve():
	pass
test = 1
test = int(input().strip())
for t in range(0, test):
	n = int(input().strip())
	a = [int(x) for x in input().strip().split()]
	b = [int(x) for x in input().strip().split()]
	ma = min(a)
	mb = min(b)
	cnt = 0
	for i in range(n):
		cnt += max(a[i] - ma, b[i] - mb)
	print(cnt)
	ans = solve()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	a = [x - a_min for x in a]
	b = [x - b_min for x in b]
	ans = [max(x, y) for (x, y) in zip(a, b)]
	print(sum(ans))


testcases = int(input())
for testcase in range(testcases):
	n = int(input())
	arra = []
	arrb = []
	temparr = input()
	temparr = temparr.split()
	for i in temparr:
		arra.append(int(i))
	temparr = input()
	temparr = temparr.split()
	for i in temparr:
		arrb.append(int(i))
	minsa = min(arra)
	minsb = min(arrb)
	count = 0
	for i in range(n):
		count += max(arra[i] - minsa, arrb[i] - minsb)
	print(count)


def solve(n, a, b):
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - amin, b[i] - bmin)
	return ans
t = int(input())
for we in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(n, a, b))


def minMoves(Candies, Oranges):
	moves = 0
	minC = min(Candies)
	minO = min(Oranges)
	for i in range(len(Candies)):
		moves += max(Candies[i] - minC, Oranges[i] - minO)
	return moves
for _ in range(int(input())):
	N = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	print(minMoves(candies, oranges))


import sys
lines = sys.stdin.read().splitlines()
lincnt = -1

def input():
	global lincnt
	lincnt += 1
	return lines[lincnt]

def solve():
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mia = min(a)
	mib = min(b)
	cnt = 0
	for i in range(len(a)):
		cnt += max(a[i] - mia, b[i] - mib)
	print(cnt)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	list2 = list(map(int, input().split()))
	min1 = min(list1)
	min2 = min(list2)
	for i in range(len(list1)):
		list1[i] = list1[i] - min1
		list2[i] = list2[i] - min2
	ans = 0
	for i in range(len(list1)):
		ans += min(list1[i], list2[i])
		ans += max(list1[i], list2[i]) - min(list1[i], list2[i])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	numC = list(map(int, input().split()))
	numO = list(map(int, input().split()))
	(minC, minO) = (min(numC), min(numO))
	total = 0
	for i in range(n):
		total += max(numC[i] - minC, numO[i] - minO)
	print(total)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	a = min(l)
	b = min(l1)
	c = 0
	ctr = 0
	for j in range(n):
		if l[j] > a and l1[j] > b:
			c = min(l[j] - a, l1[j] - b)
			l[j] -= c
			l1[j] -= c
			ctr += c
	for j in range(n):
		if l[j] > a:
			c = l[j] - a
			ctr += c
		if l1[j] > b:
			c = l1[j] - b
			ctr += c
	print(ctr)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().rstrip().rsplit()))
	b = list(map(int, input().rstrip().rsplit()))
	c = 0
	la = [a[i] - min(a) for i in range(n)]
	lb = [b[i] - min(b) for i in range(n)]
	for i in range(n):
		c += min(la[i], lb[i]) + abs(la[i] - lb[i])
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	a = a.split()
	b = input()
	b = b.split()
	for i in range(n):
		a[i] = int(a[i])
		b[i] = int(b[i])
	mina = min(a)
	minb = min(b)
	ans = 0
	for i in range(n):
		diffa = a[i] - mina
		diffb = b[i] - minb
		ans += min(diffa, diffb) + abs(diffa - diffb)
	print(ans)


t = int(input())
answer = []

def minpoo(c, o, minc, mino):
	return max(c - minc, o - mino)
for a in range(t):
	n = int(input())
	line1 = [int(i) for i in input().split()]
	line2 = [int(j) for j in input().split()]
	minc = min(line1)
	mino = min(line2)
	total = 0
	for i in range(n):
		total += minpoo(line1[i], line2[i], minc, mino)
	answer.append(total)
for b in answer:
	print(str(b))


testCases = int(input())
for _ in range(testCases):
	n = int(input())
	ara = list(map(int, input().split()))
	arb = list(map(int, input().split()))
	mina = min(ara)
	minb = min(arb)
	count = 0
	for (a, b) in zip(ara, arb):
		mx = max(a - mina, b - minb)
		count += mx
	print(count)


test = int(input())
for _ in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	op = 0
	for i in range(n):
		t = min(b[i] - minb, a[i] - mina)
		op += t
		op += b[i] - minb - t
		op += a[i] - mina - t
	print(op)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	ac = []
	bc = []
	c = 0
	for i in range(n):
		ac.append(a[i] - am)
		bc.append(b[i] - bm)
		c += min(ac[i], bc[i])
		c += abs(ac[i] - bc[i])
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	res = 0
	mn_a = min(a)
	mn_b = min(b)
	for i in range(n):
		res += max(abs(mn_a - a[i]), abs(mn_b - b[i]))
	print(res)


t = int(input())
while t > 0:
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	(mina, minb) = (min(a), min(b))
	cnt = 0
	for i in range(n):
		cnt += min(a[i] - mina, b[i] - minb)
		(l, r) = (a[i], b[i])
		a[i] -= min(l - mina, r - minb)
		b[i] -= min(l - mina, r - minb)
		cnt += a[i] - mina
		cnt += b[i] - minb
	print(cnt)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	min1 = min(l1)
	min2 = min(l2)
	count = 0
	for i in range(0, n):
		if l1[i] > min1 and l2[i] == min2:
			count += l1[i] - min1
		if l2[i] > min2 and l1[i] == min1:
			count += l2[i] - min2
		if l1[i] > min1 and l2[i] > min2:
			d1 = l1[i] - min1
			d2 = l2[i] - min2
			if d1 == d2:
				count += d1
			elif d1 > d2:
				count += d1
			else:
				count += d2
	print(count)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

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

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	n = val()
	a = li()
	b = li()
	ans = 0
	mina = min(a)
	minb = min(b)
	for i in range(n):
		lessa = a[i] - mina
		lessb = b[i] - minb
		ans += max(lessa, lessb)
	print(ans)


t = int(input())
answer = []
for i in range(t):
	count = 0
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	x = min(a)
	y = min(b)
	for k in range(n):
		if a[k] > x and b[k] > y:
			while a[k] > x and b[k] > y:
				if a[k] - x >= b[k] - y:
					count = count + abs(b[k] - y)
					a[k] = a[k] - abs(b[k] - y)
					b[k] = y
				else:
					count = count + abs(a[k] - x)
					b[k] = b[k] - abs(a[k] - x)
					a[k] = x
				break
		if a[k] > x:
			count = count + (a[k] - x)
			a[k] = x
		if b[k] > y:
			count = count + (b[k] - y)
			b[k] = y
	answer.append(count)
for item in answer:
	print(item)


import math
from itertools import combinations
from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xa = min(a)
	xb = min(b)
	for i in range(len(a)):
		a[i] = abs(a[i] - xa)
	for i in range(len(b)):
		b[i] = abs(b[i] - xb)
	res = 0
	for i in range(len(a)):
		res += max(a[i], b[i])
	print(res)


ntests = int(input())
for i in range(ntests):
	N = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(mina, minb) = map(min, [a, b])
	nmoves = 0
	for i in range(N):
		adif = a[i] - mina
		bdif = b[i] - minb
		if adif and bdif:
			nmoves += max((adif, bdif))
		else:
			nmoves += adif + bdif
	print(nmoves)


t = int(input())
l = []
for i in range(t):
	n = int(input())
	s1 = list(map(int, input().split()))
	s2 = list(map(int, input().split()))
	l.append([s1, s2])
for j in l:
	cmin = min(j[0])
	omin = min(j[1])
	c = 0
	for k in range(len(j[0])):
		if j[0][k] - cmin == 0 and j[1][k] - omin > 0:
			c += j[1][k] - omin
		elif j[0][k] - cmin > 0 and j[1][k] == omin:
			c += j[0][k] - cmin
		elif j[0][k] - cmin > 0 and j[1][k] - omin > 0:
			m = max([j[0][k] - cmin, j[1][k] - omin])
			c += m
	print(c)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	minnA = min(A)
	minnB = min(B)
	c = 0
	for i in range(N):
		A[i] = A[i] - minnA
	for j in range(N):
		B[j] = B[j] - minnB
	for k in range(N):
		c += max(A[k], B[k])
	print(c)


testList = []
for i in range(int(input())):
	input()
	testList.append([])
	testList[i].append([int(num) for num in input().split()])
	testList[i].append([int(num) for num in input().split()])
for i in testList:
	count = 0
	mins = [min(i[0]), min(i[1])]
	for j in range(len(i[0])):
		if min(i[0][j] - mins[0], i[1][j] - mins[1]) == i[0][j] - mins[0]:
			(choose1, choose2) = (0, 1)
		else:
			(choose1, choose2) = (1, 0)
		count += i[choose1][j] - mins[choose1]
		count += i[choose2][j] - mins[choose2] - (i[choose1][j] - mins[choose1])
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	steps_a = 0
	steps_b = 0
	steps = 0
	i = 0
	while i < n:
		steps_a = a[i] - min_a
		steps_b = b[i] - min_b
		steps += max(steps_a, steps_b)
		i += 1
	print(steps)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	a_min = min(a)
	b_min = min(b)
	count = 0
	i = 0
	for i in range(0, n):
		diff1 = a[i] - a_min
		diff2 = b[i] - b_min
		if diff1 > diff2:
			count = count + diff1
		else:
			count = count + diff2
	print(count)
	t = t - 1


import sys

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	b = get_array()
	mina = min(a)
	minb = min(b)
	c = 0
	for i in range(0, n):
		if mina == a[i]:
			c += b[i] - minb
		elif minb == b[i]:
			c += a[i] - mina
		else:
			k = a[i] - mina
			l = b[i] - minb
			m = min(k, l)
			c += m + abs(k - l)
	print(c)


for _ in range(int(input())):
	n = int(input())
	ca = list(map(int, input().split()))
	ora = list(map(int, input().split()))
	mi1 = min(ca)
	mi2 = min(ora)
	c = 0
	v1 = 0
	v2 = 0
	v3 = 0
	for i in range(n):
		if ca[i] >= mi1 and ora[i] >= mi2:
			v1 = ca[i] - mi1
			v2 = ora[i] - mi2
			v3 = min(v1, v2)
			c = c + v3 + abs(v1 - v2)
		elif ca[i] > mi1 and ora[i] < mi2:
			c += ca[i] - mi1
		elif ca[i] < mi1 and ora[i] > mi2:
			c = c + ora[i] - mi2
	print(c)


def solv():
	x = int(input())
	s = list(map(int, input().split()))
	z = list(map(int, input().split()))
	mna = min(s)
	mnb = min(z)
	res = 0
	for n in range(x):
		s[n] -= mna
		z[n] -= mnb
		res += max(s[n], z[n])
	print(res)
for _ in range(int(input())):
	solv()


t = int(input())
for _ in range(t):
	n = int(input())
	cnd = [int(i) for i in input().split()]
	org = [int(i) for i in input().split()]
	c_min = min(cnd)
	o_min = min(org)
	ans = 0
	for i in range(n):
		ans += max(cnd[i] - c_min, org[i] - o_min)
	print(ans)


def solve(a, b, ans):
	for i in range(n):
		if a[i] > minA and b[i] > minB:
			temp = min(a[i] - minA, b[i] - minB)
			a[i] -= temp
			b[i] -= temp
			ans += temp
			if a[i] > minA:
				ans += a[i] - minA
				a[i] = minA
			if b[i] > minB:
				ans += b[i] - minB
				b[i] = minB
		elif a[i] > minA:
			ans += a[i] - minA
			a[i] = minA
		elif b[i] > minB:
			ans += b[i] - minB
			b[i] = minB
	return ans
T = int(input())
for z in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	minA = min(A)
	minB = min(B)
	ans = solve(A, B, 0)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = a[0]
	minb = b[0]
	for i in range(n):
		if mina > a[i]:
			mina = a[i]
		if minb > b[i]:
			minb = b[i]
	sum = 0
	for i in range(n):
		xa = a[i] - mina
		xb = b[i] - minb
		sum += max(xa, xb)
	print(sum)


for _ in range(int(input())):
	n = int(input())
	alist = list(map(int, input().split()))
	blist = list(map(int, input().split()))
	amin = min(alist)
	bmin = min(blist)
	count = 0
	for i in range(n):
		count += max(alist[i] - amin, blist[i] - bmin)
	print(count)


def solve(a, b):
	(x, y) = (min(a), min(b))
	ans = 0
	for i in range(len(a)):
		ans += max(a[i] - x, b[i] - y)
	return ans
T = int(input())
while T > 0:
	T -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(a, b))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cost = 0
	(ma, mb) = (min(a), min(b))
	for i in range(n):
		c_a = a[i] - ma
		c_b = b[i] - mb
		cost += max(c_a, c_b)
	print(cost)


t = int(input())
for l in range(t):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	b = list(map(int, input().strip().split(' ')))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		ans += max(a[i] - amin, b[i] - bmin)
	print(ans)


from array import array
for _ in range(int(input())):
	n = int(input())
	a = array('i', [int(x) for x in input().split()])
	b = array('i', [int(x) for x in input().split()])
	min_a = min(a)
	min_b = min(b)
	cnt = 0
	for i in range(n):
		a[i] -= min_a
		b[i] -= min_b
		cnt += max(a[i], b[i])
	print(cnt)


t = int(input())
for _ in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	min1 = min(arr1)
	min2 = min(arr2)
	total = 0
	for x in range(len(arr1)):
		reduced = min(arr1[x] - min1, arr2[x] - min2)
		total += arr1[x] - reduced - min1 + (arr2[x] - reduced - min2) + reduced
	print(total)


T = int(input())
for _ in range(T):
	N = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minA = min(a)
	minB = min(b)
	cnt = 0
	for i in range(N):
		if a[i] > minA and b[i] > minB:
			which = min(abs(a[i] - minA), abs(b[i] - minB))
			cnt += which
			a[i] -= which
			b[i] -= which
			cnt += a[i] - minA + b[i] - minB
			continue
		if a[i] > minA:
			cnt += a[i] - minA
			continue
		if b[i] > minB:
			cnt += b[i] - minB
			continue
	print(cnt)


for case in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	mna = min(a)
	mnb = min(b)
	for ix in range(n):
		ans += max(a[ix] - mna, b[ix] - mnb)
	print(ans)


t = int(input())
for o in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	cnt = 0
	for i in range(n):
		if a[i] > x and b[i] > y:
			cnt += min(a[i] - x, b[i] - y)
			m = min(a[i] - x, b[i] - y)
			a[i] -= m
			b[i] -= m
			cnt += a[i] - x
			cnt += b[i] - y
		elif a[i] > x:
			cnt += a[i] - x
			a[i] -= a[i] - x
		elif b[i] > y:
			cnt += b[i] - y
			b[i] -= b[i] - y
	print(cnt)


import math
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()]
	mina = min(a)
	minb = min(b)
	move = 0
	for i in range(N):
		move += max(a[i] - mina, b[i] - minb)
	print(move)
	T -= 1


for _ in range(int(input())):
	k = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	am = min(a)
	bm = min(b)
	steps = 0
	for i in range(k):
		steps += max(a[i] - am, b[i] - bm)
	print(steps)


t = int(input().split()[0])
for i in range(t):
	_ = input()
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	(mia, mib) = (min(a), min(b))
	eat = 0
	for (a_, b_) in zip(a, b):
		eat2 = min(a_ - mia, b_ - mib)
		eat += eat2
		eat += a_ - eat2 - mia + (b_ - eat2 - mib)
	print(eat)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	c = 0
	i = 0
	while i < len(a):
		c += max(a[i] - m1, b[i] - m2)
		i += 1
	print(c)


def get_answer(a, b):
	necessary_a = min(a)
	necessary_b = min(b)
	actions = 0
	for (curr_a, curr_b) in zip(a, b):
		a_to_eat = curr_a - necessary_a
		b_to_eat = curr_b - necessary_b
		ab_to_eat = min(a_to_eat, b_to_eat)
		a_to_eat -= ab_to_eat
		b_to_eat -= ab_to_eat
		actions += ab_to_eat + a_to_eat + b_to_eat
	return actions

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = tuple(map(int, input().split()))
		b = tuple(map(int, input().split()))
		min_actions = get_answer(a, b)
		print(min_actions)
main()


import math
t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	op = 0
	for i in range(n):
		x1 = a[i] - amin if a[i] - amin > 0 else 0
		x2 = b[i] - bmin if b[i] - bmin > 0 else 0
		d = x1 if x1 > x2 else x2
		op = op + d
	t = t - 1
	print(op)


for t in range(int(input())):
	n = int(input())
	aa = [int(x) for x in input().split()]
	bb = [int(x) for x in input().split()]
	ma = min(aa)
	mb = min(bb)
	na = [a - ma for a in aa]
	nb = [b - mb for b in bb]
	res = 0
	for i in range(n):
		res += na[i] if na[i] > nb[i] else nb[i]
	print(res)


import sys

def gifts_fixing(arr, brr):
	tot_moves = 0
	a_min = min(arr)
	b_min = min(brr)
	for i in range(len(arr)):
		if arr[i] == a_min and brr[i] == b_min:
			continue
		if arr[i] == a_min:
			tot_moves += brr[i] - b_min
		if brr[i] == b_min:
			tot_moves += arr[i] - a_min
		if arr[i] != a_min and brr[i] != b_min:
			tot_moves += max(arr[i] - a_min, brr[i] - b_min)
	return tot_moves
t = int(sys.stdin.readline().rstrip())
sol = []
for i in range(t):
	n = int(sys.stdin.readline().rstrip())
	arr = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
	brr = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
	sol.append(gifts_fixing(arr, brr))
for s in sol:
	print(s)


t = int(input())
while t:
	n = int(input())
	can = list(map(int, input().split()))
	org = list(map(int, input().split()))
	ans = 0
	can_m = min(can)
	org_m = min(org)
	for (c, o) in zip(can, org):
		ans += max(c - can_m, o - org_m)
	print(ans)
	t -= 1


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()]
	ma = min(a)
	mb = min(b)
	moves = 0
	for i in range(N):
		da = a[i] - ma
		db = b[i] - mb
		dx = max(da, db)
		moves += dx
	print(moves)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_k = min(a)
	b_k = min(b)
	result = 0
	for i in range(n):
		a1 = a[i] - a_k
		b1 = b[i] - b_k
		result += max(a1, b1)
	print(result)


c = int(input())
for i in range(c):
	d = int(input())
	a = [int(x) for x in input().split()]
	b = [int(y) for y in input().split()]
	aMin = min(a)
	bMin = min(b)
	ans = 0
	for i in range(len(a)):
		f = g = 0
		if a[i] != aMin:
			f = a[i] - aMin
		if b[i] != bMin:
			g = b[i] - bMin
		if f == g:
			ans += f
		elif f > g:
			ans += f
		elif g > f:
			ans += g
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	MINA = min(A)
	MINB = min(B)
	ANS = 0
	for i in range(n):
		a = A[i]
		b = B[i]
		aa = a - MINA
		bb = b - MINB
		ANS += max(aa, bb)
	print(ANS)


x = int(input())
for _ in range(x):
	n = int(input())
	eles_1 = [int(num) for num in input().split(' ')]
	eles_2 = [int(num) for num in input().split(' ')]
	min_1 = min(eles_1)
	min_2 = min(eles_2)
	counter = 0
	for i in range(len(eles_1)):
		a = eles_1[i] - min_1
		b = eles_2[i] - min_2
		if a > b:
			counter += b + a - b
		elif b > a:
			counter += a + b - a
		else:
			counter += a
	print(counter)


arr = lambda : list(map(int, input().split()))
t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = arr()
	b = arr()
	st = 0
	for i in range(n):
		st += max(a[i] - min(a), b[i] - min(b))
	print(st)


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
input = sys.stdin.readline
mo = 10 ** 9 + 7

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

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

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	n = inin()
	a = ain()
	b = ain()
	newa = [0] * n
	newb = [0] * n
	mia = min(a)
	mib = min(b)
	c1 = c2 = 0
	for i in range(n):
		c1 += a[i] - mia
		if b[i] > mib:
			newb[i] = max(mib, b[i] - a[i] + mia)
		else:
			newb[i] = b[i]
	for i in range(n):
		if newb[i] > mib:
			c1 += newb[i] - mib
	for i in range(n):
		c2 += b[i] - mib
		if a[i] > mia:
			newa[i] = max(mia, a[i] - b[i] + mib)
		else:
			newa[i] = a[i]
	for i in range(n):
		if newa[i] > mia:
			c2 += newa[i] - mia
	print(min(c1, c2))


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minA = min(a)
	minB = min(b)
	moves = 0
	for (ai, bi) in zip(a, b):
		moves += max(ai - minA, bi - minB)
	print(moves)


t = int(input())
for _ in range(t):
	n = int(input())
	ais = list(map(int, input().split()))
	bis = list(map(int, input().split()))
	mina = min(ais)
	minb = min(bis)
	count = 0
	for (a, b) in zip(ais, bis):
		count += max(a - mina, b - minb)
	print(count)


t = int(input())
for j in range(t):
	n = int(input())
	a = [0] * n
	b = [0] * n
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	MinCan = min(a)
	MinOr = min(b)
	ans = 0
	for i in range(n):
		if b[i] != MinOr and a[i] == MinCan:
			ans += b[i] - MinOr
		if b[i] == MinOr and a[i] != MinCan:
			ans += a[i] - MinCan
		if b[i] != MinOr and a[i] != MinCan:
			ans += max(a[i] - MinCan, b[i] - MinOr)
	print(ans)


o = int(input())
for i in range(o):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	change_a = []
	change_b = []
	for i in range(0, len(a)):
		change_a.append(a[i] - min_a)
		change_b.append(b[i] - min_b)
	sum = 0
	for i in range(0, len(a)):
		sum += max(change_a[i], change_b[i])
	print(sum)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	moves = 0
	for i in range(n):
		if a[i] > amin and b[i] > bmin:
			moves += abs(a[i] - amin - (b[i] - bmin)) + min(a[i] - amin, b[i] - bmin)
		elif a[i] > amin:
			moves += a[i] - amin
		elif b[i] > bmin:
			moves += b[i] - bmin
	print(moves)
	t -= 1


for _ in range(int(input())):
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	x = min(a)
	y = min(b)
	moves = 0
	for i in range(n):
		diff = min(a[i] - x, b[i] - y)
		moves += diff
		a[i] -= diff
		b[i] -= diff
		moves += a[i] - x
		moves += b[i] - y
	print(moves)


import sys
exec("try:sys.stdin=open('in.txt','r');sys.stdout=open('out.txt','w')\nexcept:pass")

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

def Num():
	return int(input())

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

def diff(a, x):
	ans = []
	for i in range(len(a)):
		ans.append(a[i] - x)
	return ans

def calc(a, b):
	ans = 0
	for i in range(len(a)):
		temp = min(a[i], b[i])
		ans += temp
		ans += a[i] - temp
		ans += b[i] - temp
	return ans

def solve():
	n = Num()
	a = List()
	b = List()
	(diffa, diffb) = (diff(a, min(a)), diff(b, min(b)))
	(fdiffa, fdiffb) = (diff(a, min(min(a), min(b))), diff(b, min(min(a), min(b))))
	print(min(calc(diffa, diffb), calc(fdiffa, fdiffb)))
for _ in range(Num()):
	solve()


for q in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	Min = min(a)
	res = 0
	Move = [0] * n
	for i in range(n):
		res += a[i] - Min
		Move[i] += a[i] - Min
	Min = min(b)
	for i in range(n):
		res += max(b[i] - Min - Move[i], 0)
	print(res)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	m = 0
	for i in range(n):
		if a[i] != amin and b[i] != bmin:
			m += min(a[i] - amin, b[i] - bmin)
			tmp = max(a[i] - amin, b[i] - bmin) - min(a[i] - amin, b[i] - bmin)
			m += tmp
		elif a[i] != amin:
			m += a[i] - amin
		elif b[i] != bmin:
			m += b[i] - bmin
	print(m)


import sys
t = int(input())
for i in range(0, t):
	n = int(input())
	orange = [int(item) for item in input().split(' ')]
	candy = [int(item) for item in input().split(' ')]
	orange_min = 10 ** 9
	candy_min = 10 ** 9
	for (item1, item2) in zip(orange, candy):
		orange_min = min(orange_min, item1)
		candy_min = min(candy_min, item2)
	minimum = 0
	for (item1, item2) in zip(orange, candy):
		if item1 != orange_min:
			if item2 != candy_min:
				minimum += max(item1 - orange_min, item2 - candy_min)
			else:
				minimum += item1 - orange_min
		elif item2 != candy_min:
			minimum += item2 - candy_min
	print(minimum)


def solution():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	minA = min(a)
	minB = min(b)
	count = 0
	for i in range(n):
		count += max(a[i] - minA, b[i] - minB)
	print(count)
T = int(input())
while T:
	solution()
	T -= 1


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	(a, b) = (min(l1), min(l2))
	s = 0
	for i in range(len(l1)):
		s += max(l1[i] - a, l2[i] - b)
	print(s)


t = int(input().split()[0])
for case in range(t):
	n = int(input().split()[0])
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	la = min(a)
	lb = min(b)
	(da, db) = ([], [])
	for el in a:
		da.append(el - la)
	for el in b:
		db.append(el - lb)
	ans = 0
	for i in range(n):
		ans += max(da[i], db[i])
	print(ans)


for i in range(int(input())):
	n = int(input())
	(a, b) = ([int(elem) for elem in input().split()], [int(elem) for elem in input().split()])
	(min_a, min_b) = (min(a), min(b))
	counter = 0
	for i in range(n):
		m = min(a[i] - min_a, b[i] - min_b)
		a[i] -= m
		b[i] -= m
		counter += m
		counter += b[i] - min_b
		counter += a[i] - min_a
	print(counter)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	A = list(map(int, sys.stdin.readline().split()))
	B = list(map(int, sys.stdin.readline().split()))
	ma = min(A)
	mb = min(B)
	count = 0
	for i in range(n):
		fa = A[i] - ma
		fb = B[i] - mb
		count += max(fa, fb)
	print(count)


n = int(input())
while n > 0:
	t = int(input())
	flag = 0
	arr1 = input().split(' ')
	arr2 = input().split(' ')
	arr1 = list(map(int, arr1))
	arr2 = list(map(int, arr2))
	min_a = min(arr1)
	min_b = min(arr2)
	for i in range(t):
		flag += max(int(arr1[i]) - int(min_a), int(arr2[i]) - int(min_b))
	print(flag)
	n = n - 1


import sys, math, collections
from collections import defaultdict

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

def get_array():
	l = list(map(int, input().split()))
	return l

def get_2_ints():
	(a, b) = map(int, input().split())
	return (a, b)

def get_3_ints():
	(a, b, c) = map(int, input().split())
	return (a, b, c)

def sod(n):
	(n, c) = (str(n), 0)
	for i in n:
		c += int(i)
	return c

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 getFloor(A, x):
	(left, right) = (0, len(A) - 1)
	floor = -1
	while left <= right:
		mid = (left + right) // 2
		if A[mid] == x:
			return A[mid]
		elif x < A[mid]:
			right = mid - 1
		else:
			floor = A[mid]
			left = mid + 1
	return floor

def floorSqrt(x):
	if x == 0 or x == 1:
		return x
	start = 1
	end = x
	while start <= end:
		mid = (start + end) // 2
		if mid * mid == x:
			return mid
		if mid * mid < x:
			start = mid + 1
			ans = mid
		else:
			end = mid - 1
	return ans

def main():
	for tt in range(int(input())):
		n = int(input())
		a = get_array()
		b = get_array()
		(p, q) = (min(a), min(b))
		c = 0
		for i in range(n):
			if a[i] == p and b[i] != q:
				c += b[i] - q
			elif a[i] != p and b[i] == q:
				c += a[i] - p
			elif a[i] == p and b[i] == q:
				continue
			else:
				temp = min(a[i] - p, b[i] - q)
				c += temp
				a[i] -= temp
				b[i] -= temp
				c += a[i] - p
				c += b[i] - q
		print(c)
main()


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 0
	(m1, m2) = (min(a), min(b))
	for i in range(len(a)):
		x = a[i] - m1
		y = b[i] - m2
		s = s + max(x, y)
	print(s)
	t -= 1


for t in range(int(input())):
	n = int(input())
	F = [int(i) for i in input().split()]
	P = [int(i) for i in input().split()]
	a = min(F)
	b = min(P)
	count = 0
	for i in range(len(F)):
		a1 = F[i] - a
		b1 = P[i] - b
		if a1 > b1:
			count += a1
		else:
			count += b1
	print(count)


from math import *
t = int(input())
for k in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	list_1 = sorted(l1)
	list_2 = sorted(l2)
	s1 = 0
	s2 = 0
	for i in range(1, n, 1):
		s1 = s1 + (list_1[i] - list_1[0])
	for j in range(1, n, 1):
		s2 = s2 + (list_2[j] - list_2[0])
	sum = s1 + s2
	move = 0
	for l in range(0, n, 1):
		lowest_1 = list_1[0]
		lowest_2 = list_2[0]
		dif1 = l1[l] - list_1[0]
		dif2 = l2[l] - list_2[0]
		val = min(dif1, dif2)
		move = move + val
	print(sum - move)


t = int(input())
for i in range(t):
	n = int(input())
	candies = list(map(int, input().split(' ')))
	oranges = list(map(int, input().split(' ')))
	minC = min(candies)
	minO = min(oranges)
	ans = 0
	for i in range(len(candies)):
		ans += max(candies[i] - minC, oranges[i] - minO)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(min_a, min_b) = (min(a), min(b))
	ans = 0
	for j in range(len(a)):
		if a[j] > min_a and b[j] > min_b:
			tem = min(a[j] - min_a, b[j] - min_b)
			a[j] -= tem
			b[j] -= tem
			ans += tem
		if a[j] > min_a:
			ans += a[j] - min_a
			a[j] = min_a
		if b[j] > min_b:
			ans += b[j] - min_b
			b[j] = min_b
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	x = min(l1)
	y = min(l2)
	c = 0
	for i in range(n):
		a = l1[i] - x
		b = l2[i] - y
		c += min(a, b) + abs(a - b)
	print(c)


def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	(mina, minb) = (min(a), min(b))
	ans = 0
	for i in range(n):
		if a[i] == mina and b[i] == minb:
			continue
		if a[i] == mina and b[i] != minb or (a[i] != mina and b[i] == minb):
			ans += a[i] - mina + (b[i] - minb)
		else:
			r = min(a[i] - mina, b[i] - minb)
			ans += r
			ans += a[i] - mina - r + b[i] - minb - r
	return ans
t = int(input())
ans = []
while t:
	ans.append(str(solve()))
	t -= 1
print('\n'.join(ans))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	count = 0
	for i in range(n):
		a1 = a[i] - amin
		b1 = b[i] - bmin
		count += a1 + b1 - min(a1, b1)
	print(count)


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()]
	mina = min(a)
	minb = min(b)
	moves = 0
	for i in range(n):
		movea = 0
		moveb = 0
		if a[i] > mina:
			movea = a[i] - mina
		if b[i] > minb:
			moveb = b[i] - minb
		if movea >= moveb:
			moves += movea
		else:
			moves += moveb
	print(moves)


t = int(input())
i = 0
while i < t:
	n = int(input())
	l = [int(x) for x in input().split()]
	l1 = [int(x) for x in input().split()]
	a = min(l)
	b = min(l1)
	s = 0
	for x in range(n):
		m = max(l[x] - a, l1[x] - b)
		s = s + m
	print(s)
	i += 1


t = int(input())
while t > 0:
	t -= 1
	ans = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	for i in range(n):
		c_a = a[i] - ma
		c_b = b[i] - mb
		if a[i] > ma and b[i] > mb:
			ans += max(c_a, c_b)
		elif a[i] > ma:
			ans += c_a
		elif b[i] > mb:
			ans += c_b
	print(ans)


def performOperations(a, b):
	minimum_a = min(a)
	minimum_b = min(b)
	op = 0
	for i in range(n):
		if a[i] - minimum_a >= b[i] - minimum_b:
			op += a[i] - minimum_a
		else:
			op += b[i] - minimum_b
	print(op)
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()))
	performOperations(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()))
	min_a = min(a)
	min_b = min(b)
	c = 0
	for (x, y) in zip(a, b):
		both = min(x - min_a, y - min_b)
		c += both
		x -= both
		y -= both
		if x > min_a:
			c += x - min_a
		if y > min_b:
			c += y - min_b
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	al = min(a)
	bl = min(b)
	for i in range(n):
		areq = a[i] - al
		breq = b[i] - bl
		if areq == 0:
			c += breq
		elif breq == 0:
			c += areq
		elif areq == breq:
			c += areq
		elif areq > breq:
			c += breq + (areq - breq)
		else:
			c += areq + (breq - areq)
	print(c)


Z = int(input())
for Y in range(Z):
	x = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	a1 = min(arr1)
	a2 = min(arr2)
	c = 0
	for (b1, b2) in zip(arr1, arr2):
		if b1 - a1 > b2 - a2:
			c += b1 - a1
		else:
			c += b2 - a2
	print(c)


from math import *
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	m1 = min(a)
	b = list(map(int, input().split()))
	m2 = min(b)
	s = 0
	s1 = 0
	total = 0
	for j in range(n):
		s += a[j] - m1
		s1 += b[j] - m2
		total += max(a[j] - m1, b[j] - m2)
	print(total)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = min(a)
	y = min(b)
	p = 0
	ans = 0
	while p < len(a):
		if a[p] > x and b[p] > y:
			diff = min(a[p] - x, b[p] - y)
			extra = max(a[p] - x, b[p] - y) - diff
			ans = ans + diff + extra
		elif a[p] > x and b[p] <= y:
			ans = ans + a[p] - x
		elif b[p] > y and a[p] <= x:
			ans = ans + b[p] - y
		p = p + 1
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	diffa = 0
	diffb = 0
	for i in range(n):
		diffa += a[i] - mina
		diffb += b[i] - minb
	sumab = diffa + diffb
	c = 0
	for k in range(n):
		if a[k] > mina and b[k] > minb:
			c += min(a[k] - mina, b[k] - minb)
	print(sumab - c)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	m = min(l)
	m1 = min(l1)
	sum = 0
	s = 0
	s1 = 0
	for i in range(n):
		s = abs(l[i] - m)
		s1 = abs(l1[i] - m1)
		sum += max(s, s1)
	print(sum)


t = int(input())
for z in range(t):
	n = int(input())
	a = [int(q) for q in input().split()]
	b = [int(q) for q in input().split()]
	c = min(a)
	d = min(b)
	m = 0
	for i in range(n):
		m += max(a[i] - c, b[i] - d)
	print(m)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	c = 0
	for i in range(0, len(a)):
		ha = a[i] - ma
		hb = b[i] - mb
		c = c + max(ha, hb)
	print(c)


for _ in range(int(input())):
	n = int(input())
	c = [int(x) for x in input().split()]
	o = [int(x) for x in input().split()]
	c_min = min(c)
	o_min = min(o)
	gift = []
	for i in range(n):
		gift.append([c[i], o[i]])
	count = 0
	for i in range(n):
		dif_c = gift[i][0] - c_min
		dif_o = gift[i][1] - o_min
		count += min(dif_c, dif_o)
		count += abs(dif_c - dif_o)
	print(count)


a = int(input())
for i in range(a):
	mc = 10000000000
	md = 10000000000
	s = 0
	b = int(input())
	c = input().split()
	d = input().split()
	for j in range(b):
		if int(c[j]) < mc:
			mc = int(c[j])
		if int(d[j]) < md:
			md = int(d[j])
	for j in range(b):
		s += max(int(c[j]) - mc, int(d[j]) - md)
	print(s)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	c = 0
	for i in range(n):
		if a[i] > m1 and b[i] > m2:
			k = a[i] - m1
			p = b[i] - m2
			key = min(k, p)
			a[i] = a[i] - key
			b[i] = b[i] - key
			c = c + key
		if a[i] > m1:
			c = c + (a[i] - m1)
		if b[i] > m2:
			c = c + (b[i] - m2)
	print(c)
	t = t - 1


from sys import stdin, stdout
from collections import Counter
from math import ceil
from bisect import bisect_left
from bisect import bisect_right
import math
ai = lambda : list(map(int, stdin.readline().split()))
ei = lambda : map(int, stdin.readline().split())
ip = lambda : int(stdin.readline().strip())
for i in range(ip()):
	n = ip()
	candy = ai()
	orange = ai()
	candy_min = min(candy)
	orange_min = min(orange)
	ans = 0
	for i in range(n):
		MIN = min(candy[i] - candy_min, orange[i] - orange_min)
		ans += MIN
		candy[i] -= MIN
		orange[i] -= MIN
		if candy[i] != candy_min:
			ans += candy[i] - candy_min
		if orange[i] != orange_min:
			ans += orange[i] - orange_min
	print(ans)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	candies = list(map(int, stdin.readline().split()))
	oranges = list(map(int, stdin.readline().split()))
	mo = min(oranges)
	mc = min(candies)
	count = 0
	for i in range(n):
		count += max(candies[i] - mc, oranges[i] - mo)
	stdout.write(str(count) + '\n')


for test_i in range(int(input())):
	n = int(input())
	(arr1, arr2) = (list(map(int, input().split())), list(map(int, input().split())))
	(min1, min2) = (min(arr1), min(arr2))
	ans = 0
	for i in range(n):
		ans += max(arr1[i] - min1, arr2[i] - min2)
	print(ans)


try:
	t = int(input())
	for i1 in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		amin = min(a)
		bmin = min(b)
		c = 0
		for i in range(n):
			x = a[i] - amin
			y = b[i] - bmin
			c = c + max(x, y)
		print(c)
except:
	pass


import math
from sys import stdin, stdout
from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	mini1 = min(l1)
	mini2 = min(l2)
	c = 0
	for i in range(n):
		if l1[i] > mini1 or l2[i] > mini2:
			c += max(l1[i] - mini1, l2[i] - mini2)
	print(c)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	amin = min(arr)
	bmin = min(brr)
	moves = 0
	for i in range(0, len(arr)):
		if arr[i] > amin and brr[i] > bmin:
			dono = min(arr[i] - amin, brr[i] - bmin)
			arr[i] -= dono
			brr[i] -= dono
			moves += dono
		if arr[i] > amin:
			moves += arr[i] - amin
		if brr[i] > bmin:
			moves += brr[i] - bmin
	print(moves)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(v) for v in input().split()]
	b = [int(v) for v in input().split()]
	p = min(a)
	q = min(b)
	c = 0
	for j in range(n):
		x = a[j] - p
		y = b[j] - q
		z = min(x, y)
		c = c + z
		c = c + x - z + y - z
	print(c)


integers = int(input())
for i in range(0, integers):
	inte = int(input())
	list1 = input().split(' ')
	list2 = input().split(' ')
	list1 = list(map(int, list1))
	list2 = list(map(int, list2))
	a = min(list1)
	b = min(list2)
	list1 = list(map(lambda x: x - a, list1))
	list2 = list(map(lambda x: x - b, list2))
	min_no = 0
	for i in range(inte):
		min_no += list1[i] if list1[i] > list2[i] else list2[i] if list1[i] < list2[i] else list1[i]
	print(min_no)


t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	a = min(l1)
	b = min(l2)
	c = 0
	for i in range(n):
		c += max(l1[i] - a, l2[i] - b)
	print(c)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = int(input())
for i in range(t):
	input()
	sum = 0
	candy = list(map(int, input().split()))
	orange = list(map(int, input().split()))
	for i in range(len(candy)):
		sum += max(candy[i] - min(candy), orange[i] - min(orange))
	print(sum)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	mn = min(a)
	mn1 = min(b)
	ans = 0
	for i in range(n):
		v = a[i] - mn
		vv = b[i] - mn1
		ans += max(v, vv)
	print(ans)


t = int(input())
for count in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mi = 10 ** 9
	me = 10 ** 9
	ans = 0
	for i in range(n):
		if a[i] < mi:
			mi = a[i]
		if b[i] < me:
			me = b[i]
	for i in range(n):
		if a[i] - mi > b[i] - me:
			ans += b[i] - me
			ans += a[i] - mi - b[i] + me
		else:
			ans += a[i] - mi
			ans += b[i] - me - a[i] + mi
	print(ans)


def equalize(candies, oranges):
	l_candy = min(candies)
	l_orange = min(oranges)
	moves = 0
	for (i, j) in zip(candies, oranges):
		if i > l_candy and j > l_orange:
			eat_both = min(i - l_candy, j - l_orange)
			moves += eat_both
			i -= eat_both
			j -= eat_both
		if i > l_candy:
			moves += i - l_candy
		if j > l_orange:
			moves += j - l_orange
	return moves
t = int(input())
for t_itr in range(t):
	n = int(input())
	candies = list(map(int, input().rstrip().split()))
	oranges = list(map(int, input().rstrip().split()))
	result = equalize(candies, oranges)
	print(result)


import sys

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 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = LIST()
	B = LIST()
	amn = min(A)
	bmn = min(B)
	for i in range(N):
		A[i] -= amn
		B[i] -= bmn
	ans = 0
	for i in range(N):
		ans += max(A[i], B[i])
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a_min = min(a)
	b_min = min(b)
	res = 0
	for i in range(n):
		dif_a = a[i] - a_min
		dif_b = b[i] - b_min
		res += min(dif_a, dif_b) + abs(dif_a - dif_b)
	print(res)


def solve(a, b, n):
	(x1, x2) = (min(a), min(b))
	z = min(x1, x2)
	ans = 0
	for i in range(n):
		if a[i] > z and b[i] > z:
			m = min(a[i] - z, b[i] - z)
			ans += m
			a[i] = a[i] - m
			b[i] = b[i] - m
		if a[i] > x1:
			ans += a[i] - x1
		if b[i] > x2:
			ans += b[i] - x2
	return ans

def main():
	for _ 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)
main()


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	amin = min(a)
	bmin = min(b)
	acount = []
	bcount = []
	for i in range(n):
		acount.append(a[i] - amin)
		bcount.append(b[i] - bmin)
	count = 0
	for i in range(n):
		count += max(acount[i], bcount[i])
	print(count)


t = int(input())
for i in range(t):
	l = []
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	mina = min(a)
	minb = min(b)
	for i in range(n):
		a[i] = a[i] - mina
		b[i] = b[i] - minb
		l.append(max(a[i], b[i]))
	print(sum(l))


def f(k, a):
	step = 0
	km = min(k)
	am = min(a)
	for i in range(len(a)):
		uk = k[i] - km
		ua = a[i] - am
		step += min(ua, uk)
		step += max(ua, uk) - min(ua, uk)
	print(step)
t = int(input())
for i in range(t):
	input()
	a = tuple(map(int, input().split()))
	k = tuple(map(int, input().split()))
	f(a, k)


import math
from sys import stdin, stdout
import bisect
m = 10 ** 9 + 7

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

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

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

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

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

def bexp(n, p):
	r = 1
	while p > 0:
		if p % 2:
			r = r * n
			p = p - 1
		else:
			n = n ** 2
			p = p // 2
	return r

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

def sieve(limit):
	l = [1] * (limit + 1)
	l[0] = 0
	l[1] = 0
	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 segs(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 code():
	n = inp()
	l = inpli()
	k = inpli()
	p = min(l)
	q = min(k)
	c = 0
	for i in range(n):
		if l[i] != p and k[i] != q:
			a = l[i] - p
			b = k[i] - q
			z = min(a, b)
			c = c + z
			a = a - z
			b = b - z
			c = c + max(a, b)
		else:
			c = c + max(l[i] - p, k[i] - q)
	print(c)
	return
for _ in range(inp()):
	code()


t = int(input())
while t > 0:
	t -= 1
	count = input()
	a = input().split(' ')
	b = input().split(' ')

	def processor(f):
		n = 0
		for _ in f:
			f[n] = int(_)
			n += 1
		e = []
		for _ in f:
			e.append(_)
		e.sort()
		n = 0
		e = e[0]
		for _ in f:
			f[n] = _ - e
			n += 1
		return f
	a = processor(a)
	b = processor(b)
	n = 0
	pre_answer = []
	while n < len(a):
		if a[n] > b[n]:
			pre_answer.append(a[n])
		else:
			pre_answer.append(b[n])
		n += 1
	answer = 0
	for _ in pre_answer:
		answer += _
	print(answer)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aa = min(a)
	bb = min(b)
	ans = 0
	for j in range(n):
		ans += max(a[j] - aa, b[j] - bb)
	print(ans)


t = int(input())
for case in range(t):
	n = int(input())
	A = [int(x) for x in input().split(' ')]
	B = [int(x) for x in input().split(' ')]
	(a, b) = (min(A), min(B))
	suma = 0
	for i in range(n):
		suma += max(A[i] - a, B[i] - b)
	print(suma)


def gifts_fixing(A, B, n):
	a_min = min(A)
	b_min = min(B)
	ans = 0
	for i in range(n):
		if A[i] != a_min or B[i] != b_min:
			if A[i] != a_min and B[i] == b_min:
				ans = ans + A[i] - a_min
			elif A[i] == a_min and B[i] != b_min:
				ans = ans + B[i] - b_min
			else:
				m1 = B[i] - b_min
				m2 = A[i] - a_min
				if m1 <= m2:
					ans = ans + m1 + m2 - m1
				else:
					ans = ans + m2 + m1 - m2
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split(' ')))
	B = list(map(int, input().split(' ')))
	print(gifts_fixing(A, B, n))


t = int(input())
for _ in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_candies = min(candies)
	min_oranges = min(oranges)
	moves = 0
	for i in range(n):
		r_candies = 0
		r_oranges = 0
		if candies[i] > min_candies:
			r_candies = candies[i] - min_candies
		if oranges[i] > min_oranges:
			r_oranges = oranges[i] - min_oranges
		moves += max(r_oranges, r_candies)
	print(moves)


t = int(input())
for _ in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	ans = 0
	min1 = min(arr1)
	min2 = min(arr2)
	for i in range(n):
		if arr1[i] > min1 or arr2[i] > min2:
			temp1 = 0
			temp2 = 0
			if arr1[i] > min1:
				temp1 = arr1[i] - min1
			if arr2[i] > min2:
				temp2 = arr2[i] - min2
			ans += max(temp1, temp2)
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		ac = a[i] - amin
		bc = b[i] - bmin
		ans += max(ac, bc)
	print(ans)


t = int(input())
x = 0
while x < t:
	n = int(input())
	a = []
	b = []
	a = input().split()
	a = [int(j) for j in a]
	b = input().split()
	b = [int(j) for j in b]
	i1 = a.index(min(a))
	i2 = b.index(min(b))
	count = 0
	for i in range(0, n):
		d1 = a[i] - a[i1]
		d2 = b[i] - b[i2]
		if d1 > 0 and d2 > 0:
			if d1 > d2:
				count = count + d1
			else:
				count = count + d2
		elif d1 > 0:
			count = count + d1
		elif d2 > 0:
			count = count + d2
		else:
			pass
	print(count)
	x = x + 1


def invr():
	return list(map(int, input().split()))
n = int(input())
for x in range(n):
	t = int(input())
	A = invr()
	B = invr()
	minA = min(A)
	minB = min(B)
	move = 0
	for y in range(t):
		if A[y] != minA and B[y] != minB:
			diff1 = A[y] - minA
			diff2 = B[y] - minB
			A[y] -= min(diff1, diff2)
			B[y] -= min(diff1, diff2)
			move += min(diff1, diff2)
		if A[y] != minA:
			move += A[y] - minA
			A[y] = minA
		if B[y] != minB:
			move += B[y] - minB
			B[y] = minB
	print(move)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	p = min(a)
	q = min(b)
	m = []
	count = 0
	for i in range(n):
		m.append([a[i], b[i]])
	for j in range(n):
		count += max(m[j][0] - p, m[j][1] - q)
	print(count)


def solve(x):
	for i in range(1, len(x)):
		if abs(x[i] - x[i - 1] > 1):
			return 'NO'
	return 'YES'
cases = int(input())
for i in range(cases):
	size = int(input())
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	mina = min(a)
	minb = min(b)
	suma = 0
	for (i, j) in zip(a, b):
		suma += min(i - mina, j - minb) + abs(i - mina - (j - minb))
	print(suma)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	am = min(a)
	bm = min(b)
	i = 0
	ans = 0
	while i < n:
		x = a[i] - am
		y = b[i] - bm
		ans += x
		ans += y
		ans -= min(x, y)
		i += 1
	print(ans)


x = int(input())
for i in range(x):
	y = int(input())
	result = 0
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	m1 = min(a)
	m2 = min(b)
	for i in range(len(a)):
		if a[i] > m1:
			result += a[i] - m1
			b[i] -= a[i] - m1
		if b[i] > m2:
			result += b[i] - m2
	print(result)


for _ in range(int(input())):
	n = int(input())
	lst_a = list(map(int, input().split(' ')))
	lst_b = list(map(int, input().split(' ')))
	a_min = min(lst_a)
	b_min = min(lst_b)
	ans = 0
	for i in range(n):
		ans += max(lst_a[i] - a_min, lst_b[i] - b_min)
	print(ans)


t = int(input())
arr = []
brr = []
for i in range(t):
	n = int(input())
	a = input().split(' ')
	a = [int(x) for x in a]
	b = input().split(' ')
	b = [int(x) for x in b]
	arr.append(a)
	brr.append(b)
for i in range(t):
	summ = 0
	target_a = min(arr[i])
	target_b = min(brr[i])
	for j in range(len(arr[i])):
		calc_a = arr[i][j] - target_a
		calc_b = brr[i][j] - target_b
		both = min(calc_a, calc_b)
		arr[i][j] -= both
		brr[i][j] -= both
		summ += both
		summ += arr[i][j] - target_a
		summ += brr[i][j] - target_b
	print(summ)


t = int(input())
ret = []
for _ in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	oranges = list(map(int, input().split()))
	min_oranges = min(oranges)
	min_candies = min(candies)
	counter = 0
	for (c, o) in zip(candies, oranges):
		moves_canides = c - min_candies
		moves_oranges = o - min_oranges
		counter += min(moves_canides, moves_oranges) + abs(moves_canides - moves_oranges)
	ret.append(counter)
sol = '\n'.join([str(x) for x in ret])
print(sol)


import sys
times = int(input())
while times:
	total = 0
	_ = input()
	A = list(map(int, sys.stdin.readline().split()))
	B = list(map(int, sys.stdin.readline().split()))
	minA = min(A)
	minB = min(B)
	for (a, b) in zip(A, B):
		diffA = a - minA
		diffB = b - minB
		minimal_element = min(diffA, diffB)
		total += minimal_element
		total += diffA + diffB - 2 * minimal_element
	print(total)
	total = 0
	times -= 1


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().strip().split()]
	b = [int(x) for x in input().strip().split()]
	mina = min(a)
	minb = min(b)
	moves = 0
	for i in range(n):
		diffa = a[i] - mina
		diffb = b[i] - minb
		a[i] -= min(diffa, diffb)
		b[i] -= min(diffa, diffb)
		moves += min(diffa, diffb)
		moves += a[i] - mina
		a[i] -= a[i] - mina
		moves += b[i] - minb
		b[i] -= b[i] - minb
	print(moves)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	ans = []
	for i in range(n):
		ans.append(max(a[i] - mina, b[i] - minb))
	print(sum(ans))


from sys import setrecursionlimit
setrecursionlimit(10 ** 9)
import threading
threading.stack_size(67108864)

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = 10 ** 10
	min_b = 10 ** 10
	for i in range(n):
		min_a = min(a[i], min_a)
		min_b = min(b[i], min_b)
	answer = 0
	for i in range(n):
		candy = 0
		orange = 0
		if a[i] > min_a:
			candy = a[i] - min_a
		if b[i] > min_b:
			orange = b[i] - min_b
		answer += min(orange, candy)
		answer += abs(orange - candy)
	print(answer)
t = int(input())
for _ in range(t):
	solution()


for _ in range(int(input())):
	n = int(input())
	oranges = list(map(int, input().split(' ')))
	candies = list(map(int, input().split(' ')))
	mino = min(oranges)
	minc = min(candies)
	count = 0
	for i in range(n):
		if candies[i] > minc and oranges[i] > mino:
			a = candies[i] - minc
			b = oranges[i] - mino
			val = min(a, b)
			count += val
			a -= val
			b -= val
			count += a + b
		elif candies[i] > minc:
			count += candies[i] - minc
		elif oranges[i] > mino:
			count += oranges[i] - mino
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = True
	amin = min(a)
	bmin = min(b)
	arr = []
	brr = []
	for i in range(n):
		arr.append(a[i] - amin)
		brr.append(b[i] - bmin)
	res = 0
	for i in range(n):
		if arr[i] == 0 or brr[i] == 0:
			res += arr[i] + brr[i]
		else:
			res += abs(arr[i] - brr[i]) + min(arr[i], brr[i])
	print(res)


def ans(l, l1):
	k = 0
	k1 = 0
	sum = 0
	x = min(l)
	y = min(l1)
	m = 0
	n = 0
	for i in range(0, len(l), 1):
		m = int(l[i])
		n = int(l1[i])
		k = abs(m - x)
		k1 = abs(n - y)
		sum += max(k, k1)
	print(sum)
t = int(input())
while t > 0:
	a = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	ans(l, l1)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = []
	b = []
	a[0:n] = map(int, input().split())
	b[0:n] = map(int, input().split())
	count = 0
	for i in range(n):
		cc = b[i] - min(b)
		count += cc
		if a[i] - cc > min(a):
			count += a[i] - cc - min(a)
	print(count)


def gifts_fixing(anums, bnums):
	min_a = min(anums)
	min_b = min(bnums)
	anums = [x - min_a for x in anums]
	bnums = [x - min_b for x in bnums]
	result = 0
	for i in range(len(anums)):
		result += max(anums[i], bnums[i])
	return result
test_cases = int(input())
while test_cases > 0:
	n = int(input())
	input_a = input()
	nums_a = list(map(int, input_a.split(' ')))
	input_b = input()
	nums_b = list(map(int, input_b.split(' ')))
	print(gifts_fixing(nums_a, nums_b))
	test_cases -= 1


def solution(n, p, q):
	moves = 0
	min_p = min(p)
	min_q = min(q)
	for i in range(n):
		moves += max(p[i] - min_p, q[i] - min_q)
	return moves
tests = int(input())
for _ in range(tests):
	n = int(input().strip())
	candies = list(map(int, input().strip().split()))
	oranges = list(map(int, input().strip().split()))
	print(solution(n, candies, oranges))


for y in range(int(input())):
	n = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	t1 = min(lst1)
	t2 = min(lst2)
	count = 0
	for i in range(n):
		count += max(lst1[i] - t1, lst2[i] - t2)
	print(count)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m1 = min(a)
	m2 = min(b)
	for i in range(n):
		a[i] = a[i] - m1
		b[i] = b[i] - m2
	c = 0
	for i in range(n):
		mini = min(a[i], b[i])
		a[i] -= mini
		b[i] -= mini
		c += mini
	print(c + sum(a) + sum(b))


t = int(input())
for x in range(t):
	m = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	aa = min(a)
	bb = min(b)
	for i in range(n):
		ta = a[i] - aa
		tb = b[i] - bb
		tt = min(ta, tb)
		m += tt + (ta - tt) + (tb - tt)
	print(m)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	amin = 1000000000
	bmin = 1000000000
	k = 0
	for i in range(n):
		if a[i] < amin:
			amin = a[i]
		if b[i] < bmin:
			bmin = b[i]
	for i in range(n):
		k += max(a[i] - amin, b[i] - bmin)
	print(k)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mini = min(a)
	minib = min(b)
	ans = 0
	for j in range(n):
		ans += max(a[j] - mini, b[j] - minib)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	minofl1 = min(l1)
	minofl2 = min(l2)
	count = 0
	for i in range(len(l1)):
		if l1[i] == minofl1:
			count = count + (l2[i] - minofl2)
		elif l2[i] == minofl2:
			count = count + (l1[i] - minofl1)
		else:
			temp1 = l1[i] - minofl1
			temp2 = l2[i] - minofl2
			total = abs(temp1 - temp2)
			count = count + total
			count = count + min(temp1, temp2)
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_a = min(a)
	min_b = min(b)
	c = 0
	for i in range(n):
		count_a = a[i] - min_a
		count_b = b[i] - min_b
		c += max(count_a, count_b)
	print(c)


query = int(input())
for _ in range(query):
	rang = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ma = min(a)
	mb = min(b)
	count = 0
	for i in range(rang):
		if a[i] != ma and b[i] != mb:
			da = a[i] - ma
			db = b[i] - mb
			count += max(da, db)
		elif a[i] != ma:
			count += a[i] - ma
		elif b[i] != mb:
			count += b[i] - mb
	print(count)


t = int(input())

def surpiz():
	n = int(input())
	list_candy = [int(element) for element in input().split(' ')]
	list_orange = [int(el) for el in input().split(' ')]
	min_candy = min(list_candy)
	min_orange = min(list_orange)
	count_candy = 0
	count_orange = 0
	all_count = 0
	for x in range(n):
		if list_candy[x] > min_candy:
			count_candy = list_candy[x] - min_candy
		else:
			count_candy = 0
		if list_orange[x] > min_orange:
			count_orange = list_orange[x] - min_orange
		else:
			count_orange = 0
		all_count += max(count_orange, count_candy)
	print(all_count)
for i in range(t):
	surpiz()


import sys

def solve(n, a, b):
	a_mn = min(a)
	b_mn = min(b)
	ans = 0
	for (x, y) in zip(a, b):
		q = x - a_mn
		w = y - b_mn
		mn = min(q, w)
		ans += q + w - mn
	return ans
t = int(input())
for _ in range(t):
	ln1 = next(sys.stdin)
	n = int(ln1)
	ln2 = next(sys.stdin)
	a = list(map(int, ln2.split()))
	ln3 = next(sys.stdin)
	b = list(map(int, ln3.split()))
	print(solve(n, a, b))


def main():
	t = Iint()
	for _ in range(t):
		n = Iint()
		a = Ilist()
		b = Ilist()
		ans = 0
		(ma, mb) = (min(a), min(b))
		for (ai, bi) in zip(a, b):
			(ax, bx) = (ai - ma, bi - mb)
			ans += max(ax, bx)
		print(ans)
FIO = 10

def I():
	return input()

def Iint():
	return int(input())

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

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

def Plist(li, s=' '):
	print(s.join(map(str, li)))
en = enumerate

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import sys
	import os
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(j) for j in input().split()[:n]]
	b = [int(k) for k in input().split()[:n]]
	x = min(a)
	y = min(b)
	i = 0
	cnt = 0
	while (len(set(a)) != 1 or len(set(b)) != 1) and i < n:
		if a[i] > x and b[i] > y:
			f1 = a[i] - x
			f2 = b[i] - y
			z = min(f1, f2)
			cnt += z
			a[i] -= z
			b[i] -= z
			if a[i] != x:
				g1 = a[i] - x
				a[i] -= g1
				cnt += g1
			elif b[i] != y:
				g2 = b[i] - y
				b[i] -= g2
				cnt += g2
		elif a[i] > x and b[i] == y:
			f3 = a[i] - x
			cnt += f3
			a[i] -= f3
		elif b[i] > y and a[i] == x:
			f4 = b[i] - y
			cnt += f4
			b[i] -= f4
		i += 1
	print(cnt)


t = int(input())
for test in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	(a, b) = (min(l1), min(l2))
	ans = 0
	for i in range(n):
		d1 = l1[i] - a
		d2 = l2[i] - b
		ans += max(d1, d2)
	print(ans)


from sys import stdin, stdout
input = lambda : stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	min1 = min(lst1)
	min2 = min(lst2)
	nd = 0
	for i in range(0, n):
		a = lst1[i] - min1
		b = lst2[i] - min2
		nd += max([a, b])
	print(nd)


t = int(input())
for t_i in range(t):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min_pair = [a[0], b[0]]
	for i in range(1, len(a)):
		if a[i] <= min_pair[0] and b[i] <= min_pair[1]:
			min_pair = [a[i], b[i]]
		elif a[i] <= min_pair[0] and b[i] >= min_pair[1]:
			min_pair[0] = a[i]
		elif a[i] >= min_pair[0] and b[i] <= min_pair[1]:
			min_pair[1] = b[i]
	moves = 0
	for i in range(len(a)):
		if a[i] > min_pair[0] and b[i] > min_pair[1]:
			a_decrease = a[i] - min_pair[0]
			b_decrease = b[i] - min_pair[1]
			decrease = min(a_decrease, b_decrease)
			moves += decrease
			a[i] -= decrease
			b[i] -= decrease
		if a[i] > min_pair[0]:
			moves += a[i] - min_pair[0]
		if b[i] > min_pair[1]:
			moves += b[i] - min_pair[1]
	print(moves)


for t in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	b = [int(j) for j in input().split()]
	mA = min(a)
	mB = min(b)
	c = []
	for i in range(len(a)):
		a[i] -= mA
		b[i] -= mB
		c.append(abs(a[i] - b[i]) + min(a[i], b[i]))
	print(sum(c))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	min_a = min(a)
	b = list(map(int, input().split()))
	min_b = min(b)
	print(sum((a[i] - min_a + b[i] - min_b - min(a[i] - min_a, b[i] - min_b) for i in range(n))))


t = int(input())
while t:
	n = int(input())
	a = list(map(lambda x: int(x), input().split()))
	b = list(map(lambda x: int(x), input().split()))
	minA = min(a)
	minB = min(b)
	ans = 0
	for i in range(n):
		tempA = 0
		tempB = 0
		if a[i] > minA:
			tempA = a[i] - minA
		if b[i] > minB:
			tempB = b[i] - minB
		ans += max(tempA, tempB)
	print(ans)
	t -= 1


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().strip().split()))
	b = list(map(int, stdin.readline().strip().split()))
	a_min = min(a)
	b_min = min(b)
	ans = 0
	for i in range(n):
		if a[i] > a_min and b[i] > b_min:
			x = a[i] - a_min
			y = b[i] - b_min
			ans = ans + min(x, y)
			a[i] = a[i] - min(x, y)
			b[i] = b[i] - min(x, y)
		if a[i] > a_min:
			x = a[i] - a_min
			ans = ans + x
		if b[i] > b_min:
			x = b[i] - b_min
			ans = ans + x
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = 0
	a_min = min(a)
	b_min = min(b)
	for i in range(n):
		if a[i] != a_min and b[i] != b_min:
			A = a[i] - a_min
			B = b[i] - b_min
			c = min(A, B)
			a[i] = a[i] - c
			b[i] = b[i] - c
			s = s + c
		if a[i] != a_min and b[i] == b_min:
			A = a[i] - a_min
			a[i] = a[i] - A
			s = s + A
		if a[i] == a_min and b[i] != b_min:
			B = b[i] - b_min
			b[i] = b[i] - B
			s = s + B
	print(s)


from math import log2, ceil, floor
from collections import defaultdict, OrderedDict, Counter, deque
from heapq import heappush, heappop, heapify
import re

def inp():
	return input()

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

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

def int_inp():
	return int(input())

def float_int():
	return float(input())

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
for _ in range(int_inp()):
	n = int_inp()
	a = list_inp()
	b = list_inp()
	amin = min(a)
	bmin = min(b)
	ans = 0
	for i in range(n):
		adif = a[i] - amin
		bdif = b[i] - bmin
		mn = min(adif, bdif)
		mx = max(adif, bdif)
		ans += mn + (mx - mn)
	print(ans)


def sol(lis1, lis2):
	m1 = min(lis1)
	m2 = min(lis2)
	s = 0
	for i in range(len(lis1)):
		s += max(lis1[i] - m1, lis2[i] - m2)
	print(s)
k = int(input())
for i in range(k):
	input()
	lis1 = list(map(int, input().split(' ')))
	lis2 = list(map(int, input().split(' ')))
	sol(lis1, lis2)


t = int(input())
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_m = min(a)
	b_m = min(b)
	moves = 0
	for k in range(n):
		move_b = b[k] - b_m
		move_a = a[k] - a_m
		moves = moves + max(move_a, move_b)
	print(moves)


t = int(input())
r = []
a = []
b = []
for i in range(t):
	r.append(0)
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])
	min_a = min(a)
	min_b = min(b)
	for j in range(n):
		common = 0
		common += min(a[j] - min_a, b[j] - min_b)
		r[i] += common
		a[j] = a[j] - common
		b[j] = b[j] - common
		r[i] += a[j] - min_a + (b[j] - min_b)
for i in range(t):
	print(r[i])


t = int(input())
for _t in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	o = list(map(int, input().split()))
	i = 0
	c_min = min(c)
	o_min = min(o)
	(c_count, o_count, count) = (0, 0, 0)
	while i < n:
		c_count = c[i] - c_min
		o_count = o[i] - o_min
		if c_count >= o_count:
			o_count = 0
		else:
			o_count -= c_count
		count = c_count + o_count + count
		i += 1
	print(count)


def hod(k, m):
	h = 0
	min_k = min(k)
	min_m = min(m)
	for n in range(a):
		f = k[n] - min_k
		c = m[n] - min_m
		h += max(f, c)
	print(h)
t = int(input())
for i in range(t):
	a = int(input())
	k = [int(j) for j in input().split()]
	m = [int(j) for j in input().split()]
	hod(k, m)


import sys
input = sys.stdin.readline
n = int(input())
for i in range(n):
	(m, a, b) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
	ami = min(a)
	bmi = min(b)
	ans = 0
	for i in range(len(a)):
		x = a[i] - ami
		y = b[i] - bmi
		ans += min(x, y)
		if y == x:
			continue
		elif y > x:
			y -= x
			x -= x
		else:
			x -= y
			y -= y
		ans += max(x, y)
	print(ans)


t = int(input())
ans = []
for k in range(t):
	n = int(input())
	p = input()
	q = input()
	a = list(map(int, p.split()))
	b = list(map(int, q.split()))
	(x, y) = (min(a), min(b))
	c = 0
	for i in range(n):
		d1 = a[i] - x
		d2 = b[i] - y
		c += max(d1, d2)
	ans.append(c)
for i in ans:
	print(i)


n = int(input())
for _ in range(n):
	le = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	d = 0
	s1 = min(l1)
	s2 = min(l2)
	for i in range(len(l1)):
		t1 = 0
		t2 = 0
		if s1 < l1[i]:
			t1 = abs(s1 - l1[i])
		if s2 < l2[i]:
			t2 = abs(s2 - l2[i])
		if t1 != 0 and t2 != 0:
			if t1 > t2:
				d += t1
			else:
				d += t2
		elif t1 == 0:
			d += t2
		else:
			d += t1
	print(d)


t = int(input())
for i in range(t):
	n = int(input())
	ls1 = list(map(int, input().split()))
	ls2 = list(map(int, input().split()))
	ma = min(ls1)
	mb = min(ls2)
	sum = 0
	for j in range(len(ls1)):
		sum = sum + max(abs(ma - ls1[j]), abs(mb - ls2[j]))
	print(sum)


def min_moves(n, a, b):
	moves = 0
	a_min = min(a)
	b_min = min(b)
	for i in range(n):
		if a[i] > a_min and b[i] > b_min:
			min_reduce = min(a[i] - a_min, b[i] - b_min)
			a[i] -= min_reduce
			b[i] -= min_reduce
			moves += min_reduce
		if a[i] > a_min:
			diff = a[i] - a_min
			moves += diff
		if b[i] > b_min:
			diff = b[i] - b_min
			moves += diff
	return moves
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	print(min_moves(n, a, b))


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 1000000001
	d = 1000000001
	for i in range(n):
		c = min(c, a[i])
		d = min(d, b[i])
	ans = 0
	for i in range(n):
		ans += max(a[i] - c, b[i] - d)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	min1 = min(a)
	min2 = min(b)
	ans = 0
	for i in range(n):
		num1 = a[i] - min1
		num2 = b[i] - min2
		ans += min(num1, num2)
		if num1 > num2:
			ans += num1 - num2
		else:
			ans += num2 - num1
	print(ans)


def read():
	return [int(x) for x in input().split()]
(cas,) = read()
for _ in range(cas):
	(n,) = read()
	x = read()
	y = read()
	_x = min(x)
	_y = min(y)
	print(sum([max(x[i] - _x, y[i] - _y) for i in range(n)]))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if set(a) == 1 and set(b) == 1:
		print(0)
	else:
		c = 0
		(x, y) = (min(a), min(b))
		(i1, i2) = (a.index(x), b.index(y))
		for i in range(len(a)):
			if a[i] > x and b[i] > y:
				c += max(a[i] - x, b[i] - y)
			elif b[i] > y:
				c += b[i] - y
			elif a[i] > x:
				c += a[i] - x
		print(c)


t = int(input())
for tt in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	mina = min(a)
	minb = min(b)
	res = 0
	for i in range(n):
		(eata, eatb) = (a[i] - mina, b[i] - minb)
		res += max(eata, eatb)
	print(res)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = 0
	p1 = 0
	p2 = 0
	m = min(a)
	M = min(b)
	while p1 < n and p2 < n:
		x1 = abs(a[p1] - m)
		y1 = abs(b[p2] - M)
		if x1 >= y1:
			cnt += x1
		else:
			cnt += y1
		p1 += 1
		p2 += 1
	print(cnt)


from sys import stdin, stdout
from math import gcd
input = stdin.readline
print = stdout.write

def gcda(l):
	if len(l) == 0:
		return 1
	res = l[0]
	for i in range(1, len(l)):
		res = gcd(res, l[i])
	return res
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mina = min(a)
	minb = min(b)
	suma = 0
	for i in range(n):
		suma += max(abs(a[i] - mina), abs(b[i] - minb))
	print(str(suma) + '\n')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	at = min(a)
	bt = min(b)
	ans = 0
	for j in range(n):
		t = min(b[j] - bt, a[j] - at)
		a[j] -= t
		b[j] -= t
		ans += t
		ans += b[j] - bt + a[j] - at
	print(ans)


for _ in range(int(input())):
	gifts = int(input())
	sweets = list(map(int, input().split()))
	sweets_mnm = min(sweets)
	oranges = list(map(int, input().split()))
	oranges_mnm = min(oranges)
	counter = 0
	for i in range(gifts):
		d_sweets = sweets[i] - sweets_mnm
		d_oranges = oranges[i] - oranges_mnm
		counter += max(d_sweets, d_oranges)
	print(counter)