CodeEff/ECCO huggingface dataset:
# 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])
        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)
        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)
# Original solution
A, B, Q = list(map(int,input().split()))

ss = [-10**10]+[int(eval(input())) for _ in range(A)]+[2*10**10]
ts = [-10**10]+[int(eval(input())) for _ in range(B)]+[2*10**10]
# xs = [int(input()) for _ in range(Q)]

def binarysearch(ls,x):
    n = len(ls)
    width = n//2
    pos = n//2
    while True:
        width = (width+1)//2
        if ls[pos] < x < ls[pos+1]:
            index = pos
            break    
        elif x < ls[pos]:
            pos -= width
        elif ls[pos+1] < x:
            pos += width
        pos = min(n-1,pos)
        pos = max(pos,0)
    return index

# for x in xs:
for i in range(Q):
    x = int(eval(input()))
    sind = binarysearch(ss,x)
    tind = binarysearch(ts,x)
    
    s0,s1,t0,t1 = ss[sind],ss[sind+1],ts[tind],ts[tind+1]
    d1,d2,d3,d4 = 10**10,10**10,10**10,10**10

    d1 = max(x-s0,x-t0)
    d2 = min((t1-x)*2+(x-s0),(x-s0)*2+(t1-x))
    d3 = min((s1-x)*2+(x-t0),(x-t0)*2+(s1-x))
    d4 = max(s1-x, t1-x)
    print((min(d1,d2,d3,d4)))

# Optimized solution
from bisect import bisect_right as binarysearch
A, B, Q = list(map(int,input().split()))

ss = [-10**10]+[int(eval(input())) for _ in range(A)]+[2*10**10]
ts = [-10**10]+[int(eval(input())) for _ in range(B)]+[2*10**10]
xs = [int(eval(input())) for _ in range(Q)]
for x in xs:
    sind = binarysearch(ss,x)-1
    tind = binarysearch(ts,x)-1
    
    s0,s1,t0,t1 = ss[sind],ss[sind+1],ts[tind],ts[tind+1]
    d1,d2,d3,d4 = 10**10,10**10,10**10,10**10

    d1 = max(x-s0,x-t0)
    d2 = min((t1-x)*2+(x-s0),(x-s0)*2+(t1-x))
    d3 = min((s1-x)*2+(x-t0),(x-t0)*2+(s1-x))
    d4 = max(s1-x, t1-x)
    print((min(d1,d2,d3,d4)))
# Original solution
def main():
    a,b,q = list(map(int,input().split()))
    A = []
    B = []
    
    for _ in range(a):
        A.append(int(eval(input())))
    
    for _ in range(b):
        B.append(int(eval(input())))
    
    def search(A,x):
        left =0
        right = len(A)-1
        
        if x<A[0]:
            return (float('inf'),0)
        if x >A[-1]:
            return (right,float('inf'))
        
        while left != right-1:
            center = (left+right)//2
            
            if A[center] > x:
                right = center
            else:
                left = center
        
        return (left,right)
    
    
    def dist(A,x,lr):
        if lr == float('inf'):
            return float('inf')
        return abs(x - A[lr])
    
    for _ in range(q):
        x = int(eval(input()))
        sl,sr = search(A,x)
        tl,tr = search(B,x)
        sl = dist(A,x,sl)
        sr = dist(A,x,sr)
        tl = dist(B,x,tl)
        tr = dist(B,x,tr)
        p1 = min(sl,sr)+min(tl,tr)+min(min(sl,sr),min(tl,tr))
        p2 = max(sl,tl)
        p3 = max(sr,tr)
        print((min(p1,p2,p3)))

if __name__ == '__main__':
    main()
    
    
    



# Optimized solution
def main():
    a,b,q = list(map(int,input().split()))
    A = []
    B = []
    
    for _ in range(a):
        A.append(int(eval(input())))
    
    for _ in range(b):
        B.append(int(eval(input())))
    
    def search(A,x):
        left =0
        right = len(A)-1
        
        if x<A[0]:
            return (float('inf'),abs(x - A[left]))
        if x >A[-1]:
            return (abs(x - A[right]),float('inf'))
        
        while left != right-1:
            center = (left+right)//2
            
            if A[center] > x:
                right = center
            else:
                left = center
        
        return (abs(x - A[left]),abs(x - A[right]))
    
    
    def dist(A,x,lr):
        if lr == float('inf'):
            return float('inf')
        return abs(x - A[lr])
    
    for _ in range(q):
        x = int(eval(input()))
        sl,sr = search(A,x)
        tl,tr = search(B,x)
        p1 = min(sl,sr)+min(tl,tr)+min(min(sl,sr),min(tl,tr))
        p2 = max(sl,tl)
        p3 = max(sr,tr)
        print((min(p1,p2,p3)))

