#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 (min(la, lb) <= l[i]) {
res = min(res, abs(a[i] - (a.back() - 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;
}