CodeEff/ECCO huggingface dataset:
# Original solution
def main():
  inf = float("INF")
  a,b,q = list(map(int, input().split()))
  s = [None] * (a + 3)
  s[0:2] = [-inf,-inf]
  s[-1] = inf
  t = [None] * (b + 3)
  t[0:2] = [-inf,-inf]
  t[-1] = inf
  for i in range(a):
      s[i+2] = int(eval(input()))
  for i in range(b):
      t[i+2] = int(eval(input()))

  from bisect import bisect_left

  dp0 = [None] * (a+3)
  dp1 = [None] * (b+3)

  def f(s,t,x,ss,i):
    if i == 0 and dp0[ss] != None: return abs(x - s[ss]) + dp0[ss]
    elif i == 1 and dp1[ss] != None: return abs(x - s[ss]) + dp1[ss]
    tr = bisect_left(t, s[ss])
    tl = tr - 1
    if i == 0: dp0[ss] = min(abs(s[ss] - t[tl]), abs(s[ss] - t[tr]))
    if i == 1: dp1[ss] = min(abs(s[ss] - t[tl]), abs(s[ss] - t[tr]))
    return abs(x - s[ss]) + min(abs(s[ss] - t[tl]), abs(s[ss] - t[tr]))


  for _ in range(q):
    ans = inf
    x = int(eval(input()))
    sr = bisect_left(s, x)
    ans = min(ans, f(s,t,x,sr,0))
    ans = min(ans, f(s,t,x,sr - 1,0))
    tr = bisect_left(t, x)
    ans = min(ans, f(t,s,x,tr,1))
    ans = min(ans, f(t,s,x,tr - 1,1))
    print(ans)
  
if __name__ == "__main__":
  main()

# Optimized solution
def main():
  inf = float("INF")
  a,b,q = list(map(int, input().split()))
  s = [None] * (a + 3)
  s[0:2] = [-inf,-inf]
  s[-1] = inf
  t = [None] * (b + 3)
  t[0:2] = [-inf,-inf]
  t[-1] = inf
  for i in range(a):
      s[i+2] = int(eval(input()))
  for i in range(b):
      t[i+2] = int(eval(input()))

  from bisect import bisect_right

  dp0 = [None] * (a+3)
  dp1 = [None] * (b+3)

  for _ in range(q):
    ans = inf
    x = int(eval(input()))
    sr = bisect_right(s, x)
    tr = bisect_right(t, x)    
    for si in (sr, sr-1):
      for ti in (tr, tr-1):
        ans = min(ans, abs(x-s[si]) + abs(s[si]-t[ti]), abs(x-t[ti]) + abs(s[si]-t[ti]))
    print(ans)
  
if __name__ == "__main__":
  main()
# Original solution
import bisect

A, B, Q = list(map(int, input().split()))
s = [0]*(A+4)
t = [0]*(B+4)

for i in range(2, A+2):
    s[i] = int(eval(input()))

for i in range(2, B+2):
    t[i] = int(eval(input()))

s[0], s[1], s[-2], s[-1] = -10**11-1, -10**11, 10**11, 10**11+1
t[0], t[1], t[-2], t[-1] = -10**11-1, -10**11, 10**11, 10**11+1


for i in range(Q):
    x = int(eval(input()))
    sh_left = bisect.bisect(s, x) - 1
    sh_right = sh_left + 1
    ans = 10**12
    for i in range(2):
        loc_sh = s[[sh_left, sh_right][i]]
        dis = abs(x-loc_sh)
        te_left = bisect.bisect(t, loc_sh) - 1
        te_right = te_left + 1
        loc_te_l = t[te_left]
        loc_te_r = t[te_right]
        tmp = min(dis+abs(loc_sh-loc_te_l), dis+abs(loc_sh-loc_te_r))
        ans = min(ans, tmp)
    te_left = bisect.bisect(t, x) - 1
    te_right = te_left + 1
    for i in range(2):
        loc_te = t[[te_left, te_right][i]]
        dis = abs(x-loc_te)
        sh_left = bisect.bisect(s, loc_te) - 1
        sh_right = sh_left + 1
        loc_sh_l = s[sh_left]
        loc_sh_r = s[sh_right]
        tmp = min(dis+abs(loc_te-loc_sh_l), dis+abs(loc_te-loc_sh_r))
        ans = min(ans, tmp)
    print(ans)


