CodeEff/ECCO huggingface dataset:
# Original solution
import bisect
import sys
input = sys.stdin.readline
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]
ans = []
for i in range(q):
    x = int(eval(input()))
    idxs = bisect.bisect(s, x)
    idxt = bisect.bisect(t, x)
    ans.append(min(x - min(s[idxs - 1], t[idxt -1]),
                     x - s[idxs - 1] + (t[idxt] - s[idxs - 1]),
                     t[idxt] - x + (t[idxt] - s[idxs - 1]),
                     x - t[idxt - 1] + (s[idxs] - t[idxt - 1]),
                     s[idxs] - x + (s[idxs] - t[idxt - 1]),
                     max(s[idxs], t[idxt]) - x,
                     x - min(s[idxs - 1], t[idxt -1])))
for i in range(q):
    print((ans[i]))


# Optimized solution
import bisect
import sys
input = sys.stdin.readline
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]
ans = []
for i in range(q):
    x = int(eval(input()))
    idxs = bisect.bisect(s, x)
    idxt = bisect.bisect(t, x)
    ans.append(str(min(x - min(s[idxs - 1], t[idxt -1]),
                     x - s[idxs - 1] + (t[idxt] - s[idxs - 1]),
                     t[idxt] - x + (t[idxt] - s[idxs - 1]),
                     x - t[idxt - 1] + (s[idxs] - t[idxt - 1]),
                     s[idxs] - x + (s[idxs] - t[idxt - 1]),
                     max(s[idxs], t[idxt]) - x,
                     x - min(s[idxs - 1], t[idxt -1]))))
print(('\n'.join(ans)))
# Original 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]

def dis(x,p,q):
    return min(abs(x-s[p])+abs(s[p]-t[q]),abs(x-t[q])+abs(s[p]-t[q]))

def kai(x):
    res = INF
    s1 = bisect.bisect_right(s,x)
    ls = [s1,s1 - 1]
    t1 = bisect.bisect_right(t,x)
    lt = [t1,t1 - 1]
    for ss in ls:
        for st in lt:
            res = min(res,dis(x,ss,st))
    return res

for _ in range(q):
    x = int(eval(input()))
    print((kai(x)))


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

def kai(x):
    res = INF
    s1 = bisect.bisect_right(s,x)
    ls = [s1,s1 - 1]
    t1 = bisect.bisect_right(t,x)
    lt = [t1,t1 - 1]
    for ss in ls:
        for st in lt:
            res = min(res,abs(x-s[ss])+abs(s[ss]-t[st]),abs(x-t[st])+abs(s[ss]-t[st]))
    return res

lx = [int(eval(input())) for _ in range(q)]
for x in lx:
    print((kai(x)))