if __name__ == '__main__':
    main()
# Original solution
def main():
    a,b,q = list(map(int,input().split()))
    A = []
    B = []
    
    for _ in range(a):
        A.append(int(eval(input())))
    
    for _ in range(b):
        B.append(int(eval(input())))
    
    def search(A,x):
        left =0
        right = len(A)-1
        
        if x<A[0]:
            return (float('inf'),abs(x - A[left]))
        if x >A[-1]:
            return (abs(x - A[right]),float('inf'))
        
        while left != right-1:
            center = (left+right)//2
            
            if A[center] > x:
                right = center
            else:
                left = center
        
        return (abs(x - A[left]),abs(x - A[right]))
    
    
    def dist(A,x,lr):
        if lr == float('inf'):
            return float('inf')
        return abs(x - A[lr])
    
    for _ in range(q):
        x = int(eval(input()))
        sl,sr = search(A,x)
        tl,tr = search(B,x)
        print((min(min(sl,sr)+min(tl,tr)+min(min(sl,sr),min(tl,tr)),max(sl,tl),max(sr,tr))))

if __name__ == '__main__':
    main()

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


def main():
    a,b,q = list(map(int,readline().split()))
    A = [int(readline()) for i in range(a)]
    B = [int(readline()) for i in range(b)]
    def search(A,x):
        left =0
        right = len(A)-1
        
        if x<A[0]:
            return (float('inf'),abs(x - A[left]))
        if x >A[-1]:
            return (abs(x - A[right]),float('inf'))
        
        while left != right-1:
            center = (left+right)//2
            
            if A[center] > x:
                right = center
            else:
                left = center
        
        return (abs(x - A[left]),abs(x - A[right]))
    
    
    def dist(A,x,lr):
        if lr == float('inf'):
            return float('inf')
        return abs(x - A[lr])
    
    for _ in range(q):
        x = int(readline())
        sl,sr = search(A,x)
        tl,tr = search(B,x)
        print((min(min(sl,sr)+min(tl,tr)+min(min(sl,sr),min(tl,tr)),max(sl,tl),max(sr,tr))))

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

A, B, Q = list(map(int, input().split()))
INF = float('inf')
s = [- INF] + [int(eval(input())) for i in range(A)] + [INF]
t = [- INF] + [int(eval(input())) for i in range(B)] + [INF]

for i in range(Q):
    x = int(eval(input()))
    b, d = bisect.bisect_left(s, x), bisect.bisect_left(t, x)
    ans = 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)
            ans = min(ans, d1, d2)
    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 i in range(Q):
    x = int(eval(input()))
    b, d = bisect.bisect_left(s, x), bisect.bisect_left(t, x)
    ans = 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)
            ans = min(ans, d1, d2)
    print(ans)
# Original solution
a,b,q = list(map(int, input().split()))

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.sort()
t.sort()

#print(s)
#print(t)
import bisect
for xi in x:
    i = bisect.bisect_left(s,xi)
    s_right = 10**11
    if i < len(s):
        s_right = s[i] - xi
    s_left = 10**11
    if i != 0:
        s_left = xi - s[i-1]
    j = bisect.bisect_left(t,xi)
    t_right = 10**11
    if j < len(t):
        t_right = t[j] - xi
    t_left = 10**11
    if j != 0:
        t_left = xi - t[j-1]
    #print(i,j,xi)
    #print(s_left,s_right,t_left,t_right)
    ans = min(max(s_right,t_right), max(s_left,t_left), min(s_left,t_right)*2+max(s_left,t_right), min(s_right,t_left)*2+max(s_right,t_left))
    print(ans)


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

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.sort()
t.sort()

INT_MAX = 10**11

#print(s)
#print(t)
import bisect
def func(xi):
    i = bisect.bisect_left(s,xi)
    s_right = INT_MAX
    if i < len(s):
        s_right = s[i] - xi
    s_left = INT_MAX
    if i != 0:
        s_left = xi - s[i-1]
    j = bisect.bisect_left(t,xi)
    t_right = INT_MAX
    if j < len(t):
        t_right = t[j] - xi
    t_left = INT_MAX
    if j != 0:
        t_left = xi - t[j-1]
    #print(i,j,xi)
    #print(s_left,s_right,t_left,t_right)
    return min(max(s_right,t_right), max(s_left,t_left), min(s_left,t_right)*2+max(s_left,t_right), min(s_right,t_left)*2+max(s_right,t_left))

