/*CODED BY mahmudulsakib2019
DATE:-06/3/2024;TIME:-07:39 pm
BANGALDESH , SYLHET*/
#include <iostream>
#include <vector>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int train1, train2, numStations;
cin >> train1 >> train2 >> numStations;
vector<int> stationPositions(numStations), extraLaneLengths(numStations);
for (int i = 0; i < numStations; ++i) cin >> stationPositions[i];
for (int i = 0; i < numStations; ++i) cin >> extraLaneLengths[i];
int shorterTrain = min(train1, train2);
int shortestWaitTime = 1e9;
for (int i = 0; i < numStations; ++i) {
if (extraLaneLengths[i] > shorterTrain) {
shortestWaitTime = min(shortestWaitTime, max(stationPositions[i], numStations - 1 - stationPositions[i]));
}
}
if (shortestWaitTime == 1e9) {
cout << -1 << endl;
} else {
cout << shortestWaitTime << endl;
}
}
return 0;
}