/**
 *  author: ivanzuki   
 *  created: Thu Mar 25 2021
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; i++) {
      cin >> p[i].first;
    }
    for (int i = 0; i < n; i++) {
      cin >> p[i].second;
    }
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    if (p.back() != make_pair(1, 1)) {
      p.push_back(make_pair(1, 1));
    }
    reverse(p.begin(), p.end());
    int ans = 0;
    for (int i = 0; i + 1 < (int) p.size(); i++) {
      int from_r = p[i].first, from_c = p[i].second;
      int to_r = p[i + 1].first, to_c = p[i + 1].second;
      if (to_r - from_r == to_c - from_c) {
        int cost = (from_r + from_c) % 2 == 0 ? to_c - from_c : 0;
        ans += cost;
      } else if ((to_r + to_c) % 2 == 1) {
        int d = to_c - from_c;
        int mid_r = to_r - d;
        int mid_c = to_c - d;
        int cost = 0;
        if ((from_r + from_c) % 2 == 0) {
          cost = (mid_r - from_r) / 2;
        } else {
          cost = (mid_r - from_r + 1) / 2;
        }
        ans += cost;
      } else {
        int d = to_c - from_c;
        int mid_r = to_r - 1 - d;
        int mid_c = to_c - d;
        int cost = 1;
        if ((from_r + from_c) % 2 == 0) {
          cost += (mid_r - from_r) / 2;
        } else {
          cost += (mid_r - from_r + 1) / 2;
        }
        ans += cost;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
