import bisect

A, B, Q = map(int, input().split())
K = []
T = []
for i in range(A):
    K.append(int(input()))
for j in range(B):
    T.append(int(input()))
K.sort()
T.sort()
l_1 = len(K)
l_2 = len(T)

Ans = []
for i in range(Q):
    c = int(input())
    p = bisect.bisect_right(K, c)
    if p >= l_1:
        p -= 1
    dis_1 = abs(c - K[p-1])
    dis_2 = abs(c - K[p])
    q_1 = bisect.bisect_right(T, K[p-1])
    q_2 = bisect.bisect_right(T, K[p])
    if q_1 >= l_2:
        q_1 -= 1
    if q_2 >= l_2:
        q_2 -= 1
    result_1 = min([dis_1 + abs(K[p-1] - T[q_1-1]), dis_1 + abs(K[p-1] - T[q_1]), dis_2 + abs(K[p] - T[q_2-1]), dis_2 + abs(K[p] - T[q_2])])

    p = bisect.bisect_right(T, c)
    if p >= l_2:
        p -= 1
    dis_1 = abs(c - T[p-1])
    dis_2 = abs(c - T[p])
    q_1 = bisect.bisect_right(K, T[p-1])
    q_2 = bisect.bisect_right(K, T[p])
    if q_1 >= l_1:
        q_1 -= 1
    if q_2 >= l_1:
        q_2 -= 1
    result_2 = min([dis_1 + abs(T[p-1] - K[q_1-1]), dis_1 + abs(T[p-1] - K[q_1]), dis_2 + abs(T[p] - K[q_2-1]), dis_2 + abs(T[p] - K[q_2])])
    Ans.append(min(result_1, result_2))

