#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using std::mt19937_64;
using std::random_device;
using std::uniform_int_distribution;
#include <numeric>
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 100000000000000000
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void cpc()
{
#ifndef ONLINE_JUDGE
freopen("shuffle.in", "r", stdin);
freopen("shuffle.out", "w", stdout);
#endif
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int exp(int x, int n, int m) {
if(x == 0 and n == 0) return 1;
x %= m;
int res = 1;
while (n > 0) {
if (n % 2 == 1) { res = res * x % m; }
x = x * x % m;
n /= 2;
}
return res;
}
int gcd(int a,int b){
if(a == 0) return b;
return gcd(b%a,a);
}
bool check(int x,int y,int n,int m){
if(x < 0 or y < 0 or x >= n or y >= m) return false;
return true;
}
struct DSU {
vector<int> parent, sz, ct;
DSU(int n) {
parent.resize(n+1);
sz.assign(n+1, 1);
ct.assign(n+1, 0);
iota(parent.begin(), parent.end(), 0);
}
int find(int x) {
return parent[x] == x ? x : parent[x] = find(parent[x]);
}
void unite(int a, int b) {
a = find(a), b = find(b);
if(a == b) return;
if(sz[a] < sz[b]) swap(a, b);
parent[b] = a;
sz[a] += sz[b];
ct[a] += ct[b];
}
};
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
// cpc();
int t=1;
cin >> t;
while(t--){
int n;
cin >> n;
vector<int> a(n),b(n);
multiset<int> s;
for(auto &x:a) cin >> x;
for(int i = 0 ; i < n; i++){
cin >> b[i];
s.insert(b[i]);
}
int ans = 0;
for(int i = 0 ; i < n; i++){
auto it = s.end();
it--;
if(a[i] < *it){
ans += (*it)-a[i];
}
s.erase(s.find(b[i]));
}
cout<<ans<<endl;
}
return 0;
}