# 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]

for _ in range(Q):
    x = int(eval(input()))
    sh_r, te_r = bisect_right(s, x), bisect_right(t, x)
    sh_l, te_l = sh_r - 1, te_r - 1
    SR, SL, TR, TL = s[sh_r], s[sh_l], t[te_r], t[te_l]
    ans = INF
    for i in [SR, SL]:
        for j in [TR, TL]:
            dis = abs(i-x) + abs(i-j)
            dis = min(dis, abs(j-x) + abs(j-i))
            ans = min(ans, dis)
    print(ans)
# Original solution
a,b,q = list(map(int,input().split()))

jinjya = []
otera = []

for i in range(a):
    jinjya.append(int(eval(input())))
for i in range(b):
    otera.append(int(eval(input())))
def find(arr,tar,start,end):
    if start >= end:
        return start
    bar = (start+end)//2
    if arr[bar]<tar:
        return find(arr,tar,bar+1,end)
    elif arr[bar]>tar:
        return find(arr,tar,start,bar-1)
    else:
        return bar
for i in range(q):
    jinjyaEast = 0
    jinjyaWest = 0
    oteraEast = 0
    oteraWest = 0
    pos = int(eval(input()))
    idx = find(jinjya,pos,0,len(jinjya)-1)
    if(jinjya[idx] < pos):
        jinjyaWest = jinjya[idx]
        if idx<len(jinjya)-1:
            jinjyaEast = jinjya[idx+1]
    else:
        jinjyaEast = jinjya[idx]
        if idx>0:
            jinjyaWest = jinjya[idx-1]
    idx = find(otera,pos,0,len(otera)-1)
    if(otera[idx] < pos):
        oteraWest = otera[idx]
        if idx<len(otera)-1:
            oteraEast = otera[idx+1]
    else:
        oteraEast = otera[idx]
        if idx>0:
            oteraWest = otera[idx-1]
    res = []
    j = []
    o = []
    if jinjyaWest != 0:
        j.append(jinjyaWest)
    if jinjyaEast != 0:
        j.append(jinjyaEast)
    if oteraWest != 0:
        o.append(oteraWest)
    if oteraEast != 0:
        o.append(oteraEast)
    for a in j:
        for b in o:
            res.append(min(abs(pos-a)+abs(b-a),abs(pos-b)+abs(a-b)))
    print((min(res)))


# Optimized solution
import bisect
a,b,q = list(map(int,input().split()))

jinjya = []
otera = []

for i in range(a):
    jinjya.append(int(eval(input())))
for i in range(b):
    otera.append(int(eval(input())))

INF = 10**18
jinjya = [-INF] + jinjya + [INF]
otera = [-INF] + otera + [INF]


for i in range(q):
    res = INF
    pos = int(eval(input()))
    j,o = bisect.bisect_right(jinjya,pos),bisect.bisect_right(otera,pos)
    for a in [jinjya[j-1],jinjya[j]]:
        for b in [otera[o-1],otera[o]]:
            res = min(res,abs(pos-a)+abs(a-b),abs(pos-b)+abs(a-b))
    print(res)
# Original solution
import bisect
a, b, q = list(map(int, input().split()))
s, t = [0]*(a+2), [0]*(b+2)
for i in range(a):
    s[i+1] = int(eval(input()))
for i in range(b):
    t[i+1] = int(eval(input()))

