#include <bits/stdc++.h> using namespace std; #define For(i, a, b) for(int i = (a); i < (b); i++) #define rep(i, n) For(i, 0, n) #define rFor(i, a, b) for(int i = (a); i >= (b); i--) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using lint = long long; using ld = long double; int INF = 2000000000; lint LINF = 1000000000000000000; struct SetupIo { SetupIo() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } } setupio; int main() { int n, ka, kb; cin >> n >> ka >> kb; vector<int> a(ka); rep(i, ka) { cin >> a[i]; a[i]--; } vector<int> b(kb); rep(i, kb) { cin >> b[i]; b[i]--; } auto bfs = [&](vector<int> vs) -> vector<int> { vector<int> d(n, INF); queue<int> q; for (int v : vs) { d[v] = 0; q.emplace(v); } while (!q.empty()) { int u = q.front(); q.pop(); for (int x : {-1, 1}) { int v = u + x; if (0 <= v && v < n) { if (d[v] > d[u] + 1) { d[v] = d[u] + 1; q.emplace(v); } } } } return d; }; vector<int> da = bfs(a), db = bfs(b); int ab = INF; for (int v : b) { ab = min(ab, da[v]); } int q; cin >> q; while (q--) { int s, t; cin >> s >> t; s--; t--; int ans = INF; ans = min(ans, t - s); ans = min(ans, da[s] + da[t]); ans = min(ans, db[s] + db[t]); ans = min(ans, da[s] + ab + db[t]); ans = min(ans, db[s] + ab + da[t]); cout << ans << "\n"; } }