CodeEff/ECCO huggingface dataset:
# Original solution
from bisect import bisect_left
A, B, Q = list(map(int, input().split()))
S = [-10**11] + [int(eval(input())) for _ in range(A)] + [10**11]
T = [-10**11] + [int(eval(input())) for _ in range(B)] + [10**11]
X = [int(eval(input())) for _ in range(Q)]

S1 = [0]*A
T1 = [0]*B
for i, s in enumerate(S[1:-1]):
    x = bisect_left(T, s)
    S1[i] = (s, min(abs(s - T[x-1]), abs(T[x] - s)))
for i, t in enumerate(T[1:-1]):
    x = bisect_left(S, t)
    T1[i] = (t, min(abs(t - S[x-1]), abs(S[x] - t)))
ST = S1 + T1
ST.sort()
ST = [(-10**11, 10**11)] + ST + [(10**11, 10**11)]
bist, dist = list(map(list, list(zip(*ST))))
for d in X:
    x = bisect_left(bist, d)
    print((min(abs(d - bist[x-1]) + dist[x-1], abs(bist[x] - d) + dist[x])))


# Optimized solution
import sys
from bisect import bisect as br
A, B, Q = list(map(int, input().split()))
inf = 10**11
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)]

StoT = [0]*A
for i, s in enumerate(S[1:-1]):
    x = br(T, s)
    StoT[i] = (s, min(s - T[x-1], T[x] - s))

TtoS = [0]*B
for i, t in enumerate(T[1:-1]):
    x = br(S, t)
    TtoS[i] = (t, min(t - S[x-1], S[x] - t))

M = [(-inf, inf)] + TtoS + StoT + [(inf, inf)]
M.sort()
Mk , Mv = list(map(list, list(zip(*M))))
for x in X:
    idx = br(Mk, x)
    print((min(Mk[idx] - x + Mv[idx], x - Mk[idx-1] + Mv[idx-1])))
# Original solution
from bisect import bisect_left as bl
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)]
s.insert(0,-10**12)
s.append(10**12)
t.insert(0,-10**12)
t.append(10**12)

for i in range(q):
    x = int(eval(input()))
    si = bl(s,x)
    ti = bl(t,x)
    ans = 10**12
    for j in range(si-1,si+1):
        for k in range(ti-1,ti+1):
            if s[j] <= t[k]:
                if t[k] <= x:
                    ans = min(ans,x-s[j])
                elif x <= s[j]:
                    ans = min(ans,t[k]-x)
                else:
                    ans = min(ans,min(x-s[j],t[k]-x)+t[k]-s[j])
            else:
                if s[j] <= x:
                    ans = min(ans,x-t[k])
                elif x <= t[k]:
                    ans = min(ans,s[j]-x)
                else:
                    ans = min(ans,min(x-t[k],s[j]-x)+s[j]-t[k])
    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
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a,b,q = list(map(int,readline().split()))

jinja = [-(2*10**10+10)]

for i in range(a):
    jinja.append(int(eval(input())))

tera = [-(2*10**10+10)]

for i in range(b):
    tera.append(int(eval(input())))

#add big number
jinja.append(2*10**10+10)
tera.append(2*10**10+10)

for query in range(q):
    x = int(eval(input()))
    j_r = bisect.bisect_left(jinja,x)
    j_l = jinja[j_r-1]
    t_r = bisect.bisect_left(tera,x)
    t_l = tera[t_r-1]
    j_r = jinja[j_r]
    t_r = tera[t_r]
    ans = min((x-j_l)*2+(t_r-x),(x-t_l)*2+(j_r-x),(x-j_l)+(t_r-x)*2,(x-t_l)+(j_r-x)*2)
    ans = min (ans,x - min(j_l,t_l), max(j_r,t_r)-x)
    print(ans)


# Optimized solution
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a,b,q = list(map(int,readline().split()))

jinja = [-(10**10+10)]

for i in range(a):
    jinja.append(int(readline()))

tera = [-(10**10+10)]

for i in range(b):
    tera.append(int(readline()))

#add big number
jinja.append(2*10**10+10)
tera.append(2*10**10+10)

for query in range(q):
    x = int(readline())
    j_r = bisect.bisect_left(jinja,x)
    j_l = jinja[j_r-1]
    t_r = bisect.bisect_left(tera,x)
    t_l = tera[t_r-1]
    j_r = jinja[j_r]
    t_r = tera[t_r]
    ans = min((x-j_l)*2+(t_r-x),(x-t_l)*2+(j_r-x),(x-j_l)+(t_r-x)*2,(x-t_l)+(j_r-x)*2)
    ans = min (ans,x - min(j_l,t_l), max(j_r,t_r)-x)
    print(ans)
