CodeEff/ECCO huggingface dataset:
# Original solution
import bisect

left_sentinel = -2 * (10 ** 10)
right_sentinel = 3 * (10 ** 10)

A, B, Q = list(map(int, input().split()))
ss = [left_sentinel] + [int(eval(input())) for _ in range(A)] + [right_sentinel]
ts = [left_sentinel] + [int(eval(input())) for _ in range(B)] + [right_sentinel]

for _ in range(Q):
    x = int(eval(input()))
    s_index = bisect.bisect_left(ss, x)
    right_s = ss[s_index]
    left_s = ss[s_index - 1]
    t_index = bisect.bisect_left(ts, x)
    right_t = ts[t_index]
    left_t = ts[t_index - 1]
    ans = min(
        max(right_s, right_t) - x,
        right_s - left_t + min(right_s - x, x - left_t),
        right_t - left_s + min(right_t - x, x - left_s),
        x - min(left_s, left_t)
    )
    print(ans)
    

# Optimized solution
import sys
from bisect import *
input = sys.stdin.buffer.readline

INF = 10 ** 13

A, B, Q = list(map(int, input().split()))
shrines = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
temples = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
queries = [int(eval(input())) for _ in range(Q)]

for x in queries:
    s_index = bisect(shrines, x)
    t_index = bisect(temples, x)
    rs = shrines[s_index]
    rt = temples[t_index]
    ls = shrines[s_index - 1]
    lt = temples[t_index - 1]
    ans = INF
    ans = min(ans, max(rs, rt) - x)
    ans = min(ans, x - min(ls, lt))
    ans = min(ans, (rt - ls)*2 - max(rt-x, x-ls))    
    ans = min(ans, (rs - lt)*2 - max(rs-x, x-lt))
    print(ans)
# Original solution
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)

A, B, Q = mapint()
Ss = [-10**20]+[int(eval(input())) for _ in range(A)]+[10**20]
Ts = [-10**20]+[int(eval(input())) for _ in range(B)]+[10**20]
Ss.sort()
Ts.sort()
from bisect import bisect_left

for _ in range(Q):
    x = int(eval(input()))
    xs = bisect_left(Ss, x)
    xt = bisect_left(Ts, x)

    rr = max(Ss[xs]-x, Ts[xt]-x)
    ll = max(x-Ss[xs-1], x-Ts[xt-1])
    lr = min(abs(x-Ss[xs-1])*2+abs(x-Ts[xt]), abs(x-Ts[xt-1])*2+abs(x-Ss[xs]))
    rl = min(abs(x-Ss[xs-1])+abs(x-Ts[xt])*2, abs(x-Ts[xt-1])+abs(x-Ss[xs])*2)
    print((min(rr, ll, rl, lr)))

# Optimized solution
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)

A, B, Q = mapint()
Ss = [-10**18]+[int(eval(input())) for _ in range(A)]+[10**18]
Ts = [-10**18]+[int(eval(input())) for _ in range(B)]+[10**18]
from bisect import bisect_left

for q in range(Q):
    x = int(eval(input()))
    ls = Ss[bisect_left(Ss, x)-1]
    lt = Ts[bisect_left(Ts, x)-1]
    rs = Ss[bisect_left(Ss, x)]
    rt = Ts[bisect_left(Ts, x)]
    print((min((rs-lt)+min(rs-x, x-lt), (rt-ls)+min(rt-x, x-ls), max(x-ls, x-lt), max(rs-x, rt-x))))
# Original solution
from bisect import bisect_right

A, B, Q = list(map(int, input().split()))
s = [int(eval(input())) for _ in range(A)]
t = [int(eval(input())) for _ in range(B)]
x = [int(eval(input())) for _ in range(Q)]

INF = 10 ** 18
s = [-INF] + s + [INF]
t = [-INF] + t + [INF]

