#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  }
  return b;
}
long long find_min(vector<long long> vec) {
  long long min = vec[0];
  for (int i = 1; i < vec.size(); i++) {
    if (vec[i] < min) {
      min = vec[i];
    }
  }
  return min;
}
int main() {
  int t;
  long long temp, n, min_a, min_b, count = 0;
  vector<long long> a, b;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n;
    for (long long j = 0; j < n; j++) {
      cin >> temp;
      a.push_back(temp);
    }
    for (long long j = 0; j < n; j++) {
      cin >> temp;
      b.push_back(temp);
    }
    min_a = find_min(a);
    min_b = find_min(b);
    for (long long j = 0; j < n; j++) {
      if ((a[j] > min_a) && (b[j] > min_b)) {
        long long diff = min(a[j] - min_a, b[j] - min_b);
        a[j] -= diff;
        b[j] -= diff;
        count += diff;
      }
      if (a[j] > min_a) {
        long long diff = a[j] - min_a;
        a[j] -= diff;
        count += diff;
      }
      if (b[j] > min_b) {
        long long diff = b[j] - min_b;
        b[j] -= diff;
        count += diff;
      }
    }
    cout << count << endl;
    a.clear();
    b.clear();
    count = 0;
  }
}