# Original solution
from bisect import bisect_left
a,b,q = list(map(int, input().split()))
S = []
for _ in range(a):
  S.append(int(eval(input())))
T = []
for _ in range(b):
  T.append(int(eval(input())))
X = []
for _ in range(q):
  X.append(int(eval(input())))

INF = 10 ** 11
def dfs(direction, tors, pos, count):
  if tors == 1:
    L = T
  elif tors == -1:
    L = S
  i = bisect_left(L, pos)
  if i == len(L):
    if direction == 1:
      return INF
    elif direction == -1:
      res = abs(L[i-1]-pos)
      next_pos = L[i-1]
  elif L[i] == pos:
    res = 0
    next_pos = pos
  else:
    if direction == 1:
      res = abs(L[i]-pos)
      next_pos = L[i]
    elif direction == -1:
      if i == 0:
        return INF

      res = abs(L[i-1]-pos)
      next_pos = L[i-1]

  if count == 1:
    return res

  res0 = res + dfs(direction, tors*(-1), next_pos, count-1)
  res1 = res + dfs(direction*(-1), tors*(-1), next_pos, count-1)

  return min(res0, res1)

for x in X:
  res0 = dfs(1, 1, x, 2)
  res1 = dfs(-1, 1, x, 2)
  res2 = dfs(1, -1, x, 2)
  res3 = dfs(-1, -1, x, 2)

  print((min(res0, res1, res2, res3)))


# 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
#D問題
A,B,Q = list(map(int,(input().split())))
si = [-(10**10)]+[int(eval(input())) for _ in range(A)]+[2*(10**10)] # 範囲外に追加して、xの左右に常にデータがあるようにする
ti = [-(10**10)]+[int(eval(input())) for _ in range(B)]+[2*(10**10)]
A +=2
B +=2

for _ in [0]*Q:
    x = int(eval(input()))
    l = 0
    r = A-1
    while l+1<r:
        i = (l+r)//2
        if si[i]<x:
            l = i
        else:
            r = i
    sl = si[l]
    sr = si[r]
    
    l = 0
    r = B-1
    while l+1<r:
        i = (l+r)//2
        if ti[i]<x:
            l = i
        else:
            r = i
    tl = ti[l]
    tr = ti[r]
    dsl = x-sl
    dsr = sr-x
    dtl = x-tl
    dtr = tr-x
    print((min(max(dsr,dtr),max(dsl,dtl),dsl+dtr+min(dsl,dtr),dsr+dtl+min(dsr,dtl))))

# Optimized solution
#D問題
A,B,Q = list(map(int,(input().split())))
si = [-(10**10)]+[int(eval(input())) for _ in range(A)]+[2*(10**10)] # 範囲外に追加して、xの左右に常にデータがあるようにする
ti = [-(10**10)]+[int(eval(input())) for _ in range(B)]+[2*(10**10)]
xi = [int(eval(input())) for i in range(Q)]
A +=2
B +=2

for x in xi:
    l = 0
    r = A-1
    while l+1<r:
        i = (l+r)//2
        if si[i]<x:
            l = i
        else:
            r = i
    sl = si[l]
    sr = si[r]
    
    l = 0
    r = B-1
    while l+1<r:
        i = (l+r)//2
        if ti[i]<x:
            l = i
        else:
            r = i
    tl = ti[l]
    tr = ti[r]
    dsl = x-sl
    dsr = sr-x
    dtl = x-tl
    dtr = tr-x
    print((min(max(dsr,dtr),max(dsl,dtl),dsl+dtr+min(dsl,dtr),dsr+dtl+min(dsr,dtl))))
# Original solution
#D問題
A,B,Q = list(map(int,(input().split())))
si = [-(10**10)]+[int(eval(input())) for _ in range(A)]+[2*(10**10)] # 範囲外に追加して、xの左右に常にデータがあるようにする
ti = [-(10**10)]+[int(eval(input())) for _ in range(B)]+[2*(10**10)]
xi = [int(eval(input())) for i in range(Q)]
A +=2
B +=2