# Original solution
a, b, q = [int(i) for i in 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')]
x = [int(eval(input())) for _ in range(q)]

for xx in x:
  
  low = 0
  high = len(s)-1
  mid = (low+high)//2
  while low<=high:
    tmp = [i-xx for i in s[mid:mid+2]]
    if tmp[0] <= 0 and 0 <= tmp[1]:
      s_l = abs(tmp[0])
      s_r = abs(tmp[1])
      break
    elif tmp[0] > 0:
      high = mid
      mid = (low+high)//2
    else:
      low = mid
      mid = (low+high)//2
      
  low = 0
  high = len(t)-1
  mid = (low+high)//2
  while low<=high:
    tmp = [i-xx for i in t[mid:mid+2]]
    if tmp[0] <= 0 and 0 <= tmp[1]:
      t_l = abs(tmp[0])
      t_r = abs(tmp[1])
      break
    elif tmp[0] > 0:
      high = mid
      mid = (low+high)//2
    else:
      low = mid
      mid = (low+high)//2
  
  #print(s_l,s_r,t_l,t_r)
  
  #l = max(s_l,t_l)
  #r = max(s_r,t_r)
  if s_l <= t_l:
    l = t_l
    lr = s_l*2 + t_r
  else:
    l = s_l
    lr = t_l*2 + s_r
  if s_r <= t_r:
    r = t_r
    rl = s_r*2 + t_l
  else:
    r = s_r
    rl = t_r*2 + s_l
 
  ans = min(l,r,lr,rl)
  print(ans)
  


# Optimized solution
def search(x,r):
  low = 0
  high = len(r) - 1
  while low < high:
    mid = (low+high)//2
    if x < r[mid]:
      high = mid
    else:
      low = mid + 1
  return(abs(r[low-1]-x),abs(r[low]-x))
      
a, b, q = [int(i) for i in 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')]
x = [int(eval(input())) for _ in range(q)]

for xx in x:
  
  s_l,s_r=search(xx,s)
  t_l,t_r=search(xx,t)
  
  if s_l <= t_l:
    l = t_l
    lr = s_l*2 + t_r
  else:
    l = s_l
    lr = t_l*2 + s_r
  if s_r <= t_r:
    r = t_r
    rl = s_r*2 + t_l
  else:
    r = s_r
    rl = t_r*2 + s_l
 
  ans = min(l,r,lr,rl)
  print(ans)
# 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 find_left_and_right(st, pos):
    for i, s_i in enumerate(st):
        if s_i - pos > 0:
            return (i-1, i)
    return (len(st) - 1, -1)


def find_optimum(ss, ts, pos):
    (sl_index, sr_index) = find_left_and_right(ss, pos)
    (tl_index, tr_index) = find_left_and_right(ts, pos)

    penalty = 9999999999999
    s_left = s[sl_index] if 0 <= sl_index else penalty
    s_right = s[sr_index] if 0 <= sr_index else penalty
    t_left = t[tl_index] if 0 <= tl_index else penalty
    t_right = t[tr_index] if 0 <= tr_index else penalty

    dist0 = abs(s_left - pos) + min(abs(t_left - s_left), abs(t_right - s_left))
    dist1 = abs(s_right - pos) + min(abs(t_left - s_right), abs(t_right - s_right))
    dist2 = abs(t_left - pos) + min(abs(s_left - t_left), abs(s_right - t_left))
    dist3 = abs(t_right - pos) + min(abs(s_left - t_right), abs(s_right - t_right))
    return min([dist0, dist1, dist2, dist3])


for x_i in x:
    print((find_optimum(s, t, x_i)))

# Optimized solution
import bisect

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

for x_i in x:
    ss = bisect.bisect_left(s, x_i)
    tt = bisect.bisect_left(t, x_i)

    sc = [ss - 1, ss]
    tc = [tt - 1, tt]
    optimum = 10 ** 19
    for s_i in sc:
        for t_i in tc:
            dist = abs(s[s_i] - x_i) + abs(s[s_i] - t[t_i])
            if dist < optimum:
                optimum = dist
            dist = abs(t[t_i] - x_i) + abs(t[t_i] - s[s_i])
            if dist < optimum:
                optimum = dist
    print(optimum)
# Original solution
import sys
from bisect import bisect_left
inpurt = sys.stdin.readline
a, b, q = list(map(int, input().split()))
INF = 10 ** 11
s = [-INF]
for i in range(a):
    si = int(eval(input()))
    s.append(si)
s.append(INF)
t = [-INF]
for i in range(b):
    ti = int(eval(input()))
    t.append(ti)
t.append(INF)
x = []
for i in range(q):
    xi = int(eval(input()))
    x.append(xi)

for xi in x:
    index_s = bisect_left(s, xi)
    s1 = abs(xi - s[index_s - 1])
    s2 = abs(xi - s[index_s])
    index_t = bisect_left(t, xi)
    t1 = abs(xi - t[index_t - 1])
    t2 = abs(xi - t[index_t])
    print((min(max(s1, t1), max(s2, t2), min(s1, t2) * 2 + max(s1, t2), min(s2, t1) * 2 + max(s2, t1))))


# Optimized solution
import sys
from bisect import bisect_left
inpurt = sys.stdin.readline
a, b, q = list(map(int, input().split()))
INF = 10 ** 11
s = [-INF]
s_append = s.append
for i in range(a):
    si = int(eval(input()))
    s_append(si)
s_append(INF)
t = [-INF]
t_append = t.append
for i in range(b):
    ti = int(eval(input()))
    t_append(ti)
t_append(INF)
x = []
x_append = x.append
for i in range(q):
    xi = int(eval(input()))
    x_append(xi)

for xi in x:
    index_s = bisect_left(s, xi)
    s1 = abs(xi - s[index_s - 1])
    s2 = abs(xi - s[index_s])
    index_t = bisect_left(t, xi)
    t1 = abs(xi - t[index_t - 1])
    t2 = abs(xi - t[index_t])
    print((min(max(s1, t1), max(s2, t2), min(s1, t2) * 2 + max(s1, t2), min(s2, t1) * 2 + max(s2, t1))))
# Original solution
import sys
from bisect import bisect_left
inpurt = sys.stdin.readline
a, b, q = list(map(int, input().split()))
INF = 10 ** 11
s = [-INF]
s_append = s.append
for i in range(a):
    si = int(eval(input()))
    s_append(si)
s_append(INF)
t = [-INF]
t_append = t.append
for i in range(b):
    ti = int(eval(input()))
    t_append(ti)
t_append(INF)
x = []
x_append = x.append
for i in range(q):
    xi = int(eval(input()))
    x_append(xi)

for xi in x:
    index_s = bisect_left(s, xi)
    s1 = xi - s[index_s - 1]
    s2 = s[index_s] - xi
    index_t = bisect_left(t, xi)
    t1 = xi - t[index_t - 1]
    t2 = t[index_t] -xi
    print((min(max(s1, t1), max(s2, t2), min(s1, t2) * 2 + max(s1, t2), min(s2, t1) * 2 + max(s2, t1))))


# Optimized solution
import sys
from bisect import bisect_left
inpurt = sys.stdin.readline
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]
x = [int(eval(input())) for _ in range(q)]

for xi in x:
    index_s = bisect_left(s, xi)
    s1 = xi - s[index_s - 1]
    s2 = s[index_s] - xi
    index_t = bisect_left(t, xi)
    t1 = xi - t[index_t - 1]
    t2 = t[index_t] -xi
    print((min(max(s1, t1), max(s2, t2), min(s1, t2) * 2 + max(s1, t2), min(s2, t1) * 2 + max(s2, t1))))
# Original solution
A=list(map(int,input().split()))
S,T,X=[[int(eval(input())) for i in range(A[j])] for j in range(3)]
def binary(a,l,):
	low=0
	high=len(l)-1
	while high-low>1:
		mid=(low+high)//2
		if l[mid]<a:
			low=mid
		else:
			high=mid
	return [l[high],l[low]]
			
for x in X:
	s=set(binary(x,S))
	t=set(binary(x,T))
	Min=20000000000
	for i in s:
		for j in t:
			Min=min(Min,min(abs(x-i),abs(x-j))+abs(i-j))
	print(Min)
	

# Optimized solution
import sys
input=sys.stdin.readline
A=list(map(int,input().split()))
S,T,X=[[int(eval(input())) for i in range(A[j])] for j in range(3)]
def binary(a,l,):
	low=0
	high=len(l)-1
	while high-low>1:
		mid=(low+high)//2
		if l[mid]<a:
			low=mid
		else:
			high=mid
	return [l[high],l[low]]
			
for x in X:
	s=set(binary(x,S))
	t=set(binary(x,T))
	Min=20000000000
	for i in s:
		for j in t:
			Min=min(Min,min(abs(x-i),abs(x-j))+abs(i-j))
	print(Min)
# Original solution
from bisect import bisect_left

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


for q in Q:
    ps = bisect_left(S, q)
    if ps == len(S):
        s1, s2 = S[ps - 1], S[ps - 1]
    elif ps == 0:
        s1, s2 = S[ps], S[ps]
    else:
        s1, s2 = S[ps - 1], S[ps]

    pt = bisect_left(T, q)
    if pt == len(T):
        t1, t2 = T[pt - 1], T[pt - 1]
    elif pt == 0:
        t1, t2 = T[pt], T[pt]
    else:
        t1, t2 = T[pt - 1], T[pt]

    ans = 10 ** 11
    for s in (s1, s2):
        for t in (t1, t2):
            path1 = abs(q - s) + abs(s - t)
            path2 = abs(q - t) + abs(s - t)
            ans = min(ans, path1, path2)
    print(ans)


# Optimized solution
from bisect import bisect_left


INF = 10 ** 12
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]
Q = [int(eval(input())) for _ in range(Q)]