ans = list(map(func, x))
print(("\n".join(map(str,ans))))
# 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)]
x = [int(eval(input())) for _ in range(Q)]

for xx in x:
    # 神先
    ps_r = 0
    s_r = bisect_left(s, xx)
    if s_r < A:
        ps_r += s[s_r] - xx
        t_r = bisect_left(t, s[s_r])
        t_l = t_r - 1

        b = 0
        if t_r < B:
            b = t[t_r] - s[s_r]
        if 0 <= t_l < B:
            if b == 0:
                b = s[s_r] - t[t_l]
            else:
                b = min(b, s[s_r] - t[t_l])
        ps_r += b
    else:
        ps_r = 10 ** 12

    ps_l = 0
    s_l = s_r - 1
    if 0 <= s_l < A:
        ps_l += xx - s[s_l]
        t_r = bisect_left(t, s[s_l])
        t_l = t_r - 1

        b = 0
        if t_r < B:
            b = t[t_r] - s[s_l]
        if 0 <= t_l < B:
            if b == 0:
                b = s[s_l] - t[t_l]
            else:
                b = min(b, s[s_l] - t[t_l])
        ps_l += b
    else:
        ps_l = 10 ** 12

    # 寺前
    pt_r = 0
    t_r = bisect_left(t, xx)
    if t_r < B:
        pt_r += t[t_r] - xx
        s_r = bisect_left(s, t[t_r])
        s_l = s_r - 1

        b = 0
        if s_r < A:
            b = s[s_r] - t[t_r]
        if 0 <= s_l < A:
            if b == 0:
                b = t[t_r] - s[s_l]
            else:
                b = min(b, t[t_r] - s[s_l])
        pt_r += b
    else:
        pt_r = 10 ** 12

    pt_l = 0
    t_l = t_r - 1
    if 0 <= t_l < B:
        pt_l += xx - t[t_l]
        s_r = bisect_left(s, t[t_l])
        s_l = s_r - 1

        b = 0
        if s_r < A:
            b = s[s_r] - t[t_l]
        if 0 <= s_l < A:
            if b == 0:
                b = t[t_l] - s[s_l]
            else:
                b = min(b, t[t_l] - s[s_l])
        pt_l += b
    else:
        pt_l = 10 ** 12

    # print(ps_r, ps_l, pt_r, pt_l)
    print((min(ps_r, ps_l, pt_r, pt_l)))


# Optimized solution
from bisect import bisect_left
from itertools import product

inf = float('inf')

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

for xx in x:
    ret = inf

    sr = bisect_left(s, xx)  # xx以上の最小値
    sl = max(0, sr - 1)

    tr = bisect_left(t, xx)
    tl = max(0, tr - 1)

    for ss, tt in product(s[sl:sr + 1], t[tl:tr + 1]):
        ret = min(
            ret,
            abs(xx - ss) + abs(ss - tt),
            abs(xx - tt) + abs(tt - ss)
        )
    print(ret)
# Original solution
from bisect import bisect

A, B, Q = list(map(int, input().split()))
s = [-10**15]
t = [-10**15]
for _ in range(A):
    s.append(int(eval(input())))
s.append(10**15)
for _ in range(B):
    t.append(int(eval(input())))
t.append(10**15)
x = list(map(int, (eval(input()) for _ in range(Q))))
for y in x:
    i = bisect(s, y)
    j = bisect(t, y)
    ans = min(
        max(abs(s[i] - y), abs(t[j] - y)),
        max(abs(s[i - 1] - y), abs(t[j - 1] - y)),
        2 * min(abs(s[i] - y), abs(t[j - 1] - y)) + max(abs(s[i] - y), abs(t[j - 1] - y)),
        2 * min(abs(s[i - 1] - y), abs(t[j] - y)) + max(abs(s[i - 1] - y), abs(t[j] - y))
    )
    print(ans)

# Optimized solution
from bisect import bisect

