Buggy python submission (verdict: Time Limit Exceeded):
import bisect
A, B, Q = map(int, input().split())
INF = float("inf")
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]

for q in range(Q):
    x = int(input())
    ans = INF
    a_i = bisect.bisect_right(s, x)
    b_i = bisect.bisect_right(t, x)
    for a in [s[a_i], s[a_i - 1]]:
        for b in [t[b_i], t[b_i - 1]]:
            ans = min(ans, abs(x - a) + abs(b - a), abs(x - b) + abs(b - a))
    print(ans)

Fixed submission:
import bisect

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

for x in X:
    ans = float('inf')
    if x < S[0]:
        right_S = S[0]
        left_S = None
    elif x > S[-1]:
        right_S = None
        left_S = S[-1]

    else:
        index_right_S = bisect.bisect_right(S, x)
        if index_right_S < A and S[index_right_S] == x:
            left_S = x
            right_S = x
        else:
            if index_right_S - 1 >= 0:
                left_S = S[index_right_S - 1]
            if index_right_S < A:
                right_S = S[index_right_S]

    if x < T[0]:
        right_T = T[0]
        left_T = None
    elif x > T[-1]:
        right_T = None
        left_T = T[-1]

    else:
        index_right_T = bisect.bisect_right(T, x)
        if index_right_T < B and T[index_right_T] == x:
            left_T = x
            right_T = x
        else:
            if index_right_T - 1 >= 0:
                left_T = T[index_right_T - 1]
            if index_right_T < B:
                right_T = T[index_right_T]

    if left_T and right_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - right_S),
                                   abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - left_S),
                                  abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

for x in X:
    ans = float('inf')
    if x < S[0]:
        right_S = S[0]
        left_S = None
    elif x > S[-1]:
        right_S = None
        left_S = S[-1]

    else:
        index_right_S = bisect.bisect_right(S, x)
        if index_right_S < A and S[index_right_S] == x:
            left_S = x
            right_S = x
        else:
            if index_right_S - 1 >= 0:
                left_S = S[index_right_S - 1]
            if index_right_S < A:
                right_S = S[index_right_S]

    if x < T[0]:
        right_T = T[0]
        left_T = None
    elif x > T[-1]:
        right_T = None
        left_T = T[-1]

    else:
        index_right_T = bisect.bisect_right(T, x)
        if index_right_T < B and T[index_right_T] == x:
            left_T = x
            right_T = x
        else:
            if index_right_T - 1 >= 0:
                left_T = T[index_right_T - 1]
            if index_right_T < B:
                right_T = T[index_right_T]

    if left_T and right_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - right_S),
                                   abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - left_S),
                                  abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(ans)

Fixed submission:
import bisect

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

for x in X:
    ans = float('inf')
    if x < S[0]:
        right_S = S[0]
        left_S = None
    elif x > S[-1]:
        right_S = None
        left_S = S[-1]

    else:
        index_right_S = bisect.bisect_right(S, x)
        if index_right_S < A and S[index_right_S] == x:
            left_S = x
            right_S = x
        else:
            if index_right_S - 1 >= 0:
                left_S = S[index_right_S - 1]
            if index_right_S < A:
                right_S = S[index_right_S]

    if x < T[0]:
        right_T = T[0]
        left_T = None
    elif x > T[-1]:
        right_T = None
        left_T = T[-1]

    else:
        index_right_T = bisect.bisect_right(T, x)
        if index_right_T < B and T[index_right_T] == x:
            left_T = x
            right_T = x
        else:
            if index_right_T - 1 >= 0:
                left_T = T[index_right_T - 1]
            if index_right_T < B:
                right_T = T[index_right_T]

    if left_T and right_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - right_S),
                                   abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - left_S),
                                  abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

