from collections import deque from itertools import pairwise INF = 1 << 60 N, KA, KB = map(int, input().split()) A = list(map(lambda x: int(x)-1, input().split())) B = list(map(lambda x: int(x)-1, input().split())) def calc_warp_dists(warps: list[int]) -> list[int]: dists = [INF] * N q = deque() for wi in warps: q.append(wi) dists[wi] = 0 while q: wi = q.popleft() if wi > 0 and dists[wi-1] > dists[wi] + 1: dists[wi-1] = dists[wi] + 1 q.append(wi-1) if wi+1 < N and dists[wi+1] > dists[wi] + 1: dists[wi+1] = dists[wi] + 1 q.append(wi+1) return dists a_warp_dists = calc_warp_dists(A) b_warp_dists = calc_warp_dists(B) ab_warp_dist = INF # ワープ A, B 間の最短距離 ws = [] for a in A: ws.append((a, 0)) for b in B: ws.append((b, 1)) for (x, xt), (y, yt) in pairwise(sorted(ws)): if xt != yt: ab_warp_dist = min(ab_warp_dist, y - x) def solve(s: int, t: int) -> int: x1 = t - s x2 = a_warp_dists[s] + a_warp_dists[t] x3 = b_warp_dists[s] + b_warp_dists[t] x4 = a_warp_dists[s] + ab_warp_dist + b_warp_dists[t] x5 = b_warp_dists[s] + ab_warp_dist + a_warp_dists[t] return min(x1, x2, x3, x4, x5) Q = int(input()) for _ in range(Q): s, t = map(lambda x: int(x)-1, input().split()) res = solve(s, t) print(res)