A, B, Q = list(map(int, input().split()))
s = [-10**15] + [int(eval(input())) for i in range(A)] + [10**15]
t = [-10**15] + [int(eval(input())) for i in range(B)] + [10**15]
# s = [-10**15]
# t = [-10**15]
# for _ in range(A):
#     s.append(int(input()))
# s.append(10**15)
# for _ in range(B):
#     t.append(int(input()))
# t.append(10**15)
x = list(map(int, (eval(input()) for _ in range(Q))))
for y in x:
    i = bisect(s, y)
    j = bisect(t, y)
    ans = min(
        max(abs(s[i] - y), abs(t[j] - y)),
        max(abs(s[i - 1] - y), abs(t[j - 1] - y)),
        2 * min(abs(s[i] - y), abs(t[j - 1] - y)) + max(abs(s[i] - y), abs(t[j - 1] - y)),
        2 * min(abs(s[i - 1] - y), abs(t[j] - y)) + max(abs(s[i - 1] - y), abs(t[j] - y))
    )
    print(ans)
# 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
from bisect import bisect_right

A, B, Q = list(map(int, input().split()))
INF = 10**18
s = [-INF]
t = [-INF]
for _ in range(A):
    s.append(int(eval(input())))
s.append(INF)
for _ in range(B):
    t.append(int(eval(input())))
t.append(INF)
x = list(map(int, (eval(input()) for _ in range(Q))))
for y in x:
    i = bisect_right(s, y)
    j = bisect_right(t, y)
    # ans = INF
    # for S in [s[i - 1], s[i]]:
    #     for T in [t[j - 1], t[j]]:
    #         d1, d2 = abs(S - y) + abs(T - S), abs(T - y) + abs(S - T)
    #         ans = min(ans, d1, d2)
    ans = min(
        max(abs(s[i] - y), abs(t[j] - y)),
        max(abs(s[i - 1] - y), abs(t[j - 1] - y)),
        2 * min(abs(s[i] - y), abs(t[j - 1] - y)) + max(abs(s[i] - y), abs(t[j - 1] - y)),
        2 * min(abs(s[i - 1] - y), abs(t[j] - y)) + max(abs(s[i - 1] - y), abs(t[j] - y))
    )
    print(ans)
# Original solution
import bisect
A, B, Q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF]
t = [-INF]
for _ in range(A):
    s.append(int(eval(input())))
s.append(INF)
for _ in range(B):
    t.append(int(eval(input())))
t.append(INF)
for q in range(Q):
    x = int(eval(input()))
    i, j = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    ans = min(
        max(abs(s[i] - x), abs(t[j] - x)),
        max(abs(s[i - 1] - x), abs(t[j - 1] - x)),
        2 * min(abs(s[i] - x), abs(t[j - 1] - x)) + max(abs(s[i] - x), abs(t[j - 1] - x)),
        2 * min(abs(s[i - 1] - x), abs(t[j] - x)) + max(abs(s[i - 1] - x), abs(t[j] - x))
    )
    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 i in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
xs = [int(eval(input())) for i in range(Q)]
for x in xs:
    b, d = bisect_right(s, x), 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_right
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]
xs = [int(eval(input())) for i in range(Q)]
for x in xs:
    b, d = bisect_right(s, x), 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
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]


# 指定した変位に対する問に二分探索を用いて回答
def f(y):
    i = bisect_right(S, y)
    j = bisect_right(T, y)
    return min(
        abs(b - a) + min(abs(a - y), abs(b - y))
        for a in (S[i - 1], S[i])
        for b in (T[j - 1], T[j])
    )


# 各問に対して、fにより解を得る
ans = '\n'.join(map(str, list(map(f, x))))

# 出力
print(ans)
# Original solution
from bisect import bisect_left, bisect_right
a, b, q = list(map(int, input().split()))
inf = 10**18
shrine = [-inf] + [int(eval(input())) for _ in range(a)] + [inf]
temple = [-inf] + [int(eval(input())) for _ in range(b)] + [inf]

for _ in range(q):
    ans = inf
    x = int(eval(input()))
    index_s = bisect_left(shrine, x)
    index_t = bisect_right(temple, x)
    for i in range(index_s-1, index_s+1):
        s = shrine[i]
        i_t = bisect_left(temple, s)
        t0, t1 = temple[i_t-1], temple[i_t]
        ans = min(
            ans,
            abs(x - s) + abs(s - t0),
            abs(x - s) + abs(s - t1),
        )

    for i in range(index_t-1, index_t+1):
        t = temple[i]
        i_s = bisect_left(shrine, t)
        s0 = shrine[i_s - 1]
        s1 = shrine[i_s]
        ans = min(
            ans,
            abs(x - t) + abs(t - s0),
            abs(x - t) + abs(t - s1),
        )

    print(ans)