for x in xi:
    l = 0
    r = A-1
    while l+1<r:
        i = (l+r)//2
        if si[i]<x:
            l = i
        else:
            r = i
    sl = si[l]
    sr = si[r]
    
    l = 0
    r = B-1
    while l+1<r:
        i = (l+r)//2
        if ti[i]<x:
            l = i
        else:
            r = i
    tl = ti[l]
    tr = ti[r]
    dsl = x-sl
    dsr = sr-x
    dtl = x-tl
    dtr = tr-x
    print((min(max(dsr,dtr),max(dsl,dtl),dsl+dtr+min(dsl,dtr),dsr+dtl+min(dsr,dtl))))

# Optimized solution
#D問題
import sys
A,B,Q = list(map(int,(input().split())))
si = [-(10**10)]+[int(eval(input())) for _ in range(A)]+[2*(10**10)] # 範囲外に追加して、xの左右に常にデータがあるようにする
ti = [-(10**10)]+[int(eval(input())) for _ in range(B)]+[2*(10**10)]
#xi = [int(input()) for i in range(Q)]
*xi, = list(map(int,"".join(sys.stdin.readlines()).split()))
A +=2
B +=2

for x in xi:
    l = 0
    r = A-1
    while l+1<r:
        i = (l+r)//2
        if si[i]<x:
            l = i
        else:
            r = i
    sl = si[l]
    sr = si[r]
    
    l = 0
    r = B-1
    while l+1<r:
        i = (l+r)//2
        if ti[i]<x:
            l = i
        else:
            r = i
    tl = ti[l]
    tr = ti[r]
    dsl = x-sl
    dsr = sr-x
    dtl = x-tl
    dtr = tr-x
    print((min(max(dsr,dtr),max(dsl,dtl),dsl+dtr+min(dsl,dtr),dsr+dtl+min(dsr,dtl))))
# Original solution
import bisect
A, B, Q = list(map(int, input().split()))
INF = 10 ** 13
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)

# Optimized solution
import bisect
import sys
A, B, Q = list(map(int, input().split()))
INF = 10 ** 13
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(sys.stdin.readline())
    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
import bisect
import sys
A, B, Q = list(map(int, input().split()))
INF = 10 ** 13
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(sys.stdin.readline())
    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)


# Optimized solution
import bisect
import sys
A, B, Q = list(map(int, input().split()))
INF = 10 ** 13
s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
xs = [int(sys.stdin.readline()) for i in range(Q)]
for x in xs:
    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
import bisect
import sys
A, B, Q = list(map(int, input().split()))
INF = 10 ** 13
s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
xs = [int(sys.stdin.readline()) for i in range(Q)]
for x in xs:
    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)

# Optimized solution
def solve():
    import bisect
    import sys
    A, B, Q = list(map(int, input().split()))
    INF = 10 ** 13
    s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
    t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
    xs = [int(sys.stdin.readline()) for i in range(Q)]
    for x in xs:
        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)
if __name__ == '__main__':
  	solve()
# Original solution
from bisect import bisect_right

A , B , Q = list(map(int,input().split()))
INF = 10**20

s = [0] * A
t = [0] * B
x = [0] * Q

for i in range(A) :
    s[i] = int(eval(input()))
for i in range(B) :
    t[i] = int(eval(input()))
for i in range(Q) :
    x[i] = int(eval(input()))

s = [-INF] + s + [INF]
t = [-INF] + t + [INF]

for p in x :
    rightS = bisect_right(s,p)
    rightT = bisect_right(t,p)

    dist = INF

    for ss in [s[rightS - 1], s[rightS]] :
        for tt in [t[rightT - 1], t[rightT]] :
            dist1 = abs(ss - p) + abs(ss - tt)
            dist2 = abs(tt - p) + abs(tt - ss)
            dist = min(dist, dist1, dist2)

    print(dist)


# Optimized solution
from bisect import bisect_left, bisect_right

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)] + [float('inf'), -float('inf')]
T = [int(input()) for _ in range(B)] + [float('inf'), -float('inf')]

S.sort()
T.sort()

ans = []
for _ in range(Q):
    x = int(input())

    midS = bisect_right(S, x)
    midT = bisect_right(T, x)

    lS = S[midS - 1]
    rS = S[midS]
    lT = T[midT - 1]
    rT = T[midT]

    dist = min(
        max(rS, rT) - x,
        x - min(lS, lT),
        abs(rS - lT) + min(rS - x, x - lT),
        abs(rT - lS) + min(rT - x, x - lS)
    )

    ans.append(dist)