for x in X:
    if x < S[0]:
        right_S = S[0]
        left_S = None
    elif x > S[-1]:
        right_S = None
        left_S = S[-1]

    else:
        index_right_S = bisect.bisect_right(S, x)
        if index_right_S < A and S[index_right_S] == x:
            left_S = x
            right_S = x
        else:
            if index_right_S - 1 >= 0:
                left_S = S[index_right_S - 1]
            if index_right_S < A:
                right_S = S[index_right_S]

    if x < T[0]:
        right_T = T[0]
        left_T = None
    elif x > T[-1]:
        right_T = None
        left_T = T[-1]

    else:
        index_right_T = bisect.bisect_right(T, x)
        if index_right_T < B and T[index_right_T] == x:
            left_T = x
            right_T = x
        else:
            if index_right_T - 1 >= 0:
                left_T = T[index_right_T - 1]
            if index_right_T < B:
                right_T = T[index_right_T]

    if left_T and right_S:
        score_left_T_right_S = min(abs(left_T - x) + abs(left_T - right_S),
                                   abs(right_S - x) + abs(left_T - right_S))
    else:
        score_left_T_right_S = float('inf')

    if left_T and left_S:
        score_left_T_left_S = min(abs(left_T - x) + abs(left_T - left_S),
                                  abs(left_S - x) + abs(left_T - left_S))
    else:
        score_left_T_left_S = float('inf')

    if right_T and left_S:
        score_right_T_left_S = min(abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))
    else:
        score_right_T_left_S = float('inf')

    if right_T and right_S:
        score_right_T_right_S = min(abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))
    else:
        score_right_T_right_S = float('inf')

    print(min(score_left_T_right_S, score_left_T_left_S, score_right_T_left_S, score_right_T_right_S))

Fixed submission:
import bisect

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

for x in X:
    ans = float('inf')
    if x < S[0]:
        right_S = S[0]
        left_S = None
    elif x > S[-1]:
        right_S = None
        left_S = S[-1]

    else:
        index_right_S = bisect.bisect_right(S, x)
        if index_right_S < A and S[index_right_S] == x:
            left_S = x
            right_S = x
        else:
            if index_right_S - 1 >= 0:
                left_S = S[index_right_S - 1]
            if index_right_S < A:
                right_S = S[index_right_S]

    if x < T[0]:
        right_T = T[0]
        left_T = None
    elif x > T[-1]:
        right_T = None
        left_T = T[-1]

    else:
        index_right_T = bisect.bisect_right(T, x)
        if index_right_T < B and T[index_right_T] == x:
            left_T = x
            right_T = x
        else:
            if index_right_T - 1 >= 0:
                left_T = T[index_right_T - 1]
            if index_right_T < B:
                right_T = T[index_right_T]

    if left_T and right_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - right_S),
                                   abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - left_S),
                                  abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

