#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using dt = array<int, 2>;
void test() {
int n;
cin >> n;
vector<ll> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
ll tot = 0;
for (int i = n - 2; i >= 0; i--) {
b[i] = max(b[i], b[i + 1]);
}
for (int i = 0; i < n; i++) {
if (a[i] <= b[i]) {
tot += b[i] - a[i];
}
}
cout << tot << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
for (int i = 1; i <= T; i++) {
test();
}
return 0;
}