for q in Q:
    ps = bisect_left(S, q)
    s1, s2 = S[ps - 1], S[ps]

    pt = bisect_left(T, q)
    t1, t2 = T[pt - 1], T[pt]

    ans = INF
    for s in (s1, s2):
        for t in (t1, t2):
            path1 = abs(q - s) + abs(s - t)
            path2 = abs(q - t) + abs(s - t)
            ans = min(ans, path1, path2)
    print(ans)
# 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)]
inf = 10 ** 18

s = [-inf] + s + [inf]
t = [-inf] + t + [inf]

ans_Q = [None] * Q
i_last = j_last = 0
for idx, x_tmp in sorted(enumerate(x), key=lambda x: x[1]):
    i_l, i_r = i_last, A + 2
    while i_r - i_l > 1:
        m = i_l + (i_r - i_l) // 2
        # print("##", i_l, i_r, (m, s[m]), x_tmp)
        if s[m] <= x_tmp:
            i_l = m
        else:
            i_r = m
    #
    j_l, j_r = j_last, B + 2
    while j_r - j_l > 1:
        m = j_l + (j_r - j_l) // 2
        # print("##", j_l, j_r, (m, t[m]), x_tmp)
        if t[m] <= x_tmp:
            j_l = m
        else:
            j_r = m
    #
    ans = inf
    for i, j in ((i_l, j_l), (i_l + 1, j_l), (i_l, j_l + 1), (i_l + 1, j_l + 1)):
        if i < 1 or A < i: continue
        if j < 1 or B < j: continue
        ans_tmp_s = abs(x_tmp - s[i]) + abs(s[i] - t[j])
        ans_tmp_t = abs(x_tmp - t[j]) + abs(s[i] - t[j])
        ans_tmp = min(ans_tmp_s, ans_tmp_t)
        # print("#", x_tmp, s[i], t[j], ans_tmp)
        if ans > ans_tmp:
            ans = ans_tmp
    #
    i_last, j_last = i_l, j_l
    ans_Q[idx] = ans