s[0] = -float("inf")
s[-1] = float("inf")
t[0] = -float("inf")
t[-1] = float("inf")
#print(s)
#print(t)
for _ in range(q):
    start = int(eval(input()))
    x = bisect.bisect_right(s, start)
    y = bisect.bisect_right(t, start)
    ans = float("inf")
    for i in [s[x], s[x-1]]:
        for j in [t[y], t[y-1]]:
            res = min(abs(i-start) + abs(j-i), abs(j-start) + abs(i-j))
            ans = min(ans, res)
    print(ans)

# Optimized solution
import bisect
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]
#print(s)
#print(t)
for _ in range(q):
    start = int(eval(input()))
    x = bisect.bisect_right(s, start)
    y = bisect.bisect_right(t, start)
    ans = inf
    for i in [s[x], s[x-1]]:
        for j in [t[y], t[y-1]]:
            res = min(abs(i-start) + abs(j-i), abs(j-start) + abs(i-j))
            ans = min(ans, res)
    print(ans)
# Original solution
import bisect

def main():
    a,b,q = list(map(int, input().split()))

    sl = [int(eval(input())) for _ in range(a)]
    tl = [int(eval(input())) for _ in range(b)]
    xl = [int(eval(input())) for _ in range(q)]

    for x in xl:
        ans = 10**11

        curr_dist = 0
        ind_s = bisect.bisect_left(sl, x)
        ind_t = bisect.bisect_left(tl, x)
        
        for next_s in [ind_s, ind_s-1]:
            if 0 <= next_s < a:
                curr_dist = abs(x-sl[next_s])
                curr_pos = sl[next_s]
                ind_t2 = bisect.bisect_left(tl, curr_pos)
                if ind_t2 == 0:
                    curr_dist += abs(tl[0] - curr_pos)
                elif ind_t2 == b:
                    curr_dist += abs(tl[b-1] - curr_pos)
                else:
                    curr_dist += min( abs( tl[ind_t2-1] - curr_pos), abs(tl[ind_t2]-curr_pos))
                ans = min(curr_dist, ans)


        for next_t in [ind_t, ind_t-1]:
            if 0 <= next_t < b:
                curr_dist = abs(x-tl[next_t])
                curr_pos = tl[next_t]
                ind_s2 = bisect.bisect_left(sl, curr_pos)
                if ind_s2 == 0:
                    curr_dist += abs(sl[0] - curr_pos)
                elif ind_s2 == a:
                    curr_dist += abs(sl[a-1] - curr_pos)
                else:
                    curr_dist += min( abs( sl[ind_s2-1] - curr_pos), abs(sl[ind_s2]-curr_pos))
                ans = min(curr_dist, ans)

        print(ans)


if __name__ == "__main__":
    main()

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

def main():
    a,b,q = list(map(int, input().split()))

    sl = [int(eval(input())) for _ in range(a)]
    tl = [int(eval(input())) for _ in range(b)]
    xl = [int(eval(input())) for _ in range(q)]

    for x in xl:
        ans = 10**11

        curr_dist = 0
        ind_s = bisect.bisect_left(sl, x)
        ind_t = bisect.bisect_left(tl, x)
        
        for next_s in [ind_s, ind_s-1]:
            if 0 <= next_s < a:
                curr_dist = abs(x-sl[next_s])
                curr_pos = sl[next_s]
                ind_t2 = bisect.bisect_left(tl, curr_pos)
                if ind_t2 == 0:
                    curr_dist += abs(tl[0] - curr_pos)
                elif ind_t2 == b:
                    curr_dist += abs(tl[b-1] - curr_pos)
                else:
                    curr_dist += min( abs( tl[ind_t2-1] - curr_pos), abs(tl[ind_t2]-curr_pos))
                ans = min(curr_dist, ans)


        for next_t in [ind_t, ind_t-1]:
            if 0 <= next_t < b:
                curr_dist = abs(x-tl[next_t])
                curr_pos = tl[next_t]
                ind_s2 = bisect.bisect_left(sl, curr_pos)
                if ind_s2 == 0:
                    curr_dist += abs(sl[0] - curr_pos)
                elif ind_s2 == a:
                    curr_dist += abs(sl[a-1] - curr_pos)
                else:
                    curr_dist += min( abs( sl[ind_s2-1] - curr_pos), abs(sl[ind_s2]-curr_pos))
                ans = min(curr_dist, ans)

        print(ans)