print(*ans, sep='\n')
# Original solution
from bisect import bisect_right, bisect_left
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()))

    lS, lT = S[bisect_right(S, x) - 1], T[bisect_right(T, x) - 1]
    rS, rT = S[bisect_left(S, x)], T[bisect_left(T, x)]

    ans = min(
        abs(lS - lT) + (x - max(lS, lT)),
        abs(rS - rT) + (min(rS, rT) - x),
        (rT - lS) + min(x - lS, rT - x),
        (rS - lT) + min(x - lT, rS - x)
    )

    print(ans)


# Optimized solution
from bisect import bisect_left

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

S.sort()
T.sort()

for _ in range(Q):
    x = int(eval(input()))

    s = bisect_left(S, x)
    ls = S[s - 1]
    rs = S[s]

    t = bisect_left(T, x)
    lt = T[t - 1]
    rt = T[t]

    ans = min(
        abs(ls - rt) + min(abs(x - ls), abs(x - rt)),
        abs(lt - rs) + min(abs(x - lt), abs(x - rs)),
        max(abs(x - ls), abs(x - lt)),
        max(abs(x - rs), abs(x - rt))
    )

    print(ans)
# Original solution
import bisect

a, b, q =  [ int(v) for v in input().split() ]

temple_list = [ int(eval(input())) for i in range(a) ]
shrine_list = [ int(eval(input())) for i in range(b) ]


def excursion(x):
	global temple_list, shine_list
	temple_west = bisect.bisect_left(temple_list,x)
	shrine_west = bisect.bisect_left(shrine_list,x)

	tw, te, sw, se = temple_list[(temple_west-1)%a],temple_list[temple_west%a],shrine_list[(shrine_west-1)%b],shrine_list[(shrine_west)%b]
	print((min( abs(x-tw) + min(abs(sw-tw),abs(tw-se)) , abs(te-x) + min(abs(se-te),abs(te-sw)), abs(x-sw) + min(abs(tw-sw),abs(sw-te)) , abs(se-x) + min(abs(te-se),abs(se-tw)))))
	return 


for i in range(q):
	excursion(int(eval(input())))


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

a, b, q =  [ int(v) for v in input().split() ]

temple_list = [ int(eval(input())) for i in range(a) ]
shrine_list = [ int(eval(input())) for i in range(b) ]


def excursion(x):
	global temple_list, shine_list
	temple_west = bisect.bisect_left(temple_list,x)
	shrine_west = bisect.bisect_left(shrine_list,x)

	tw, te, sw, se = temple_list[(temple_west-1)%a],temple_list[temple_west%a],shrine_list[(shrine_west-1)%b],shrine_list[(shrine_west)%b]
	print((min( abs(x-tw) + min(abs(sw-tw),abs(tw-se)) , abs(te-x) + min(abs(se-te),abs(te-sw)), abs(x-sw) + min(abs(tw-sw),abs(sw-te)) , abs(se-x) + min(abs(te-se),abs(se-tw)))))
	return 


for i in range(q):
	excursion(int(eval(input())))
# Original solution
A,B,Q = list(map(int, input().split()))
s = [-(10**11)]+[int(eval(input())) for _ in range(A)]+[10**11]
t = [-(10**11)]+[int(eval(input())) for _ in range(B)]+[10**11]
s.sort()
t.sort()

import bisect
import itertools
for _ in range(Q):
    pos = int(eval(input()))
    s_near_id = bisect.bisect_left(s, pos)-1
    t_near_id = bisect.bisect_left(t, pos)-1
    print((min( min(abs(pos-s_pos)+abs(s_pos-t_pos), abs(pos-t_pos)+abs(t_pos-s_pos)) for s_pos, t_pos in itertools.product(s[s_near_id:s_near_id+2],t[t_near_id:t_near_id+2]) )))


# Optimized solution
A,B,Q = list(map(int, input().split()))
s = [-(10**11)]+[int(eval(input())) for _ in range(A)]+[10**11]
t = [-(10**11)]+[int(eval(input())) for _ in range(B)]+[10**11]
s.sort()
t.sort()
 
import bisect
import itertools
for _ in range(Q):
    pos = int(eval(input()))
    near_s = bisect.bisect_left(s, pos)-1
    near_t = bisect.bisect_left(t, pos)-1
    s1, s2 = s[near_s], s[near_s+1]
    t1, t2 = t[near_t], t[near_t+1]
    print((min(
        pos - min(s1,t1),
        max(s2,t2) - pos,
        (s2 - pos) + (s2 - t1),
        (pos - t1) + (s2 - t1),
        (t2 - pos) + (t2 - s1),
        (pos - s1) + (t2 - s1)
    )))
# 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)]

