#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long inf = 1e9;
ll n, m, k;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<pair<ll, ll> > o(n), c(n), change(n, {0, 0});
    for (int i = 0; i < n; i++) {
      cin >> o[i].first;
      o[i].second = i;
    }
    for (int i = 0; i < n; i++) {
      cin >> c[i].first;
      c[i].second = i;
    }
    sort(o.begin(), o.end());
    sort(c.begin(), c.end());
    ll sc = c[0].first, so = o[0].first;
    for (int i = 1; i < n; i++) {
      change[c[i].second].first = c[i].first - sc;
      change[o[i].second].second = o[i].first - so;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ans += max(change[i].first, change[i].second);
    }
    cout << ans << "\n";
  }
  return 0;
}