# Optimized solution
from bisect import bisect_left, bisect_right
a, b, q = list(map(int, input().split()))
inf = 10**18
shrine = [-inf] + [int(eval(input())) for _ in range(a)] + [inf]
temple = [-inf] + [int(eval(input())) for _ in range(b)] + [inf]

for _ in range(q):
    ans = inf
    x = int(eval(input()))
    index_s = bisect_left(shrine, x)
    index_t = bisect_right(temple, x)
    for i in range(index_s-1, index_s+1):
        s = shrine[i]
        i_t = index_t
        t0, t1 = temple[i_t-1], temple[i_t]
        ans = min(
            ans,
            abs(x - s) + abs(s - t0),
            abs(x - s) + abs(s - t1),
        )

    for i in range(index_t-1, index_t+1):
        t = temple[i]
        i_s = index_s
        s0 = shrine[i_s - 1]
        s1 = shrine[i_s]
        ans = min(
            ans,
            abs(x - t) + abs(t - s0),
            abs(x - t) + abs(t - s1),
        )

    print(ans)
# 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()))
    s=bisect.bisect_right(S,x)
    t=bisect.bisect_right(T,x)
    d=INF
    for i in [S[s-1],S[s]]:
        for j in [T[t-1],T[t]]:
            ds=abs(i-x)+abs(i-j)
            dt=abs(j-x)+abs(i-j)
            d=min(d,ds,dt)
    print(d)

# 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()))
    i=bisect.bisect_left(S,x)
    j=bisect.bisect_left(T,x)
    ans=INF
    for s in [S[i-1],S[i]]:
        for t in [T[j-1],T[j]]:
            d1=abs(s-x)+abs(s-t)
            d2=abs(t-x)+abs(s-t)
            ans=min(ans,d1,d2)
    print(ans)
# Original solution
import bisect
import itertools

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

for _ in range(Q):
    answer = INF
    x = int(eval(input()))
    si = bisect.bisect_left(S, x)    
    ti = bisect.bisect_left(T, x)
    for s, t in itertools.product(S[si-1:si+1], T[ti-1:ti+1]):
        d = min(abs(s-x), abs(t-x)) + abs(t-s)            
        answer = min(answer, d)
    print(answer)

# Optimized solution
import bisect
import itertools

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

# 簡略化のため常に左右に存在するようにしておく
INF = 10 ** 15
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 solve(x):
  # xの位置
  i = bisect.bisect_left(S, x)
  j = bisect.bisect_left(T, x)
  result = INF
  # どの2つを目指すのか
  for s,t in itertools.product(S[i-1:i+1], T[j-1:j+1]):
    d = min(abs(s-x),abs(t-x)) + abs(t-s)
    result = min(result,d)
  return result

for x in X:
  answer = solve(x)
  print(answer)
# Original solution
import bisect
import itertools

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

# 簡略化のため常に左右に存在するようにしておく
INF = 10 ** 15
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 solve(x):
  # xの位置
  i = bisect.bisect_left(S, x)
  j = bisect.bisect_left(T, x)
  result = INF
  # どの2つを目指すのか
  for s,t in itertools.product(S[i-1:i+1], T[j-1:j+1]):
    d = min(abs(s-x),abs(t-x)) + abs(t-s)
    result = min(result,d)
  return result

for x in X:
  answer = solve(x)
  print(answer)


# Optimized solution
# coding: utf-8
import sys
from bisect import bisect_left

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 番兵を左右に置いて、4通り試す
A, B, Q = lr()
INF = 10 ** 12
S = [-INF] + [ir() for _ in range(A)] + [INF]
T = [-INF] + [ir() for _ in range(B)] + [INF]
S.sort(); T.sort()
for _ in range(Q):
    x = ir()
    si = bisect_left(S, x)
    ti = bisect_left(T, x)
    temp = []
    temp.append(max(S[si], T[ti]) - x)
    y = abs(S[si] - x)
    z = abs(T[ti-1] - x)
    temp.append(min(y, z) * 2 + max(y, z))
    y = abs(S[si-1] - x)
    z = abs(T[ti] - x)
    temp.append(min(y, z) * 2 + max(y, z))
    temp.append(x - min(S[si-1], T[ti-1]))
    print((min(temp)))

# 46