for i in range(Q):
    b = bisect_right(s, x[i])
    d = bisect_right(t, x[i])
    res = INF
    for n in [s[b - 1], s[b]]:
        for m in [t[d - 1], t[d]]:
            d1 = abs(n - x[i]) + abs(m - n)
            d2 = abs(m - x[i]) + abs(n - m)
            res = min(res, d1, d2)
    print(res)


# Optimized solution

from bisect import bisect_right

A, B, Q = list(map(int, input().split()))
INF = 10 ** 18
S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
X = [int(eval(input())) for _ in range(Q)]

for x in X:
    b = bisect_right(S, x)
    d = bisect_right(T, x)
    res = INF
    for s in [S[b - 1], S[b]]:
        for t in [T[d - 1], T[d]]:
            dist_0 = abs(x - s) + abs(s - t)
            dist_1 = abs(x - t) + abs(t - s)
            res = min(res, dist_0, dist_1)

    print(res)
# Original solution
from bisect import bisect_left

INF = 10**18

A, B, Q = list(map(int, input().split()))
S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]

for _ in range(Q):
    x = int(eval(input()))
    si = bisect_left(S,x)
    ti = bisect_left(T,x)
    res = INF
    res = min(res, max(S[si] - x, T[ti] - x))
    res = min(res, max(x - S[si - 1], x - T[ti - 1]))
    res = min(res, x + T[ti] - 2 * S[si - 1])
    res = min(res, -x + 2 * T[ti] - S[si - 1])
    res = min(res, x + S[si] - 2 * T[ti - 1])
    res = min(res, -x + 2 * S[si] - T[ti - 1])
    print(res)

# Optimized solution
from bisect import bisect_left
import sys
input = sys.stdin.readline

INF = 10**18

A, B, Q = list(map(int, input().split()))
S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]

for _ in range(Q):
    x = int(eval(input()))
    si = bisect_left(S,x)
    ti = bisect_left(T,x)
    res = INF
    res = min(res, max(S[si] - x, T[ti] - x))
    res = min(res, max(x - S[si - 1], x - T[ti - 1]))
    res = min(res, x + T[ti] - 2 * S[si - 1])
    res = min(res, -x + 2 * T[ti] - S[si - 1])
    res = min(res, x + S[si] - 2 * T[ti - 1])
    res = min(res, -x + 2 * S[si] - T[ti - 1])
    print(res)
# Original solution
from bisect import bisect_left
A, B, Q = list(map(int, input().split()))
S = [-float('inf')] + [int(eval(input())) for _ in range(A)] + [float('inf')]
T = [-float('inf')] + [int(eval(input())) for _ in range(B)] + [float('inf')]
S_rev = [-s for s in S][::-1]
T_rev = [-t for t in T][::-1]

for q in range(Q):
    x = int(eval(input()))
    ans = float('inf')

    # Case1: 右に直進
    cost1_s = S[bisect_left(S, x)] - x
    cost1_t = T[bisect_left(T, x)] - x
    ans = min(ans, max(cost1_s, cost1_t))

    # Case2: 左に直進
    cost2_s = S_rev[bisect_left(S_rev, -x)] + x
    cost2_t = T_rev[bisect_left(T_rev, -x)] + x
    ans = min(ans, max(cost2_s, cost2_t))

    # Case3: 右でS、左でT
    cost3_s = S[bisect_left(S, x)] - x
    cost3_t = T_rev[bisect_left(T_rev, -x)] + x
    ans = min(ans, 2 * min(cost3_s, cost3_t) + max(cost3_s, cost3_t))

    # Case4: 右でT、左でS
    cost3_s = S_rev[bisect_left(S_rev, -x)] + x
    cost3_t = T[bisect_left(T, x)] - x
    ans = min(ans, 2 * min(cost3_s, cost3_t) + max(cost3_s, cost3_t))

    print(ans)