if __name__ == "__main__":
    main()
# Original solution
from bisect import bisect_left as bl
A,B,Q=list(map(int,input().split()))
S=[]
T=[]
X=[]
for i in range(A):
    S.append(int(eval(input())))
for i in range(B):
    T.append(int(eval(input())))
def rl(X,a):
    ind=bl(X,a)
    if ind>=len(X):
        return ind-1
    return ind
def ll(X,a):
    ind=bl(X,a)-1
    if ind<0:
        return ind+1
    return ind
def l(X,a):
    ind=bl(X,a)
    if ind>=len(X):
        ind1=ind-1
        return (ind1,ind1)
    elif ind-1<0:
        return (ind,ind)
    else:
        return (ind,ind-1)
t=[]
for i in range(A):
    ind1,ind2=l(T,S[i])
    mi=min(abs(T[ind1]-S[i]),abs(T[ind2]-S[i]))
    t.append(mi)
"""
    if abs(T[rl(T,S[i])]-S[i])>=abs(T[ll(T,S[i])]-S[i]):
        t.append(abs(T[ll(T,S[i])]-S[i]))
    else:
        t.append(abs(T[rl(T,S[i])])-S[i])
"""
s=[]
for i in range(B):
    ind1,ind2=l(S,T[i])
    mi=min(abs(S[ind1]-T[i]),abs(S[ind2]-T[i]))
    s.append(mi)
"""
    if abs(S[rl(S,T[i])]-T[i])>=abs(S[ll(S,T[i])]-T[i]):
        s.append(abs(S[ll(S,T[i])]-T[i]))
    else:
        s.append(abs(S[rl(S,T[i])])-T[i])
"""
for i in range(Q):
    x=int(eval(input()))
    a=rl(S,x)
    a=t[a]+abs(S[a]-x)

    b=ll(S,x)
    b=t[b]+abs(S[b]-x)

    c=rl(T,x)
    c=s[c]+abs(T[c]-x)

    d=ll(T,x)
    d=s[d]+abs(T[d]-x)

    print((min(a,b,c,d)))


# Optimized solution
from bisect import bisect_left as bl
A,B,Q=list(map(int,input().split()))
S=[]
T=[]
X=[]
INF=10**18
S.append(-INF)
T.append(-INF)
for i in range(A):
    S.append(int(eval(input())))
for i in range(B):
    T.append(int(eval(input())))
S.append(INF)
T.append(INF)
for i in range(Q):
    x=int(eval(input()))
    b,d=bl(S,x),bl(T,x)
    res=INF
    for s in [S[b-1],S[b]]:
        for t in [T[d-1],T[d]]:
            d1,d2=abs(s-x)+abs(t-s),abs(t-x)+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 i in range(A)]
T = [int(eval(input())) for i in range(B)]
X = [int(eval(input())) for i in range(Q)]


def bs(x, L, ub, lb):
    if x < L[0]:
        return -1
    if x > L[-1]:
        return len(L)-1
    c = (ub+lb)//2
    if ub-lb <= 1:
        return c
    if L[c] >= x:
        return bs(x, L, c, lb)
    else:
        return bs(x, L, ub, c)
    
for i in range(Q):
    s_l = bs(X[i], S, A-1, 0)
    t_l = bs(X[i], T, B-1, 0)
    
    if s_l < 0:
        sl = 10**11
        su = S[0]-X[i]
    elif s_l == A-1:
        sl = X[i]-S[s_l]
        su = 10**11
    else:
        sl = X[i]-S[s_l]
        su = S[s_l+1]-X[i]
        
    if t_l < 0:
        tl = 10**11
        tu = T[0]-X[i]
    elif t_l == B-1:
        tl = X[i]-T[t_l]
        tu = 10**11
    else:
        tl = X[i]-T[t_l]
        tu = T[t_l+1]-X[i]
    ans = min(max(su, tu), max(sl, tl), su*2+tl, tl*2+su, sl*2+tu, tu*2+sl)
    print(ans)

