#include "testlib.h"
#include <bits/stdc++.h>
 
using namespace std;
 
int main(int argc, char** argv) {
	registerValidation(argc, argv);
	const int minTests = 1, maxTests = 1000;
	const int min_monster_hp = 1, max_monster_hp = int(1e9);
	const int min_hero_hp = 1, max_hero_hp = int(1e9);
	const int min_hero_dmg = 1, max_hero_dmg = int(1e9);
	const int max_sum_n = int(2e5);
	int t = inf.readInt(minTests, maxTests, "t");
	inf.readEoln();
	int total_n = 0;
	for (int tc = 1; tc <= t; ++tc) {
	    setTestCase(tc);
		inf.readInt(min_monster_hp, max_monster_hp, "a");
		inf.readEoln();
		int n = inf.readInt(1, max_sum_n, "n");
		inf.readEoln();
		total_n += n;
		ensuref(total_n <= max_sum_n, "Expected sum n %d be <= %d", total_n, max_sum_n);
		inf.readInts(n, 1, max_hero_hp, "h");
		inf.readEoln();
		inf.readInts(n, 1, max_hero_dmg, "d");
		inf.readEoln();
	}
	inf.readEof();
	return 0;
}