#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, x, p, q;
    cin >> n;
    vector<long long> a, b;
    long long ma, mb;
    ma = mb = 9999999999;
    for (long long i = 0; i < n; i++) {
      cin >> x;
      a.push_back(x);
      ma = min(ma, x);
    }
    for (long long i = 0; i < n; i++) {
      cin >> x;
      b.push_back(x);
      mb = min(mb, x);
    }
    long long count = 0;
    for (long long i = 0; i < n; i++) {
      while (a[i] > ma && b[i] > mb) {
        p = a[i] - ma;
        q = b[i] - mb;
        if (p < q) {
          count += p;
          a[i] -= p;
          b[i] -= p;
        } else {
          count += q;
          a[i] -= q;
          b[i] -= q;
        }
      }
      while (a[i] > ma) {
        p = a[i] - ma;
        a[i] = ma;
        count += p;
      }
      while (b[i] > mb) {
        p = b[i] - mb;
        b[i] = mb;
        count += p;
      }
    }
    cout << count << endl;
  }
  return 0;
}