for i in Ans:
    print(i) import bisect bisect A, B, Q = map(int, input().split()) A map(int, input().split()) map int input().split() ().split () input split B Q K = [] K [] T = [] T [] for i in range(A):
    K.append(int(input())) i range(A) range A K.append(int(input())) K.append K append int(input()) int input() input for j in range(B):
    T.append(int(input())) j range(B) range B T.append(int(input())) T.append T append int(input()) int input() input K.sort() K.sort K sort T.sort() T.sort T sort l_1 = len(K) l_1 len(K) len K l_2 = len(T) l_2 len(T) len T Ans = [] Ans [] for i in range(Q):
    c = int(input())
    p = bisect.bisect_right(K, c)
    if p >= l_1:
        p -= 1
    dis_1 = abs(c - K[p-1])
    dis_2 = abs(c - K[p])
    q_1 = bisect.bisect_right(T, K[p-1])
    q_2 = bisect.bisect_right(T, K[p])
    if q_1 >= l_2:
        q_1 -= 1
    if q_2 >= l_2:
        q_2 -= 1
    result_1 = min([dis_1 + abs(K[p-1] - T[q_1-1]), dis_1 + abs(K[p-1] - T[q_1]), dis_2 + abs(K[p] - T[q_2-1]), dis_2 + abs(K[p] - T[q_2])])

    p = bisect.bisect_right(T, c)
    if p >= l_2:
        p -= 1
    dis_1 = abs(c - T[p-1])
    dis_2 = abs(c - T[p])
    q_1 = bisect.bisect_right(K, T[p-1])
    q_2 = bisect.bisect_right(K, T[p])
    if q_1 >= l_1:
        q_1 -= 1
    if q_2 >= l_1:
        q_2 -= 1
    result_2 = min([dis_1 + abs(T[p-1] - K[q_1-1]), dis_1 + abs(T[p-1] - K[q_1]), dis_2 + abs(T[p] - K[q_2-1]), dis_2 + abs(T[p] - K[q_2])])
    Ans.append(min(result_1, result_2)) i range(Q) range Q c = int(input()) c int(input()) int input() input p = bisect.bisect_right(K, c) p bisect.bisect_right(K, c) bisect.bisect_right bisect bisect_right K c if p >= l_1:
        p -= 1
     p >= l_1 p l_1 p -= 1 p 1 dis_1 = abs(c - K[p-1]) dis_1 abs(c - K[p-1]) abs c - K[p-1] c K[p-1] K p-1 p 1 dis_2 = abs(c - K[p]) dis_2 abs(c - K[p]) abs c - K[p] c K[p] K p q_1 = bisect.bisect_right(T, K[p-1]) q_1 bisect.bisect_right(T, K[p-1]) bisect.bisect_right bisect bisect_right T K[p-1] K p-1 p 1 q_2 = bisect.bisect_right(T, K[p]) q_2 bisect.bisect_right(T, K[p]) bisect.bisect_right bisect bisect_right T K[p] K p if q_1 >= l_2:
        q_1 -= 1
     q_1 >= l_2 q_1 l_2 q_1 -= 1 q_1 1 if q_2 >= l_2:
        q_2 -= 1
     q_2 >= l_2 q_2 l_2 q_2 -= 1 q_2 1 result_1 = min([dis_1 + abs(K[p-1] - T[q_1-1]), dis_1 + abs(K[p-1] - T[q_1]), dis_2 + abs(K[p] - T[q_2-1]), dis_2 + abs(K[p] - T[q_2])]) result_1 min([dis_1 + abs(K[p-1] - T[q_1-1]), dis_1 + abs(K[p-1] - T[q_1]), dis_2 + abs(K[p] - T[q_2-1]), dis_2 + abs(K[p] - T[q_2])]) min [dis_1 + abs(K[p-1] - T[q_1-1]), dis_1 + abs(K[p-1] - T[q_1]), dis_2 + abs(K[p] - T[q_2-1]), dis_2 + abs(K[p] - T[q_2])] dis_1 + abs(K[p-1] - T[q_1-1]) dis_1 abs(K[p-1] - T[q_1-1]) abs K[p-1] - T[q_1-1] K[p-1] K p-1 p 1 T[q_1-1] T q_1-1 q_1 1 dis_1 + abs(K[p-1] - T[q_1]) dis_1 abs(K[p-1] - T[q_1]) abs K[p-1] - T[q_1] K[p-1] K p-1 p 1 T[q_1] T q_1 dis_2 + abs(K[p] - T[q_2-1]) dis_2 abs(K[p] - T[q_2-1]) abs K[p] - T[q_2-1] K[p] K p T[q_2-1] T q_2-1 q_2 1 dis_2 + abs(K[p] - T[q_2]) dis_2 abs(K[p] - T[q_2]) abs K[p] - T[q_2] K[p] K p T[q_2] T q_2 p = bisect.bisect_right(T, c) p bisect.bisect_right(T, c) bisect.bisect_right bisect bisect_right T c if p >= l_2:
        p -= 1
     p >= l_2 p l_2 p -= 1 p 1 dis_1 = abs(c - T[p-1]) dis_1 abs(c - T[p-1]) abs c - T[p-1] c T[p-1] T p-1 p 1 dis_2 = abs(c - T[p]) dis_2 abs(c - T[p]) abs c - T[p] c T[p] T p q_1 = bisect.bisect_right(K, T[p-1]) q_1 bisect.bisect_right(K, T[p-1]) bisect.bisect_right bisect bisect_right K T[p-1] T p-1 p 1 q_2 = bisect.bisect_right(K, T[p]) q_2 bisect.bisect_right(K, T[p]) bisect.bisect_right bisect bisect_right K T[p] T p if q_1 >= l_1:
        q_1 -= 1
     q_1 >= l_1 q_1 l_1 q_1 -= 1 q_1 1 if q_2 >= l_1:
        q_2 -= 1
     q_2 >= l_1 q_2 l_1 q_2 -= 1 q_2 1 result_2 = min([dis_1 + abs(T[p-1] - K[q_1-1]), dis_1 + abs(T[p-1] - K[q_1]), dis_2 + abs(T[p] - K[q_2-1]), dis_2 + abs(T[p] - K[q_2])]) result_2 min([dis_1 + abs(T[p-1] - K[q_1-1]), dis_1 + abs(T[p-1] - K[q_1]), dis_2 + abs(T[p] - K[q_2-1]), dis_2 + abs(T[p] - K[q_2])]) min [dis_1 + abs(T[p-1] - K[q_1-1]), dis_1 + abs(T[p-1] - K[q_1]), dis_2 + abs(T[p] - K[q_2-1]), dis_2 + abs(T[p] - K[q_2])] dis_1 + abs(T[p-1] - K[q_1-1]) dis_1 abs(T[p-1] - K[q_1-1]) abs T[p-1] - K[q_1-1] T[p-1] T p-1 p 1 K[q_1-1] K q_1-1 q_1 1 dis_1 + abs(T[p-1] - K[q_1]) dis_1 abs(T[p-1] - K[q_1]) abs T[p-1] - K[q_1] T[p-1] T p-1 p 1 K[q_1] K q_1 dis_2 + abs(T[p] - K[q_2-1]) dis_2 abs(T[p] - K[q_2-1]) abs T[p] - K[q_2-1] T[p] T p K[q_2-1] K q_2-1 q_2 1 dis_2 + abs(T[p] - K[q_2]) dis_2 abs(T[p] - K[q_2]) abs T[p] - K[q_2] T[p] T p K[q_2] K q_2 Ans.append(min(result_1, result_2)) Ans.append Ans append min(result_1, result_2) min result_1 result_2 for i in Ans:
    print(i) i Ans print(i) print i p = bisect.bisect_right(T, c) bisect.bisect_right(T, c) p c = int(input()) int(input()) c A, B, Q = map(int, input().split()) map(int, input().split()) A Q = map(int, input().split()) map(int, input().split()) Q p -= 1 1 p result_1 = min([dis_1 + abs(K[p-1] - T[q_1-1]), dis_1 + abs(K[p-1] - T[q_1]), dis_2 + abs(K[p] - T[q_2-1]), dis_2 + abs(K[p] - T[q_2])]) min([dis_1 + abs(K[p-1] - T[q_1-1]), dis_1 + abs(K[p-1] - T[q_1]), dis_2 + abs(K[p] - T[q_2-1]), dis_2 + abs(K[p] - T[q_2])]) result_1 dis_1 = abs(c - T[p-1]) abs(c - T[p-1]) dis_1 dis_2 = abs(c - T[p]) abs(c - T[p]) dis_2 l_1 = len(K) len(K) l_1 dis_1 = abs(c - K[p-1]) abs(c - K[p-1]) dis_1 T = [] [] T q_1 = bisect.bisect_right(K, T[p-1]) bisect.bisect_right(K, T[p-1]) q_1 q_1 -= 1 1 q_1 p -= 1 1 p q_1 -= 1 1 q_1 p = bisect.bisect_right(K, c) bisect.bisect_right(K, c) p K = [] [] K q_2 = bisect.bisect_right(T, K[p]) bisect.bisect_right(T, K[p]) q_2 q_2 = bisect.bisect_right(K, T[p]) bisect.bisect_right(K, T[p]) q_2 B, Q = map(int, input().split()) map(int, input().split()) B result_2 = min([dis_1 + abs(T[p-1] - K[q_1-1]), dis_1 + abs(T[p-1] - K[q_1]), dis_2 + abs(T[p] - K[q_2-1]), dis_2 + abs(T[p] - K[q_2])]) min([dis_1 + abs(T[p-1] - K[q_1-1]), dis_1 + abs(T[p-1] - K[q_1]), dis_2 + abs(T[p] - K[q_2-1]), dis_2 + abs(T[p] - K[q_2])]) result_2 Ans = [] [] Ans q_2 -= 1 1 q_2 dis_2 = abs(c - K[p]) abs(c - K[p]) dis_2 l_2 = len(T) len(T) l_2 q_1 = bisect.bisect_right(T, K[p-1]) bisect.bisect_right(T, K[p-1]) q_1 q_2 -= 1 1 q_2
