#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(a) a.begin(), a.end()
#define endl '\n'
void solve()
{
ll a, b;
cin >> a >> b;
ll n;
cin >> n;
vector<ll> pos(n), len(n);
for (auto &x : pos)
cin >> x;
for (auto &x : len)
cin >> x;
ll last = pos[n - 1];
ll mina = 1e18;
ll cur;
ll det = 1;
for (ll i = 0; i < n; i++)
{
if (len[i] > min(a,b))
{
det = 0;
cur = last - pos[i]-pos[i];
if (cur >= 0)
mina = min(mina, cur);
}
}
ll minb = 1e18;
ll first = 0;
last=pos[n-1];
cur=0;
for (ll i = n - 1; i > -1; i--)
{
if (len[i] > min(a,b))
{
det = 0;
first = (last - pos[i]);
cur = last - first;
if(cur>=0)minb = min(minb, cur);
}
}
if (det)
cout << -1 << endl;
else
cout << min(mina, minb) << endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll t;
cin >> t;
while (t--)
{
solve();
}
}