# Optimized solution
def main():
    from bisect import bisect_left
    A, B, Q = list(map(int, input().split()))
    INF = 2 * 10 ** 10
    S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
    T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
    S_rev = [-s for s in S][::-1]
    T_rev = [-t for t in T][::-1]

    for q in range(Q):
        x = int(eval(input()))
        ans = 5 * 10 ** 10

        # Case1: 右に直進
        cost1_s = S[bisect_left(S, x)] - x
        cost1_t = T[bisect_left(T, x)] - x
        ans = min(ans, max(cost1_s, cost1_t))

        # Case2: 左に直進
        cost2_s = S_rev[bisect_left(S_rev, -x)] + x
        cost2_t = T_rev[bisect_left(T_rev, -x)] + x
        ans = min(ans, max(cost2_s, cost2_t))

        # Case3: 右でS、左でT
        cost3_s = S[bisect_left(S, x)] - x
        cost3_t = T_rev[bisect_left(T_rev, -x)] + x
        ans = min(ans, 2 * min(cost3_s, cost3_t) + max(cost3_s, cost3_t))

        # Case4: 右でT、左でS
        cost3_s = S_rev[bisect_left(S_rev, -x)] + x
        cost3_t = T[bisect_left(T, x)] - x
        ans = min(ans, 2 * min(cost3_s, cost3_t) + max(cost3_s, cost3_t))

        print(ans)


if __name__ == "__main__":
    main()
# Original solution
#!/usr/bin/env python3
from bisect import bisect_right

def main():
    A, B, Q = list(map(int, input().split()))
    s = [int(eval(input())) for _ in range(A)]
    t = [int(eval(input())) for _ in range(B)]
    # print(s,t)
    s = [-10**12] + s + [10**12]
    t = [-10**12] + t + [10**12]

    for _ in range(Q):
        x = int(eval(input()))
        i = bisect_right(s,x)
        j = bisect_right(t,x)
        # print(i,j,x)
        ans = []

        ans.append(max(abs(s[i-1] - x), abs(t[j-1] - x)))
        ans.append(max(abs(s[i] - x), abs(t[j] - x)))
        ans.append(abs(s[i-1] - x) + abs(t[j] - x) + min(abs(s[i-1]-x), abs(t[j]-x)))
        ans.append(abs(s[i] - x) + abs(t[j-1] - x) + min(abs(s[i]-x), abs(t[j-1]-x)))

        print((min(ans)))

if __name__ == "__main__":
    main()


# Optimized solution
from bisect import bisect_left

A, B, Q = list(map(int, input().split()))
INF = 10**12
s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]

for _ in range(Q):
    x = int(eval(input()))
    si = bisect_left(s,x)
    ti = bisect_left(t,x)
    sl = [s[si-1],s[si]]
    tl = [t[ti-1],t[ti]]
    ans = INF
    for i in range(2):
        for j in range(2):
            ans = min(ans, abs(x-sl[i])+abs(sl[i]-tl[j]), abs(x-tl[j])+abs(tl[j]-sl[i]))
    print(ans)
# Original solution
def calc(a_list, b_list, x):
    inf = 10**11
    aa = [a - x for a in a_list]
    bb = [b - x for b in b_list]
    if len([b for b in bb if b>=0])*len([a for a in aa if a>=0]) >0:
        p_1 = max([b for b in bb if b>=0][0], [a for a in aa if a>=0][0])
    else:
        p_1 = inf
    if len([b for b in bb if b<=0])*len([a for a in aa if a<=0]) >0:
        p_2 = max(abs(max([b for b in bb if b<=0])), abs(max([a for a in aa if a<=0])))
    else:
        p_2 = inf
    if len([b for b in bb if b<=0])*len([a for a in aa if a>=0]) >0:
        b_tmp = max([b for b in bb if b<=0])
        a_tmp = min([a for a in aa if a>=0])
        p_3 = a_tmp - b_tmp + min(abs(a_tmp), abs(b_tmp))
    else:
        p_3 = inf
    if len([b for b in bb if b>=0])*len([a for a in aa if a<=0]) >0:
        b_tmp = min([b for b in bb if b>=0])
        a_tmp = max([a for a in aa if a<=0])
        p_4 = b_tmp - a_tmp + min(abs(a_tmp), abs(b_tmp))
    else:
        p_4 = inf
    return min(p_1, p_2, p_3, p_4)
