#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
long long int n, t = 1, a[N], b[N], z, sum;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    long long int ma = 1e9, mb = 1e9;
    for (int i = 1; i <= n; i++) cin >> a[i], ma = min(ma, a[i]);
    for (int i = 1; i <= n; i++) cin >> b[i], mb = min(mb, b[i]);
    long long int ans = 0;
    for (int i = 1; i <= n; i++) {
      long long int da = a[i] - ma, db = b[i] - mb;
      long long int tt = min(da, db);
      ans += tt;
      if (da >= tt) ans += da - tt;
      if (db >= tt) ans += db - tt;
    }
    cout << ans << endl;
  }
  return 0;
}