for ansi in ans_Q: print(ansi)

# Optimized solution
import sys, 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)]
x = [int(eval(input())) for _ in range(Q)]
inf = 10 ** 18

s = [-inf] + s + [inf]
t = [-inf] + t + [inf]

ans_Q = [None] * Q
i_last = j_last = 0
for idx, x_tmp in sorted(enumerate(x), key=lambda x: x[1]):
    i_l = max(0, bisect.bisect_left(s, x_tmp, lo=i_last) - 1)
    j_l = max(0, bisect.bisect_left(t, x_tmp, lo=j_last) - 1)
    # print("#", x_tmp, (i_l, s[i_l]), (j_l, t[j_l]))
    #
    ans = inf
    for i, j in ((i_l, j_l), (i_l + 1, j_l), (i_l, j_l + 1), (i_l + 1, j_l + 1)):
        if i < 1 or A < i: continue
        if j < 1 or B < j: continue
        ans_tmp_s = abs(x_tmp - s[i]) + abs(s[i] - t[j])
        ans_tmp_t = abs(x_tmp - t[j]) + abs(s[i] - t[j])
        ans_tmp = min(ans_tmp_s, ans_tmp_t)
        # print("#", x_tmp, s[i], t[j], ans_tmp)
        if ans > ans_tmp:
            ans = ans_tmp
    #
    i_last, j_last = i_l, j_l
    ans_Q[idx] = ans

for ansi in ans_Q: print(ansi)
# Original solution
import bisect

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

for i in range(Q):
    sx, tx, sy, ty = [], [], [], []
    for j in s:
        sx.append(abs(j - x[i]))
    for j in t:
        tx.append(abs(j - x[i]))
    sxi = sx.index(min(sx))
    txi = tx.index(min(tx))
    for j in t:
        ty.append(abs(j - s[sxi]))
    for j in s:
        sy.append(abs(j - t[txi]))
    a = min(sx) + min(ty)
    b = min(tx) + min(sy)
    if a < b:
        print((str(a)))
    else:
        print((str(b)))


# Optimized solution
import bisect

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

