#include <bits/stdc++.h>
using namespace std;

bool isLeftArrow(int r, int c) {
  return (r + c) % 2 == 0;
}

bool isRightArrow(int r, int c) {
  return (r + c) % 2 == 1;
}

int calcDist(int r1, int c1, int r2, int c2) {
  if (r1 - c1 == r2 - c2) {
    return isRightArrow(r1, c1) ? 0 : r2 - r1;
  }
  r2 -= r1 - 1;
  c2 -= c1 - 1;
  if (isLeftArrow(r1, c1)) {
    return (r2 - c2) / 2;
  } else {
    return (r2 - c2 + 1) / 2;
  }
}

void solve() {
  int n;
  cin >> n;
  vector<int> r(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  vector<pair<int, int>> pts;
  for (int i = 0; i < n; i++) {
    pts.emplace_back(r[i], c[i]);
  }
  sort(pts.begin(), pts.end());
  int curR = 1, curC = 1;
  int res = 0;
  for (auto[nextR, nextC] : pts) {
    res += calcDist(curR, curC, nextR, nextC);
    curR = nextR;
    curC = nextC;
  }
  cout << res << "\n";
}

int main() {
  int tests;
  cin >> tests;
  while (tests-- > 0) {
    solve();
  }
  return 0;
}