#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void solve(int cs) {
int la, lb;
cin >> la >> lb;
int n;
cin >> n;
vector<int> a(n);
vector<int> l(n);
for (int &i : a) cin >> i;
for (int &i : l) cin >> i;
int res = 1e9;
for (int i = 0; i < n; i++) {
if (l[i] > lb) {
res = min(res, abs(a.back() - a[i] - a[i]));
}
}
for (int i = 0; i < n; i++) {
if (l[i] > la) {
res = min(res, abs(a.back() - a[i] - a[i]));
}
}
cout << (res == 1e9 ? -1 : res) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
cin >> tc;
for (int cs = 1; cs <= tc; cs++) {
solve(cs);
}
return 0;
}