#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t) {
    int n;
    cin >> n;
    vector<int> candy(n);
    vector<int> orange(n);
    for (size_t i = 0; i < n; i++) {
      cin >> candy[i];
    }
    for (size_t i = 0; i < n; i++) {
      cin >> orange[i];
    }
    long long moves = 0;
    int mincandy = *min_element(candy.begin(), candy.end());
    int minorange = *min_element(orange.begin(), orange.end());
    bool done = 0;
    int c = 0, o = 0;
    while (!done) {
      if (candy[c] > mincandy && orange[o] > minorange) {
        int steps = min(candy[c] - mincandy, orange[o] - minorange);
        candy[c] -= steps;
        orange[o] -= steps;
        moves += steps;
      } else if (candy[c] > mincandy && orange[o] <= minorange) {
        int steps = candy[c] - mincandy;
        candy[c] -= steps;
        moves += steps;
      } else if (candy[c] <= mincandy && orange[o] > minorange) {
        int steps = orange[c] - minorange;
        orange[o] -= steps;
        moves += steps;
      }
      if (candy[c] == mincandy && orange[o] == minorange) {
        c++;
        o++;
      }
      if (c == n && o == n) done = 1;
    }
    cout << moves << endl;
    t--;
  }
}
