#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <math.h>
#include <cassert>
using namespace std;
typedef long long ll;

#define f first
#define s second

const int NMX = 2e5+5;
pair<int, int> a[NMX];

void task() {
	int n; cin >> n;
	
	for(int i = 0; i < n; i++)
		cin >> a[i].s;
	for(int i = 0; i < n; i++)
		cin >> a[i].f;
	
	sort(a, a + n);
	ll cost[2] = {0, 0};
	int lastRow = 1, lastCol = 1;
	
	for(int i = 0; i < n; i++) {
		int r = a[i].s, c = a[i].f;
		//cout << "{" << r << ", " << c << "}\n";
		
		if(r == c) {
			cost[1] = 1LL * r - 1;
			continue;
		}
		
		int curRow = r - c + 1;
		
		if(curRow <= lastRow) {
			cost[0] += 1LL * (curRow % 2) * (c - lastCol);
		} else {
			cost[0] += 1LL * (curRow - lastRow + (curRow % 2)) / 2;
			lastRow = curRow + (curRow % 2);
		}
		lastCol = c;
		//cout << lastRow << " " << cost[0] << "\n";
	}
	
	cout << cost[0] + cost[1] << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t; cin >> t;
	while(t--) {
		task();
	}
	return 0;
}