#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n], b[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    for (long long int i = 0; i < n; i++) cin >> b[i];
    long long int mina = INT_MAX, minb = INT_MAX;
    for (long long int i = 0; i < n; i++) mina = min(mina, a[i]);
    for (long long int i = 0; i < n; i++) minb = min(minb, b[i]);
    long long int ans = 0, i = 0;
    while (i < n) {
      while (a[i] > mina && b[i] > minb) {
        long long int xx = a[i] - mina;
        long long int yy = b[i] - minb;
        long long int zz = min(xx, yy);
        ans += zz;
        a[i] -= zz;
        b[i] -= zz;
      }
      while (a[i] > mina && b[i] <= minb) {
        ans += a[i] - mina;
        a[i] = mina;
      }
      while (b[i] > minb && a[i] <= mina) {
        ans += b[i] - minb;
        b[i] = minb;
      }
      i++;
    }
    cout << ans << endl;
  }
  return 0;
}
