#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;
template <typename T>
using OrderedSet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define v vector
#define int long long
#define vin vector <int>
#define pii pair <int, int>
#define all(a) a.begin(), a.end()
#define yes cout << "YES\n"
#define Yes cout << "Yes\n"
#define no cout << "NO\n"
#define No cout << "No\n"
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repn(i, a, b) for(int i = a; i <= b; i++)
#define rev(i, a, b) for(int i = a; i >= b; i--)
int mod = 998244353;
void fastIO(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
}
void pk() {
int n; cin >> n;
vin a(n), b(n);
rep(i, 0, n) cin >> a[i];
rep(i, 0, n) cin >> b[i];
rev(i, n-2, 0) b[i] = max(b[i], b[i+1]);
int ans = 0;
rep(i, 0, n) ans += max(0LL, b[i]-a[i]);
cout << ans <<'\n';
}
int32_t main(){
fastIO();
int t = 1;
cin >> t;
while(t--) pk();
return 0;
}