# Optimized solution
import bisect
A, B, Q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]

for q in range(Q):
    x = int(eval(input()))
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)
# Original solution
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)]


def binary_search(q, A):
    l, r = 0, len(A)
    while r - l > 1:
        mid = (l + r) // 2
        if q > A[mid]:
            l = mid
        else:
            r = mid
    return A[l], A[r]


def main():
    for x in X:
        s1, s2 = binary_search(x, S)
        t1, t2 = binary_search(x, T)
        print((min(abs(s-t) + min(abs(s-x), abs(t-x)) for s in [s1, s2] for t in [t1, t2])))
    return

if __name__ == '__main__':
    main()


# Optimized solution
import sys
import bisect

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


# def binary_search(q, A):
#     l, r = 0, len(A)
#     while r - l > 1:
#         mid = (l + r) // 2
#         if q > A[mid]:
#             l = mid
#         else:
#             r = mid
#     return A[l], A[r]


def main():
    for x in X:
        ids, idt = bisect.bisect_right(S, x), bisect.bisect_right(T, x)
        print((min(abs(s-t) + min(abs(s-x), abs(t-x)) for s in S[ids-1:ids+1] for t in T[idt-1:idt+1])))
    return

if __name__ == '__main__':
    main()
# Original solution
from collections import deque
import bisect

a, b, q = [int(x) for x in input().split()]
s = [int(eval(input())) for i in range(a)]
t = [int(eval(input())) for i in range(b)]
#x = [int(input()) for i in range(q)]

s_que = deque(s)
s_que.appendleft(-10 ** 12)
s_que.append(10 ** 12)

t_que = deque(t)
t_que.appendleft(-10 ** 12)
t_que.append(10 ** 12)

for i in range(q):
    x = int(eval(input()))
    k = bisect.bisect_left(s_que, x)
    sb = s_que[k]
    sa = s_que[k-1]
    j = bisect.bisect_left(t_que, x)
    tb = t_que[j]
    ta = t_que[j-1]

    y = []
    for h in [sa, sb]:
        for g in [ta, tb]:
            y.append(abs(x-h) + abs(h-g))
    for h in [ta, tb]:
        for g in [sa, sb]:
            y.append(abs(x-h) + abs(h-g))

    print((min(y)))


# Optimized solution
#from collections import deque
import bisect

a, b, q = [int(x) for x in input().split()]
s = [-10**12] + [int(eval(input())) for i in range(a)] + [10**12]
t = [-10**12] + [int(eval(input())) for i in range(b)] + [10**12]
#x = [int(input()) for i in range(q)]

#s_que = deque(s)
#s_que.appendleft(-10 ** 12)
#s_que.append(10 ** 12)

#t_que = deque(t)
#t_que.appendleft(-10 ** 12)
#t_que.append(10 ** 12)

for i in range(q):
    x = int(eval(input()))
    k = bisect.bisect_left(s, x)
    sb = s[k]
    sa = s[k-1]
    j = bisect.bisect_left(t, x)
    tb = t[j]
    ta = t[j-1]

    y = []
    for h in [sa, sb]:
        for g in [ta, tb]:
            y.append(abs(x-h) + abs(h-g))
    for h in [ta, tb]:
        for g in [sa, sb]:
            y.append(abs(x-h) + abs(h-g))

    print((min(y)))
# Original solution
import sys


sys.setrecursionlimit(10000)


def my_search(l, low, high, t):
    n = (low+high)//2
    if t > l[n]:
        low = n
    else:
        high = n
    if high == low + 1:
        return low
    else:
        return my_search(l, low, high, t)