a,b,q = list(map(int, input().split()))
a_list = []
b_list = []
q_list = []
for i in range(a):
    a_list.append(int(eval(input())))
for j in range(b):
    b_list.append(int(eval(input())))
for k in range(q):
    q = int(eval(input()))
    ans = calc(a_list, b_list, q)
    print(ans)

# Optimized solution
import bisect
a, b, q = list(map(int, input().split()))
s = []
for i in range(a):
    s.append(int(eval(input())))
t = []
for j in range(b):
    t.append(int(eval(input())))
inf = 10 ** 18
s = [-inf] + s + [inf]
t = [-inf] + t + [inf]
for k in range(q):
    x = int(eval(input()))
    s_r, t_r = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = inf
    for s_ in [s[s_r], s[s_r - 1]]:
        for t_ in [t[t_r], t[t_r - 1]]:
            d = min(abs(x-s_), abs(x-t_)) + abs(s_ - t_)
            res = min(d, res)
    print(res)
# Original solution
import bisect

A, B, Q = list(map(int, input().split()))
INF = 10 ** 11
s_list = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t_list = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
for q in range(Q):
    x = int(eval(input()))
    near_right_s = bisect.bisect_right(s_list, x)
    near_right_t = bisect.bisect_right(t_list, x)
    min_distance = INF
    for s in [s_list[near_right_s - 1], s_list[near_right_s]]:
        for t in [t_list[near_right_t - 1], t_list[near_right_t]]:
            distance_1 = abs(s - x) + abs(t - s)
            distance_2 = abs(t - x) + abs(s - t)
            min_distance = min(min_distance, distance_1, distance_2)
    print(min_distance)

# Optimized solution
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect

a,b,q=nii()
s=[-10**18]+[int(eval(input())) for i in range(a)]+[10**18]
t=[-10**18]+[int(eval(input())) for i in range(b)]+[10**18]

for i in range(q):
  x=int(eval(input()))
  s_inx=bisect(s,x)
  t_inx=bisect(t,x)

  s_l=s[s_inx-1]
  s_r=s[s_inx]

  t_l=t[t_inx-1]
  t_r=t[t_inx]

  ans=10**18
  for i in [s_l,s_r]:
    for j in [t_l,t_r]:
      ans=min(ans,abs(i-x)+abs(j-i))

  for i in [t_l,t_r]:
    for j in [s_l,s_r]:
      ans=min(ans,abs(i-x)+abs(j-i))

  print(ans)
# Original solution
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(eval(input()))
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      list(map(int, input().split()))
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999999
R = 10**9 + 7
import bisect

def ddprint(x):
  if DBG:
    print(x)

a,b,q = inm()
s = []
t = []
for i in range(a):
    s.append(inn())
for i in range(b):
    t.append(inn())
for qq in range(q):
    x = inn()
    mn = BIG

    i = bisect.bisect_left(s,x)
    ss = [0] if i==0 else [a-1] if i==a else [i-1,i]
    for y in ss:
        d = abs(s[y]-x)
        j = bisect.bisect_left(t,s[y])
        tt = [0] if j==0 else [b-1] if j==b else [j-1,j]
        for z in tt:
            mn = min(mn, d+abs(s[y]-t[z]))

    i = bisect.bisect_left(t,x)
    tt = [0] if i==0 else [b-1] if i==b else [i-1,i]
    for y in tt:
        d = abs(t[y]-x)
        j = bisect.bisect_left(s,t[y])
        ss = [0] if j==0 else [a-1] if j==a else [j-1,j]
        for z in ss:
            mn = min(mn, d+abs(t[y]-s[z]))

    print(mn)


