#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int c[n], o[n];
    for (int i = 0; i < n; i++) cin >> c[i];
    for (int i = 0; i < n; i++) cin >> o[i];
    int min1 = INT_MAX, min2 = INT_MAX;
    for (int i = 0; i < n; i++) min1 = min(min1, c[i]);
    for (int i = 0; i < n; i++) min2 = min(min2, o[i]);
    int diff1 = 0;
    int diff2 = 0;
    long long int ans = 0;
    for (int i = 0; i < n; i++) {
      diff1 = abs(min1 - c[i]);
      diff2 = abs(min2 - o[i]);
      ans += max(diff1, diff2) % 1000000007;
    }
    cout << ans << endl;
  }
}