a,b,q = [int(_) for _ in input().split()]
s_l = [-float('inf')]
t_l = [-float('inf')]
x_l = []
for i in range(a):
    s_l.append(int(eval(input())))
s_l.append(float('inf'))
for i in range(b):
    t_l.append(int(eval(input())))
t_l.append(float('inf'))
for i in range(q):
    x_l.append(int(eval(input())))
for i in range(q):
    x = x_l[i]
    s1_id = my_search(s_l, 0, len(s_l)-1, x)
    s2_id = s1_id + 1
    s1 = s_l[s1_id]
    s2 = s_l[s2_id]
    t1_id = my_search(t_l, 0, len(t_l)-1, x)
    t2_id = t1_id + 1
    t1 = t_l[t1_id]
    t2 = t_l[t2_id]
    res = float('inf')
    for s in [s1,s2]:
        for t in [t1,t2]:
            d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)
            res = min(res, d1, d2)
    print(res)


# Optimized solution
import bisect


a,b,q = [int(_) for _ in input().split()]
s_l = [-float('inf')]
t_l = [-float('inf')]
x_l = []
for i in range(a):
    s_l.append(int(eval(input())))
s_l.append(float('inf'))
for i in range(b):
    t_l.append(int(eval(input())))
t_l.append(float('inf'))
for i in range(q):
    x_l.append(int(eval(input())))
for i in range(q):
    x = x_l[i]
    s1_id = bisect.bisect_left(s_l, x) - 1 
    s2_id = s1_id + 1
    s1 = s_l[s1_id]
    s2 = s_l[s2_id]
    t1_id = bisect.bisect_left(t_l, x) - 1 
    t2_id = t1_id + 1
    t1 = t_l[t1_id]
    t2 = t_l[t2_id]
    res = float('inf')
    for s in [s1,s2]:
        for t in [t1,t2]:
            d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)
            res = min(res, d1, d2)
    print(res)
# Original solution
from bisect import bisect_left, bisect_right

def func(x, y, z):
    yi = bisect_right(y, x)

    if yi == 0 or yi == len(y):
        ans = 0
        if yi == len(y):
            yi -= 1
        ans += abs(y[yi] - x)
        x = y[yi]

        zi = bisect_right(z, x)
        ans += min(abs(z[zi % len(z)] - x), abs(z[(zi-1) % len(z)] - x))
        return ans
    else:
        ans1 = ans2 = 0
        ans1 += abs(y[yi-1] - x)
        x1 = y[yi-1]
        zi = bisect_right(z, x1)
        ans1 += min(abs(z[zi % len(z)] - x1), abs(z[(zi-1) % len(z)] - x1))

        ans2 += abs(y[yi] - x)
        x2 = y[yi]
        zi = bisect_right(z, x2)
        ans2 += min(abs(z[zi % len(z)] - x2), abs(z[(zi-1) % len(z)] - x2))
        return min(ans1, ans2)


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 _ in range(q):
    x = int(eval(input()))

    print((min(func(x, s, t), func(x, t, s))))


# Optimized solution
from bisect import bisect_right

a, b, q = list(map(int, input().split()))
INF = 10**11
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_right(s, x)
    ti = bisect_right(t, x)

    ans = INF * 10
    for ss in [s[si-1], s[si]]:
        for tt in [t[ti-1], t[ti]]:
            ans = min(ans,
                      abs(x - ss) + abs(ss - tt),
                      abs(x - tt) + abs(tt - ss))
    print(ans)