for x in X:
    a, b = 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[a-1:a+1] for t in T[b-1:b+1])))
# 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_left(s, x), bisect.bisect_left(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()))
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
from bisect import bisect
A,B,Q = map(int,input().split())
S = [int(input()) for i in range(A)]
T = [int(input()) for i in range(B)]
qs = [int(input()) for i in range(Q)]

st = []
for s in S:
    ti = bisect(T,s)
    if ti == 0:
        st.append(abs(s-T[0]))
    elif ti == B:
        st.append(abs(s-T[-1]))
    else:
        tmp = min(abs(s-T[ti-1]), abs(s-T[ti]))
        st.append(tmp)

ts = []
for t in T:
    si = bisect(S,t)
    if si == 0:
        ts.append(abs(t-S[0]))
    elif si == A:
        ts.append(abs(t-S[-1]))
    else:
        tmp = min(abs(t-S[si-1]), abs(t-S[si]))
        ts.append(tmp)

ans = []
for q in qs:
    si = bisect(S,q)
    if si == 0:
        a = abs(q-S[0]) + st[0]
    elif si == A:
        a = abs(q-S[-1]) + st[-1]
    else:
        a = min(abs(q-S[si-1]) + st[si-1], abs(q-S[si]) + st[si])

    ti = bisect(T,q)
    if ti == 0:
        b = abs(q-T[0]) + ts[0]
    elif ti == B:
        b = abs(q-T[-1]) + ts[-1]
    else:
        b = min(abs(q-T[ti-1]) + ts[ti-1], abs(q-T[ti]) + ts[ti])

    ans.append(min(a,b))

print(*ans, sep='\n')


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

A,B,Q = map(int,input().split())
S = [int(input()) for i in range(A)]
T = [int(input()) for i in range(B)]
X = [int(input()) for i in range(Q)]

INF = float('inf')
st = []
for s in S:
    i = bisect(T,s)
    x0,x1 = -INF,INF
    if i > 0: x0 = T[i-1]
    if i < B: x1 = T[i]
    st.append(min(s-x0, x1-s))
ts = []
for t in T:
    i = bisect(S,t)
    x0,x1 = -INF,INF
    if i > 0: x0 = S[i-1]
    if i < A: x1 = S[i]
    ts.append(min(t-x0, x1-t))

ans = []
for x in X:
    d0 = d1 = d2 = d3 = INF
    si = bisect(S,x)
    if si > 0:
        d0 = x-S[si-1] + st[si-1]
    if si < A:
        d1 = S[si]-x + st[si]
    ti = bisect(T,x)
    if ti > 0:
        d2 = x-T[ti-1] + ts[ti-1]
    if ti < B:
        d3 = T[ti]-x + ts[ti]
    ans.append(min(d0,d1,d2,d3))
print(*ans, sep='\n')
# Original solution
import bisect

def main():
    A, B, Q = list(map(int, input().split()))
    s = list(int(eval(input())) for _ in range(A))
    t = list(int(eval(input())) for _ in range(B))

    sort_s = sorted(s)
    sort_t = sorted(t)
    for _ in range(Q):
        x = int(eval(input()))
        s_near = bisect.bisect_left(sort_s, x)
        t_near = bisect.bisect_left(sort_t, x)

        s_candidate = []
        t_candidate = []

        if s_near == 0:
            s_candidate.append(sort_s[s_near])
        elif s_near == A:
            s_candidate.append(sort_s[s_near-1])
        else:
            s_candidate.append(sort_s[s_near])
            s_candidate.append(sort_s[s_near-1])
        
        if t_near == 0:
            t_candidate.append(sort_t[t_near])
        elif t_near == B:
            t_candidate.append(sort_t[t_near-1])
        else:
            t_candidate.append(sort_t[t_near])
            t_candidate.append(sort_t[t_near-1])

        ans = float('inf')
        # sを先に訪れるパターンを考える
        for i in s_candidate:
            for j in t_candidate:
                tmp = abs(x - i) + abs(i - j)
                ans = min(ans, tmp)

        # tをさきに訪れるパターンを考える
        for k in t_candidate:
            for l in s_candidate:
                tmp = abs(x - k) + abs(k - l)
                ans = min(ans, tmp)

        print(ans)
        