# Optimized solution
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(eval(input()))
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      list(map(int, input().split()))
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999999
R = 10**9 + 7
import bisect

def ddprint(x):
  if DBG:
    print(x)

a,b,q = inm()
s = []
t = []
for i in range(a):
    s.append(inn())
for i in range(b):
    t.append(inn())
for qq in range(q):
    x = inn()
    mn = BIG

    i = bisect.bisect_left(s,x)
    j = bisect.bisect_left(t,x)
    #ddprint("i {} j {}".format(i,j))
    if i>0 and j>0:
        mn = min(mn, x-min(s[i-1],t[j-1]))
    if i>0 and j<b:
        mn = min(mn, min(x-s[i-1],t[j]-x)+t[j]-s[i-1])
    if i<a and j>0:
        mn = min(mn, min(x-t[j-1],s[i]-x)+s[i]-t[j-1])
    if i<a and j<b:
        mn = min(mn, max(s[i],t[j])-x)
    print(mn)
# Original solution
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    A, B, Q = list(map(int, input().split()))
    S = [-10**100]
    T = [-10**100]
    for _ in range(A): S.append(int(eval(input())))
    for _ in range(B): T.append(int(eval(input())))
    S.append(10**100)
    T.append(10**100)

    for _ in range(Q):
        x = int(eval(input()))
        idx1 = bisect_left(S, x)
        idx2 = bisect_left(T, x)
        ans = 10 ** 100
        cand1 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1])
        ans = min(ans, cand1)
        cand2 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2])
        ans = min(ans, cand2)
        cand3 = (S[idx1] - x) + abs(S[idx1] - T[idx2 - 1])
        ans = min(ans, cand3)
        cand4 = (S[idx1] - x) + abs(S[idx1] - T[idx2])
        ans = min(ans, cand4)
        cand5 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1])
        ans = min(ans, cand5)
        cand6 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1])
        ans = min(ans, cand6)
        cand7 = (T[idx2] - x) + abs(T[idx2] - S[idx1 - 1])
        ans = min(ans, cand7)
        cand8 = (T[idx2] - x) + abs(T[idx2] - S[idx1])
        ans = min(ans, cand8)
        print(ans)



if __name__ == "__main__":
    main()


# Optimized solution
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    A, B, Q = list(map(int, input().split()))
    S = [-10**50]
    T = [-10**50]
    for _ in range(A): S.append(int(eval(input())))
    for _ in range(B): T.append(int(eval(input())))
    S.append(10**50)
    T.append(10**50)

    for _ in range(Q):
        x = int(eval(input()))
        idx1 = bisect_left(S, x)
        idx2 = bisect_left(T, x)
        ans = 10 ** 11
        cand1 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1])
        ans = min(ans, cand1)
        cand2 = (x - S[idx1 - 1]) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand2)
        cand3 = (S[idx1] - x) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand3)
        cand4 = (S[idx1] - x) + abs(S[idx1] - T[idx2])
        ans = min(ans, cand4)
        cand5 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1])
        ans = min(ans, cand5)
        cand6 = (x - T[idx2 - 1]) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand6)
        cand7 = (T[idx2] - x) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand7)
        cand8 = (T[idx2] - x) + abs(T[idx2] - S[idx1])
        ans = min(ans, cand8)
        print(ans)



if __name__ == "__main__":
    main()
