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: introductory

Starter code:

Solutions:
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 math

T = int(input())

for i in range(T):
  n = int(input())
  #n,k = map(int, input().split())
  a = list(map(int,input().split()))
  b = list(map(int,input().split()))
  #a = input()
  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)

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)

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)


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)

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 _ 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)

"""
                            pppppppppppppppppppp
                         ppppp  ppppppppppppppppppp
                      ppppppp    ppppppppppppppppppppp
                      pppppppp  pppppppppppppppppppppp
                      pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
       ppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppp
      pppppppppppppppppppppppppppppppppppppppppppppppp  ppppppppppppppppppppp
     ppppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppppp
    ppppppppppppppppppppppppppppppppppppppppppppppp    pppppppppppppppppppppppp
   pppppppppppppppppppppppppppppppppppppppppppppp     pppppppppppppppppppppppppp
  ppppppppppppppppppppppppppppppppppppppppppppp      pppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppppppp               pppppppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppp     pppppppppppppppppppppppppppppppppppppppppppppp
  ppppppppppppppppppppppppppp    pppppppppppppppppppppppppppppppppppppppppppppppp
    pppppppppppppppppppppppp  pppppppppppppppppppppppppppppppppppppppppppppppppp
     ppppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppppp
      pppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppp
       ppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
                              pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppp  pppppppp
                              ppppppppppppppppppppp    ppppppp
                                 ppppppppppppppppppp  ppppp
                                    pppppppppppppppppppp
"""


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
# sys.setrecursionlimit(2 * (10 ** 5))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
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 list(map(int, data().split()))
def ssp(): return list(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)


import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
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
#from itertools import permutations,combinations
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
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+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)



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

# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 05/08/2020

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 you in range(t):
    n=int(input())
    a=input().split()
    ai=[int(i) for i in a]
    b=input().split()
    bi=[int(i) for i in b]
    x=min(ai)
    y=min(bi)
    count=0
    for i in range(n):
        count+=max(ai[i]-x,bi[i]-y)
    print(count)


## necessary imports
import sys
input = sys.stdin.readline
# from math import ceil, floor, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1;
    return x;
    
# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## nCr function efficient using Binomial Cofficient
def nCr(n, k): 
    if(k > n - k): 
        k = n - k; 
    res = 1;
    for i in range(k): 
        res = res * (n - i);
        res = res / (i + 1); 
    return int(res);

## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0, hi = None):
    if hi == None:
        hi = len(a);
    while lo < hi:
        mid = (lo+hi)//2;
        if a[mid] < x:
            lo = mid+1;
        else:
            hi = mid;
    return lo;

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;


# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
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
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret;
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

for _ in range(int(input())):
    n = int(input());
    a = int_array(); b = int_array();
    ma = min(a); mb = min(b); ans = 0;
    for i in range(n):
        x = a[i] - ma;
        y = b[i] - mb;
        ans += min(x, y);
        ans += abs(x - y);
    print(ans);

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)


#Bhargey Mehta (Junior)
#DA-IICT, Gandhinagar
import sys, math
mod = 10**9

def solve(test_index):
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    tga, tgb = min(a), min(b)
    ans = 0
    for i in range(n):
        ans += max(a[i]-tga, b[i]-tgb)
    print(ans)
    return

if 'PyPy' not in sys.version:
    sys.stdin = open('input.txt', 'r')

sys.setrecursionlimit(100000)
num_tests = 1
num_tests = int(input())
for test in range(1, num_tests+1):
    #print("Case #{}: ".format(test), end="")
    solve(test)

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)


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)


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(n):
        f=min(a[i]-ma,b[i]-mb)
        ans+=f
        a[i]-=f
        b[i]-=f
        ans+=b[i]-mb+a[i]-ma
    print(ans)


def solve():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    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 _ in range(t):
    solve()

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)


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)

import time
from collections import deque 

def inpt():
    return int(input())
def inpl():
    return list(map(int,input().split()))
def inpm():
    return list(map(int,input().split()))
    
def solve():
    n = inpt()
    a = inpl()
    b = inpl()
    ans=[]
    x=min(a)
    y=min(b)
    for i in range(n):
        ans.append(max(abs(a[i]-x),abs(b[i]-y)))
    print(sum(ans))
    
    
def main():
    #start_time=time.time()
    m=10**9+7
    t = int(input())
    while(t):
        t-=1
        solve()
        
    
    #print('Time Elapsed = ',time.time()-start_time," seconds")
def __starting_point():
    main()

__starting_point()

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)

import sys
# sys.setrecursionlimit(10**6) 
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)

import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
input = stdin.readline
#print = stdout.write
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)

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)

#!/usr/bin/env pypy3

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))

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)


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


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)

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 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)

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)

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):
        ga=a[i]-ma 
        gb=b[i]-mb 
        ans=ans+max(ga,gb)
    print(ans)