main()

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

def main():
    A, B, Q = list(map(int, input().split()))
    s = list(int(eval(input())) for _ in range(A))
    t = list(int(eval(input())) for _ in range(B))

    sort_s = sorted(s)
    sort_t = sorted(t)
    for _ in range(Q):
        x = int(eval(input()))
        s_near = bisect.bisect_left(sort_s, x)
        t_near = bisect.bisect_left(sort_t, x)

        s_candidate = []
        t_candidate = []

        if s_near == 0:
            s_candidate.append(sort_s[s_near])
        elif s_near == A:
            s_candidate.append(sort_s[s_near-1])
        else:
            s_candidate.append(sort_s[s_near])
            s_candidate.append(sort_s[s_near-1])
        
        if t_near == 0:
            t_candidate.append(sort_t[t_near])
        elif t_near == B:
            t_candidate.append(sort_t[t_near-1])
        else:
            t_candidate.append(sort_t[t_near])
            t_candidate.append(sort_t[t_near-1])

        ans = float('inf')
        # sを先に訪れるパターンを考える
        for i in s_candidate:
            for j in t_candidate:
                tmp = abs(x - i) + abs(i - j)
                ans = min(ans, tmp)

        # tをさきに訪れるパターンを考える
        for k in t_candidate:
            for l in s_candidate:
                tmp = abs(x - k) + abs(k - l)
                ans = min(ans, tmp)

        print(ans)

main()
# Original solution
# -*- coding: utf-8 -*-
"""
D - Lazy Faith
https://atcoder.jp/contests/abc119/tasks/abc119_d

"""
import sys
from bisect import bisect_left, bisect_right

def solve(x):
    i = bisect_right(shrines, x)
    ds = x - shrines[i-1]
    j = bisect_right(temples, x)
    dt = x - temples[j-1]
    ans1 = max(ds, dt)

    i = bisect_left(shrines, x)
    ds = shrines[i] - x
    j = bisect_left(temples, x)
    dt = temples[j] - x
    ans2 = max(ds, dt)

    i = bisect_left(shrines, x)
    ds = shrines[i] - x
    j = bisect_right(temples, x)
    dt = x - temples[j-1]
    ans3 = min(ds, dt) * 2 + max(ds, dt)

    i = bisect_right(shrines, x)
    ds = x - shrines[i-1]
    j = bisect_left(temples, x)
    dt = temples[j] - x
    ans4 = min(ds, dt) * 2 + max(ds, dt)

    return min(ans1, ans2, ans3, ans4)


shrines = None
temples = None

def main(args):
    global shrines, temples
    A, B, Q = list(map(int, input().split()))
    shrines = sorted([int(eval(input())) for _ in range(A)] + [float('-inf'), float('inf')])
    temples = sorted([int(eval(input())) for _ in range(B)] + [float('-inf'), float('inf')])
    for _ in range(Q):
        x = int(eval(input()))
        ans = solve(x)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


# Optimized solution
# -*- coding: utf-8 -*-
"""
D - Lazy Faith
https://atcoder.jp/contests/abc119/tasks/abc119_d

"""
import sys
from bisect import bisect_left, bisect_right

def solve(x):
    i = bisect_right(shrines, x)
    s_left = x - shrines[i-1]
    j = bisect_right(temples, x)
    t_left = x - temples[j-1]

    i = bisect_left(shrines, x)
    s_right = shrines[i] - x
    j = bisect_left(temples, x)
    t_right = temples[j] - x

    ans1 = max(s_left, t_left)
    ans2 = max(s_right, t_right)
    ans3 = min(s_right, t_left) * 2 + max(s_right, t_left)
    ans4 = min(s_left, t_right) * 2 + max(s_left, t_right)
    return min(ans1, ans2, ans3, ans4)


shrines = None
temples = None

def main(args):
    global shrines, temples
    A, B, Q = list(map(int, input().split()))
    shrines = [float('-inf')] + [int(eval(input())) for _ in range(A)] + [float('inf')]
    temples = [float('-inf')] + [int(eval(input())) for _ in range(B)] + [float('inf')]
    for _ in range(Q):
        x = int(eval(input()))
        ans = solve(x)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])