#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long int> a(n);
    vector<long long int> b(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    long long int cnt = 0;
    long long int min_a = *min_element(a.begin(), a.end());
    long long int min_b = *min_element(b.begin(), b.end());
    for (int i = 0; i < n; i++) {
      if (a[i] > min_a && b[i] > min_b) {
        long long int num;
        num = min(a[i] - min_a, b[i] - min_b);
        cnt += num;
        a[i] -= num;
        b[i] -= num;
      }
    }
    for (int i = 0; i < n; i++) {
      cnt += (a[i] - min_a);
      cnt += (b[i] - min_b);
    }
    cout << cnt << endl;
  }
}
