# No sorting

def solve():
    n = int(input())
    hs = list(map(int, input().split()))
    ps = list(map(int, input().split()))
    diffs = [p - h for h, p in zip(hs, ps)]
    print(max(diffs) if all(d >= 0 for d in diffs) else -1)

for _ in range(int(input())):
    solve()