score_left_T_right_S = float('inf')
score_left_T_left_S = float('inf')
score_right_T_left_S = float('inf')
score_right_T_right_S = float('inf')
for x in X:
    if x < S[0]:
        right_S = S[0]
        left_S = None
    elif x > S[-1]:
        right_S = None
        left_S = S[-1]

    else:
        index_right_S = bisect.bisect_right(S, x)
        if index_right_S < A and S[index_right_S] == x:
            left_S = x
            right_S = x
        else:
            if index_right_S - 1 >= 0:
                left_S = S[index_right_S - 1]
            if index_right_S < A:
                right_S = S[index_right_S]

    if x < T[0]:
        right_T = T[0]
        left_T = None
    elif x > T[-1]:
        right_T = None
        left_T = T[-1]

    else:
        index_right_T = bisect.bisect_right(T, x)
        if index_right_T < B and T[index_right_T] == x:
            left_T = x
            right_T = x
        else:
            if index_right_T - 1 >= 0:
                left_T = T[index_right_T - 1]
            if index_right_T < B:
                right_T = T[index_right_T]

    if left_T and right_S:
        score_left_T_right_S = min(abs(left_T - x) + abs(left_T - right_S),
                                   abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        score_left_T_left_S = min(abs(left_T - x) + abs(left_T - left_S),
                                  abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        score_right_T_left_S = min(abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        score_right_T_right_S = min(abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(min(score_left_T_right_S, score_left_T_left_S, score_right_T_left_S, score_right_T_right_S))

    score_left_T_right_S = float('inf')
    score_left_T_left_S = float('inf')
    score_right_T_left_S = float('inf')
    score_right_T_right_S = float('inf')

Fixed submission:
import bisect

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

for x in X:
    ans = float('inf')
    if x < S[0]:
        right_S = S[0]
        left_S = None
    elif x > S[-1]:
        right_S = None
        left_S = S[-1]

    else:
        index_right_S = bisect.bisect_right(S, x)
        if index_right_S < A and S[index_right_S] == x:
            left_S = x
            right_S = x
        else:
            if index_right_S - 1 >= 0:
                left_S = S[index_right_S - 1]
            if index_right_S < A:
                right_S = S[index_right_S]

    if x < T[0]:
        right_T = T[0]
        left_T = None
    elif x > T[-1]:
        right_T = None
        left_T = T[-1]

    else:
        index_right_T = bisect.bisect_right(T, x)
        if index_right_T < B and T[index_right_T] == x:
            left_T = x
            right_T = x
        else:
            if index_right_T - 1 >= 0:
                left_T = T[index_right_T - 1]
            if index_right_T < B:
                right_T = T[index_right_T]

    if left_T and right_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - right_S),
                                   abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - left_S),
                                  abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

score_left_T_right_S = float('inf')
score_left_T_left_S = float('inf')
score_right_T_left_S = float('inf')
score_right_T_right_S = float('inf')
for x in X:
    index_left_S = bisect.bisect_left(S, x)
    index_right_S = bisect.bisect_right(S, x)
    if index_left_S < A and S[index_left_S] == x:
        left_S = x
        right_S = x
    else:
        if index_right_S - 1 >= 0:
            left_S = S[index_right_S - 1]
        elif index_right_S - 1 < 0:
            left_S = None
        if index_right_S < A:
            right_S = S[index_right_S]
        elif index_right_S >= A:
            right_S = None

    index_left_T = bisect.bisect_left(T, x)
    index_right_T = bisect.bisect_right(T, x)
    if index_right_T < B and T[index_right_T] == x:
        left_T = x
        right_T = x
    else:
        if index_right_T - 1 >= 0:
            left_T = T[index_right_T - 1]
        elif index_right_T - 1 < 0:
            left_T = None
        if index_right_T < B:
            right_T = T[index_right_T]
        elif index_right_T >= B:
            right_T = None

    if left_T and right_S:
        score_left_T_right_S = min(abs(left_T - x) + abs(left_T - right_S), abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        score_left_T_left_S = min(abs(left_T - x) + abs(left_T - left_S), abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        score_right_T_left_S = min(abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        score_right_T_right_S = min(abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(min(score_left_T_right_S, score_left_T_left_S, score_right_T_left_S, score_right_T_right_S))

    score_left_T_right_S = float('inf')
    score_left_T_left_S = float('inf')
    score_right_T_left_S = float('inf')
    score_right_T_right_S = float('inf')

Fixed submission:
import bisect

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

for x in X:
    ans = float('inf')
    if x < S[0]:
        right_S = S[0]
        left_S = None
    elif x > S[-1]:
        right_S = None
        left_S = S[-1]

    else:
        index_right_S = bisect.bisect_right(S, x)
        if index_right_S < A and S[index_right_S] == x:
            left_S = x
            right_S = x
        else:
            if index_right_S - 1 >= 0:
                left_S = S[index_right_S - 1]
            if index_right_S < A:
                right_S = S[index_right_S]

    if x < T[0]:
        right_T = T[0]
        left_T = None
    elif x > T[-1]:
        right_T = None
        left_T = T[-1]

    else:
        index_right_T = bisect.bisect_right(T, x)
        if index_right_T < B and T[index_right_T] == x:
            left_T = x
            right_T = x
        else:
            if index_right_T - 1 >= 0:
                left_T = T[index_right_T - 1]
            if index_right_T < B:
                right_T = T[index_right_T]

    if left_T and right_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - right_S),
                                   abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - left_S),
                                  abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

score_left_T_right_S = float('inf')
score_left_T_left_S = float('inf')
score_right_T_left_S = float('inf')
score_right_T_right_S = float('inf')
for x in X:
    if bisect.bisect_left(S, x) < A and S[bisect.bisect_left(S, x)] == x:
        left_S = x
        right_S = x
    else:
        if bisect.bisect_right(S, x) - 1 >= 0:
            left_S = S[bisect.bisect_right(S, x) - 1]
        elif bisect.bisect_right(S, x) - 1 < 0:
            left_S = None
        if bisect.bisect_right(S, x) < A:
            right_S = S[bisect.bisect_right(S, x)]
        elif bisect.bisect_right(S, x) >= A:
            right_S = None

    if bisect.bisect_right(T, x) < B and T[bisect.bisect_right(T, x)] == x:
        left_T = x
        right_T = x
    else:
        if bisect.bisect_right(T, x) - 1 >= 0:
            left_T = T[bisect.bisect_right(T, x) - 1]
        elif bisect.bisect_right(T, x) - 1 < 0:
            left_T = None
        if bisect.bisect_right(T, x) < B:
            right_T = T[bisect.bisect_right(T, x)]
        elif bisect.bisect_right(T, x) >= B:
            right_T = None

    if left_T and right_S:
        score_left_T_right_S = min(abs(left_T - x) + abs(left_T - right_S), abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        score_left_T_left_S = min(abs(left_T - x) + abs(left_T - left_S), abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        score_right_T_left_S = min(abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        score_right_T_right_S = min(abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(min(score_left_T_right_S, score_left_T_left_S, score_right_T_left_S, score_right_T_right_S))

    score_left_T_right_S = float('inf')
    score_left_T_left_S = float('inf')
    score_right_T_left_S = float('inf')
    score_right_T_right_S = float('inf')

Fixed submission:
import bisect

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

for x in X:
    ans = float('inf')
    if x < S[0]:
        right_S = S[0]
        left_S = None
    elif x > S[-1]:
        right_S = None
        left_S = S[-1]

    else:
        index_right_S = bisect.bisect_right(S, x)
        if index_right_S < A and S[index_right_S] == x:
            left_S = x
            right_S = x
        else:
            if index_right_S - 1 >= 0:
                left_S = S[index_right_S - 1]
            if index_right_S < A:
                right_S = S[index_right_S]

    if x < T[0]:
        right_T = T[0]
        left_T = None
    elif x > T[-1]:
        right_T = None
        left_T = T[-1]

    else:
        index_right_T = bisect.bisect_right(T, x)
        if index_right_T < B and T[index_right_T] == x:
            left_T = x
            right_T = x
        else:
            if index_right_T - 1 >= 0:
                left_T = T[index_right_T - 1]
            if index_right_T < B:
                right_T = T[index_right_T]

    if left_T and right_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - right_S),
                                   abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - left_S),
                                  abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

score_left_T_right_S = 10**100
score_left_T_left_S = 10**100
score_right_T_left_S = 10**100
score_right_T_right_S = 10**100
for x in X:
    if bisect.bisect_left(S, x) < A and S[bisect.bisect_left(S, x)] == x:
        left_S = x
        right_S = x
    else:
        if bisect.bisect_right(S, x) - 1 >= 0:
            left_S = S[bisect.bisect_right(S, x) - 1]
        elif bisect.bisect_right(S, x) - 1 < 0:
            left_S = None
        if bisect.bisect_right(S, x) < A:
            right_S = S[bisect.bisect_right(S, x)]
        elif bisect.bisect_right(S, x) >= A:
            right_S = None

    if bisect.bisect_right(T, x) < B and T[bisect.bisect_right(T, x)] == x:
        left_T = x
        right_T = x
    else:
        if bisect.bisect_right(T, x) - 1 >= 0:
            left_T = T[bisect.bisect_right(T, x) - 1]
        elif bisect.bisect_right(T, x) - 1 < 0:
            left_T = None
        if bisect.bisect_right(T, x) < B:
            right_T = T[bisect.bisect_right(T, x)]
        elif bisect.bisect_right(T, x) >= B:
            right_T = None

    if left_T and right_S:
        score_left_T_right_S = min(abs(left_T - x) + abs(left_T - right_S), abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        score_left_T_left_S = min(abs(left_T - x) + abs(left_T - left_S), abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        score_right_T_left_S = min(abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        score_right_T_right_S = min(abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(min(score_left_T_right_S, score_left_T_left_S, score_right_T_left_S, score_right_T_right_S))

    score_left_T_right_S = 10 ** 100
    score_left_T_left_S = 10 ** 100
    score_right_T_left_S = 10 ** 100
    score_right_T_right_S = 10 ** 100

Fixed submission:
import bisect

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

for x in X:
    ans = float('inf')
    if x < S[0]:
        right_S = S[0]
        left_S = None
    elif x > S[-1]:
        right_S = None
        left_S = S[-1]

    else:
        index_right_S = bisect.bisect_right(S, x)
        if index_right_S < A and S[index_right_S] == x:
            left_S = x
            right_S = x
        else:
            if index_right_S - 1 >= 0:
                left_S = S[index_right_S - 1]
            if index_right_S < A:
                right_S = S[index_right_S]

    if x < T[0]:
        right_T = T[0]
        left_T = None
    elif x > T[-1]:
        right_T = None
        left_T = T[-1]

    else:
        index_right_T = bisect.bisect_right(T, x)
        if index_right_T < B and T[index_right_T] == x:
            left_T = x
            right_T = x
        else:
            if index_right_T - 1 >= 0:
                left_T = T[index_right_T - 1]
            if index_right_T < B:
                right_T = T[index_right_T]

    if left_T and right_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - right_S),
                                   abs(right_S - x) + abs(left_T - right_S))

    if left_T and left_S:
        ans = min(ans, abs(left_T - x) + abs(left_T - left_S),
                                  abs(left_S - x) + abs(left_T - left_S))

    if right_T and left_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - left_S),
                                   abs(left_S - x) + abs(right_T - left_S))

    if right_T and right_S:
        ans = min(ans, abs(right_T - x) + abs(right_T - right_S),
                                  abs(right_S - x) + abs(right_T - right_S))

    print(ans)