def bs(z, st):
    l = 0
    r = len(st) - 1
    while r - l != 1:
        m = (l + r) // 2
        if st[m] == z:
            return m
        elif st[m] < z:
            l = m
        else:
            r = m
    return l

for xi in x:
    tmps = []
    tmpt = []
    if xi <= s[0]:
        tmps.append(s[0] - xi)
    elif s[-1] <= xi:
        tmps.append(s[-1] - xi)
    else:
        tmp = bs(xi, s)
        tmps.append(s[tmp] - xi)
        tmps.append(s[tmp + 1] - xi)

    if xi <= t[0]:
        tmpt.append(t[0] - xi)
    elif t[-1] <= xi:
        tmpt.append(t[-1] - xi)
    else:
        tmp = bs(xi, t)
        tmpt.append(t[tmp] - xi)
        tmpt.append(t[tmp + 1] - xi)
    anss = []
    for i in tmps:
        for j in tmpt:
            if i // abs(i) == j // abs(j):
                anss.append(max(abs(i), abs(j)))
            else:
                maxij = max(abs(i), abs(j)) 
                minij = min(abs(i), abs(j)) 
                anss.append(abs(maxij + minij * 2))
    anss.sort()
    print((anss[0]))

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

def bs(z, st):
    l = 0
    r = len(st) - 1
    while r - l != 1:
        m = (l + r) // 2
        if st[m] <= z:
            l = m
        else:
            r = m
    return l

for xi in x:
    tmps = []
    tmpt = []
    if xi <= s[0]:
        tmps.append(s[0] - xi)
    elif s[-1] <= xi:
        tmps.append(s[-1] - xi)
    else:
        tmp = bs(xi, s)
        tmps.append(s[tmp] - xi)
        tmps.append(s[tmp + 1] - xi)

    if xi <= t[0]:
        tmpt.append(t[0] - xi)
    elif t[-1] <= xi:
        tmpt.append(t[-1] - xi)
    else:
        tmp = bs(xi, t)
        tmpt.append(t[tmp] - xi)
        tmpt.append(t[tmp + 1] - xi)
    anss = []
    for i in tmps:
        for j in tmpt:
            if i // abs(i) == j // abs(j):
                anss.append(max(abs(i), abs(j)))
            else:
                maxij = max(abs(i), abs(j)) 
                minij = min(abs(i), abs(j)) 
                anss.append(abs(maxij + minij * 2))
    anss.sort()
    print((anss[0]))
# Original 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)

# Optimized solution
import bisect

a,b,q = list(map(int,input().split()))
shrine = [-10**12, 10**12]
for _ in range(a):
    s = int(eval(input()))
    shrine.append(s)
shrine.sort()

temple = [-10**12, 10**12]
for _ in range(b):
    t = int(eval(input()))
    temple.append(t)
temple.sort()

for _ in range(q):
    x = int(eval(input()))
    sx = bisect.bisect_right(shrine,x)
    tx = bisect.bisect_right(temple,x)
    ans = 10**12
    for i in [shrine[sx-1], shrine[sx]]:
        for j in [temple[tx-1], temple[tx]]:
            case_1 = abs(i-x)+abs(i-j)
            case_2 = abs(j-x)+abs(i-j)
            ans = min(ans,case_1,case_2)
            
    print(ans)
# Original solution
import bisect
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)]
s.append(float('inf'))
s.insert(0, -float('inf'))
t.append(float('inf'))
t.insert(0, -float('inf'))
x = [int(eval(input())) for _i in range(q)]

for i in x:
    n = bisect.bisect_right(s, i)
    m = bisect.bisect_right(t, i)
    e = abs(max([s[n], t[m]])-i)
    f = abs(i-min(s[n-1], t[m-1]))
    g = min([abs(i-s[n]), abs(i-t[m-1])])+abs(s[n]-t[m-1])
    h = min([abs(i-s[n-1]), abs(i-t[m])])+abs(s[n-1]-t[m])
    print((min([e, f, g, h])))

# Optimized solution
import bisect
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)]
s.append(float('inf'))
s.insert(0, -float('inf'))
t.append(float('inf'))
t.insert(0, -float('inf'))
x = [int(eval(input())) for _i in range(q)]

for i in x:
    n = bisect.bisect_right(s, i)
    m = bisect.bisect_right(t, i)
    print((min([abs(max([s[n], t[m]])-i), min([abs(i-s[n-1]), abs(i-t[m])])+abs(s[n-1]-t[m]), min([abs(i-s[n]), abs(i-t[m-1])])+abs(s[n]-t[m-1]), abs(i-min(s[n-1], t[m-1]))])))