# Original solution
def main():
  import bisect
  A, B, Q = list(map(int, input().split()))
  s = list()
  t = list()
  s.append(-10**12)
  t.append(-10**12)
  for i in range(A):
    s.append(int(eval(input())))
  for i in range(B):
    t.append(int(eval(input())))
  s.append(10**12)
  t.append(10**12)
  for i in range(Q):
    x = int(eval(input()))
    sw = bisect.bisect_right(s, x)-1 #xより西で一番近い(同じ場所でもいい)神社の番号
    se = sw + 1 #xより東で一番近い神社の番号
    tw = bisect.bisect_right(t, x)-1
    te = tw + 1
    l1 = max(x-s[sw], x-t[tw])
    l2 = max(s[se]-x, t[te]-x)
    l3 = s[se]-x + s[se]-t[tw]
    l4 = t[te]-x + t[te]-s[sw]
    l5 = x-s[sw] + t[te]-s[sw]
    l6 = x-t[tw] + s[se]-t[tw]
    print((min(l1, l2, l3, l4, l5, l6)))
main()

# Optimized solution
import bisect
INF = 10**15
A, B, Q = list(map(int, input().split()))
s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
for i in range(Q):
  x = int(eval(input()))
  sw = bisect.bisect_right(s, x)-1 #xより西で一番近い(同じ場所でもいい)神社の番号
  se = sw + 1 #xより東で一番近い神社の番号
  tw = bisect.bisect_right(t, x)-1
  te = tw + 1
  res = INF
  for S in [s[sw], s[se]]:
    for T in [t[tw], t[te]]:
      d1, d2 = abs(x-S) + abs(T-S), abs(x-T) + abs(S-T)
      res = min(res, d1, d2)
  print(res)
# Original solution
A,B,Q = list(map(int,input().split()))
S = [int(eval(input())) for _ in range(A)]
T = [int(eval(input())) for _ in range(B)]
X = [int(eval(input())) for _ in range(Q)]

StoT_W = [10000000010]*A
t = 0
for i in range(A):
    if S[i]<T[0]:
        continue
    while(((t+1)<B)and(T[t+1] < S[i])):
        t += 1
    StoT_W[i] = S[i] - T[t]

StoT_E = [10000000010]*A
t = B-1
for i in range(A-1,-1,-1):
    if T[B-1]<S[i]:
        continue
    while((-1<(t-1))and(S[i] < T[t-1])):
        t-=1
    StoT_E[i] = T[t] - S[i]

StoT = [10000000010]*A
for i in range(A):
    StoT[i] = min(StoT_W[i],StoT_E[i])

TtoS_W = [10000000010]*B
s = 0
for i in range(B):
    if T[i]<S[0]:
        continue
    while(((s+1)<A)and(S[s+1] < T[i])):
        s += 1
    TtoS_W[i] = T[i] - S[s]
    
TtoS_E = [10000000010]*B
s = 0
for i in range(B):
    while(S[s]<T[i]):
        s+=1
        if s==A:
            break
    else:
        TtoS_E[i] = S[s] - T[i]
        continue
    break

TtoS = [10000000010]*B
for i in range(B):
    TtoS[i] = min(TtoS_W[i],TtoS_E[i])

for x in X:
    ans = 30000000000
    for i in range(A):
        ans = min(ans,abs(S[i]-x)+StoT[i])
    for i in range(B):
        ans = min(ans,abs(T[i]-x)+TtoS[i])
    print(ans)


# Optimized solution
from bisect import bisect_left
I = lambda x: [-1<<50] + [int(eval(input())) for i in range(x)] + [1<<50]

A,B,Q = list(map(int,input().split()))
S,T = I(A),I(B)

for _ in range(Q):
    x = int(eval(input()))
    LS_ = bisect_left(S,x)
    LT_ = bisect_left(T,x)



    LS = S[LS_-1]
    RS = S[LS_]
    LT = T[LT_-1]
    RT = T[LT_]

    print((min(
        x-min(LS,LT),
        max(RS,RT)-x,
        (x-LS)*2+(RT-x),
        (x-LT)*2+(RS-x),
        (RT-x)*2+(x-LS),
        (RS-x)*2+(x-LT)
        )))