# Original solution
import bisect
from itertools import product
A,B,Q = list(map(int,input().split()))
s = [int(eval(input())) for i in range(A)]
t = [int(eval(input())) for i in range(B)]
stlist = [s,t]
ab = [A,B]
for i in range(Q):
    x = int(eval(input()))
    cand = []
    for i in range(2):
        st = stlist[i]
        cand1 = set()
        l1 = bisect.bisect_left(st,x)
        r1 = bisect.bisect_right(st,x)
        if 0 <= l1 <= ab[i]-1:
            cand1.add(st[l1])
        if 0 <= l1-1 <= ab[i]-1:
            cand1.add(st[l1-1])  
        if 0 <= r1 <= ab[i]-1:
            cand1.add(st[r1])
        if 0 <= r1+1 <= ab[i]-1:
            cand1.add(st[r1+1])
        cand.append(cand1)
        
    ans = float('inf')
    for a,b in product(cand[0],cand[1]):
        c = min(abs(x-a)+abs(b-a),abs(x-b)+abs(b-a))
        ans = min(ans,c)
    print(ans)
        
        
    

# Optimized solution
import sys
import bisect
from itertools import product
def input(): return sys.stdin.readline().strip()
A,B,Q = list(map(int,input().split()))
s = [int(eval(input())) for i in range(A)]
t = [int(eval(input())) for i in range(B)]
stlist = [s,t]
ab = [A,B]
for i in range(Q):
    x = int(eval(input()))
    cand = []
    for i in range(2):
        st = stlist[i]
        cand1 = set()
        l1 = bisect.bisect_left(st,x)
        r1 = bisect.bisect_right(st,x)
        if 0 <= l1 <= ab[i]-1:
            cand1.add(st[l1])
        if 0 <= l1-1 <= ab[i]-1:
            cand1.add(st[l1-1])  
        if 0 <= r1 <= ab[i]-1:
            cand1.add(st[r1])
        if 0 <= r1+1 <= ab[i]-1:
            cand1.add(st[r1+1])
        cand.append(cand1)
        
    ans = float('inf')
    for a,b in product(cand[0],cand[1]):
        c = min(abs(x-a)+abs(b-a),abs(x-b)+abs(b-a))
        ans = min(ans,c)
    print(ans)
# Original solution
import sys
import bisect
from itertools import product
def input(): return sys.stdin.readline().strip()
A,B,Q = list(map(int,input().split()))
s = [int(eval(input())) for i in range(A)]
t = [int(eval(input())) for i in range(B)]
stlist = [s,t]
ab = [A,B]
for i in range(Q):
    x = int(eval(input()))
    cand = []
    for i in range(2):
        st = stlist[i]
        cand1 = set()
        l1 = bisect.bisect_left(st,x)
        r1 = bisect.bisect_right(st,x)
        if 0 <= l1 <= ab[i]-1:
            cand1.add(st[l1])
        if 0 <= l1-1 <= ab[i]-1:
            cand1.add(st[l1-1])  
        if 0 <= r1 <= ab[i]-1:
            cand1.add(st[r1])
        if 0 <= r1+1 <= ab[i]-1:
            cand1.add(st[r1+1])
        cand.append(cand1)
        
    ans = float('inf')
    for a,b in product(cand[0],cand[1]):
        c = min(abs(x-a)+abs(b-a),abs(x-b)+abs(b-a))
        ans = min(ans,c)
    print(ans)
        
        
    

# Optimized solution
import sys
import bisect
from itertools import product
def input(): return sys.stdin.readline().strip()
A,B,Q = list(map(int,input().split()))
s = [int(eval(input())) for i in range(A)]
t = [int(eval(input())) for i in range(B)]
stlist = [s,t]
ab = [A,B]
for i in range(Q):
    x = int(eval(input()))
    cand = []
    for i in range(2):
        st = stlist[i]
        cand1 = set()
        l1 = bisect.bisect_left(st,x)
        r1 = bisect.bisect_right(st,x)
        if 0 <= l1 <= ab[i]-1:
            cand1.add(st[l1])
        if 0 <= l1-1 <= ab[i]-1:
            cand1.add(st[l1-1])
        cand.append(cand1)
        
    ans = float('inf')
    for a,b in product(cand[0],cand[1]):
        c = min(abs(x-a)+abs(b-a),abs(x-b)+abs(b-a))
        ans = min(ans,c)
    print(ans)