import bisect

A, B, Q = map(int, input().split())
K = []
T = []
for i in range(A):
    K.append(int(input()))
for j in range(B):
    T.append(int(input()))
K.sort()
T.sort()
l_1 = len(K)
l_2 = len(T)

Ans = []
for i in range(Q):
    c = int(input())
    p = bisect.bisect_right(K, c)
    if p >= l_1:
        p -= 1
    dis_1 = abs(c - K[p-1])
    dis_2 = abs(c - K[p])
    q_1 = bisect.bisect_right(T, K[p-1])
    q_2 = bisect.bisect_right(T, K[p])
    if q_1 >= l_2:
        q_1 -= 1
    if q_2 >= l_2:
        q_2 -= 1
    result_1 = min([dis_1 + abs(K[p-1] - T[q_1-1]), dis_1 + abs(K[p-1] - T[q_1]), dis_2 + abs(K[p] - T[q_2-1]), dis_2 + abs(K[p] - T[q_2])])

    p = bisect.bisect_right(T, c)
    if p >= l_2:
        p -= 1
    dis_1 = abs(c - T[p-1])
    dis_2 = abs(c - T[p])
    q_1 = bisect.bisect_right(K, T[p-1])
    q_2 = bisect.bisect_right(K, T[p])
    if q_1 >= l_1:
        q_1 -= 1
    if q_2 >= l_1:
        q_2 -= 1
    result_2 = min([dis_1 + abs(T[p-1] - K[q_1-1]), dis_1 + abs(T[p-1] - K[q_1]), dis_2 + abs(T[p] - K[q_2-1]), dis_2 + abs(T[p] - K[q_2])])
    Ans.append(min(result_1, result_2))

for i in Ans:
    print(i)