# Original solution
def main():
    from bisect import bisect_left as bl
    a, b, q, *stx = list(map(int, open(0).read().split()))
    s = [-float('Inf')] + stx[:a] + [float('Inf')]
    t = [-float('Inf')] + stx[a:a + b] + [float('Inf')]
    x = stx[a + b:]
    tmp = []
    for i in x:
        f, g = bl(s, i), bl(t, i)

        sl, sr = s[f - 1], s[f]
        tl, tr = t[g - 1], t[g]

        d = float('Inf')
        for j in [sl, sr]:
            for k in [tr, tl]:
                if j <= i and k <= i:
                    d = min(d, i - min(j, k))
                elif j <= i <= k or k <= i <= j:
                    d = min(d, min(abs(i - j), abs(i - k)) * 2 + max(abs(i - j), abs(i - k)))
                else:
                    d = min(d, max(j, k) - i)

        tmp.append(d)

    ans = '\n'.join(map(str, tmp))
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    from bisect import bisect_left as bl
    a, b, q, *stx = list(map(int, open(0).read().split()))
    s = [-float('Inf')] + stx[:a] + [float('Inf')]
    t = [-float('Inf')] + stx[a:a + b] + [float('Inf')]
    x = stx[a + b:]
    tmp = []
    for i in x:
        f, g = bl(s, i), bl(t, i)

        sr, sl = s[f - 1], s[f]
        tr, tl = t[g - 1], t[g]

        d = min([max(sl, tl) - i, i - min(sr, tr), 2 * (tl - sr) - max(i - sr, tl - i), 2 * (sl - tr) - max(sl - i, i - tr)])
        tmp.append(d)

    ans = '\n'.join(map(str, tmp))
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
import bisect
a, b, q = list(map(int, input().split()))
s = [int(eval(input())) for _ in range(a)]
t = [int(eval(input())) for _ in range(b)]
for i in range(q):
    x = int(eval(input()))
    idx_s = bisect.bisect_left(s, x)
    idx_t = bisect.bisect_left(t, x)

    indices_s = []
    indices_t = []

    if idx_s == 0:
        indices_s.append(0)
    elif idx_s == a:
        indices_s.append(a-1)
    else:
        indices_s.append(idx_s)
        indices_s.append(idx_s-1)

    if idx_t == 0:
        indices_t.append(0)
    elif idx_t == b:
        indices_t.append(b-1)
    else:
        indices_t.append(idx_t)
        indices_t.append(idx_t-1)

    ans = []
    for i in indices_s:
        for j in indices_t:
            l, r = min(s[i], t[j]), max(s[i], t[j])
            if x < l:
                ans.append(r-x)
            elif l <= x and x < r:
                ans.append(min(r-l+(x-l), r-l+(r-x)))
            else:
                ans.append(x-l)
    print((min(ans)))



# Optimized solution
import sys
import bisect
input = sys.stdin.readline
a, b, q = list(map(int, input().split()))
s = [int(eval(input())) for _ in range(a)]
t = [int(eval(input())) for _ in range(b)]
for i in range(q):
    x = int(eval(input()))
    idx_s = bisect.bisect_left(s, x)
    idx_t = bisect.bisect_left(t, x)

    indices_s = []
    indices_t = []

    if idx_s == 0:
        indices_s.append(0)
    elif idx_s == a:
        indices_s.append(a-1)
    else:
        indices_s.append(idx_s)
        indices_s.append(idx_s-1)

    if idx_t == 0:
        indices_t.append(0)
    elif idx_t == b:
        indices_t.append(b-1)
    else:
        indices_t.append(idx_t)
        indices_t.append(idx_t-1)

    ans = []
    for i in indices_s:
        for j in indices_t:
            l, r = min(s[i], t[j]), max(s[i], t[j])
            if x < l:
                ans.append(r-x)
            elif l <= x and x < r:
                ans.append(min(r-l+(x-l), r-l+(r-x)))
            else:
                ans.append(x-l)
    print((min(ans)))