import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    A, B, Q = map(int, input().split())
    S = [-10**50]
    T = [-10**50]
    for _ in range(A): S.append(int(input()))
    for _ in range(B): T.append(int(input()))
    S.append(10**50)
    T.append(10**50)

    for _ in range(Q):
        x = int(input())
        idx1 = bisect_left(S, x)
        idx2 = bisect_left(T, x)
        ans = 10 ** 11
        cand1 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1])
        ans = min(ans, cand1)
        cand2 = (x - S[idx1 - 1]) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand2)
        cand3 = (S[idx1] - x) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand3)
        cand4 = (S[idx1] - x) + abs(S[idx1] - T[idx2])
        ans = min(ans, cand4)
        cand5 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1])
        ans = min(ans, cand5)
        cand6 = (x - T[idx2 - 1]) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand6)
        cand7 = (T[idx2] - x) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand7)
        cand8 = (T[idx2] - x) + abs(T[idx2] - S[idx1])
        ans = min(ans, cand8)
        print(ans)



if __name__ == "__main__":
    main() import sys sys from bisect import bisect_left def input(): return sys.stdin.readline().strip() input def main():
    A, B, Q = map(int, input().split())
    S = [-10**50]
    T = [-10**50]
    for _ in range(A): S.append(int(input()))
    for _ in range(B): T.append(int(input()))
    S.append(10**50)
    T.append(10**50)

    for _ in range(Q):
        x = int(input())
        idx1 = bisect_left(S, x)
        idx2 = bisect_left(T, x)
        ans = 10 ** 11
        cand1 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1])
        ans = min(ans, cand1)
        cand2 = (x - S[idx1 - 1]) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand2)
        cand3 = (S[idx1] - x) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand3)
        cand4 = (S[idx1] - x) + abs(S[idx1] - T[idx2])
        ans = min(ans, cand4)
        cand5 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1])
        ans = min(ans, cand5)
        cand6 = (x - T[idx2 - 1]) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand6)
        cand7 = (T[idx2] - x) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand7)
        cand8 = (T[idx2] - x) + abs(T[idx2] - S[idx1])
        ans = min(ans, cand8)
        print(ans) main A, B, Q = map(int, input().split()) A map(int, input().split()) map int input().split() ().split () input split B Q S = [-10**50] S [-10**50] -10**50 -10 50 T = [-10**50] T [-10**50] -10**50 -10 50 for _ in range(A): S.append(int(input()))
     _ range(A) range A for _ in range(B): T.append(int(input()))
     _ range(B) range B S.append(10**50) S.append S append 10**50 10 50 T.append(10**50) T.append T append 10**50 10 50 for _ in range(Q):
        x = int(input())
        idx1 = bisect_left(S, x)
        idx2 = bisect_left(T, x)
        ans = 10 ** 11
        cand1 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1])
        ans = min(ans, cand1)
        cand2 = (x - S[idx1 - 1]) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand2)
        cand3 = (S[idx1] - x) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand3)
        cand4 = (S[idx1] - x) + abs(S[idx1] - T[idx2])
        ans = min(ans, cand4)
        cand5 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1])
        ans = min(ans, cand5)
        cand6 = (x - T[idx2 - 1]) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand6)
        cand7 = (T[idx2] - x) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand7)
        cand8 = (T[idx2] - x) + abs(T[idx2] - S[idx1])
        ans = min(ans, cand8)
        print(ans) _ range(Q) range Q x = int(input()) x int(input()) int input() input idx1 = bisect_left(S, x) idx1 bisect_left(S, x) bisect_left S x idx2 = bisect_left(T, x) idx2 bisect_left(T, x) bisect_left T x ans = 10 ** 11 ans 10 ** 11 10 11 cand1 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1]) cand1 (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1]) x - S[idx1 - 1] x S[idx1 - 1] S idx1 - 1 idx1 1 abs(S[idx1 - 1] - T[idx2 - 1]) abs S[idx1 - 1] - T[idx2 - 1] S[idx1 - 1] S idx1 - 1 idx1 1 T[idx2 - 1] T idx2 - 1 idx2 1 ans = min(ans, cand1) ans min(ans, cand1) min ans cand1 cand2 = (x - S[idx1 - 1]) + (T[idx2] - S[idx1 - 1]) cand2 (x - S[idx1 - 1]) + (T[idx2] - S[idx1 - 1]) x - S[idx1 - 1] x S[idx1 - 1] S idx1 - 1 idx1 1 T[idx2] - S[idx1 - 1] T[idx2] T idx2 S[idx1 - 1] S idx1 - 1 idx1 1 ans = min(ans, cand2) ans min(ans, cand2) min ans cand2 cand3 = (S[idx1] - x) + (S[idx1] - T[idx2 - 1]) cand3 (S[idx1] - x) + (S[idx1] - T[idx2 - 1]) S[idx1] - x S[idx1] S idx1 x S[idx1] - T[idx2 - 1] S[idx1] S idx1 T[idx2 - 1] T idx2 - 1 idx2 1 ans = min(ans, cand3) ans min(ans, cand3) min ans cand3 cand4 = (S[idx1] - x) + abs(S[idx1] - T[idx2]) cand4 (S[idx1] - x) + abs(S[idx1] - T[idx2]) S[idx1] - x S[idx1] S idx1 x abs(S[idx1] - T[idx2]) abs S[idx1] - T[idx2] S[idx1] S idx1 T[idx2] T idx2 ans = min(ans, cand4) ans min(ans, cand4) min ans cand4 cand5 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1]) cand5 (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1]) x - T[idx2 - 1] x T[idx2 - 1] T idx2 - 1 idx2 1 abs(T[idx2 - 1] - S[idx1 - 1]) abs T[idx2 - 1] - S[idx1 - 1] T[idx2 - 1] T idx2 - 1 idx2 1 S[idx1 - 1] S idx1 - 1 idx1 1 ans = min(ans, cand5) ans min(ans, cand5) min ans cand5 cand6 = (x - T[idx2 - 1]) + (S[idx1] - T[idx2 - 1]) cand6 (x - T[idx2 - 1]) + (S[idx1] - T[idx2 - 1]) x - T[idx2 - 1] x T[idx2 - 1] T idx2 - 1 idx2 1 S[idx1] - T[idx2 - 1] S[idx1] S idx1 T[idx2 - 1] T idx2 - 1 idx2 1 ans = min(ans, cand6) ans min(ans, cand6) min ans cand6 cand7 = (T[idx2] - x) + (T[idx2] - S[idx1 - 1]) cand7 (T[idx2] - x) + (T[idx2] - S[idx1 - 1]) T[idx2] - x T[idx2] T idx2 x T[idx2] - S[idx1 - 1] T[idx2] T idx2 S[idx1 - 1] S idx1 - 1 idx1 1 ans = min(ans, cand7) ans min(ans, cand7) min ans cand7 cand8 = (T[idx2] - x) + abs(T[idx2] - S[idx1]) cand8 (T[idx2] - x) + abs(T[idx2] - S[idx1]) T[idx2] - x T[idx2] T idx2 x abs(T[idx2] - S[idx1]) abs T[idx2] - S[idx1] T[idx2] T idx2 S[idx1] S idx1 ans = min(ans, cand8) ans min(ans, cand8) min ans cand8 print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input def main():
    A, B, Q = map(int, input().split())
    S = [-10**50]
    T = [-10**50]
    for _ in range(A): S.append(int(input()))
    for _ in range(B): T.append(int(input()))
    S.append(10**50)
    T.append(10**50)

    for _ in range(Q):
        x = int(input())
        idx1 = bisect_left(S, x)
        idx2 = bisect_left(T, x)
        ans = 10 ** 11
        cand1 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1])
        ans = min(ans, cand1)
        cand2 = (x - S[idx1 - 1]) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand2)
        cand3 = (S[idx1] - x) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand3)
        cand4 = (S[idx1] - x) + abs(S[idx1] - T[idx2])
        ans = min(ans, cand4)
        cand5 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1])
        ans = min(ans, cand5)
        cand6 = (x - T[idx2 - 1]) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand6)
        cand7 = (T[idx2] - x) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand7)
        cand8 = (T[idx2] - x) + abs(T[idx2] - S[idx1])
        ans = min(ans, cand8)
        print(ans) def main():
    A, B, Q = map(int, input().split())
    S = [-10**50]
    T = [-10**50]
    for _ in range(A): S.append(int(input()))
    for _ in range(B): T.append(int(input()))
    S.append(10**50)
    T.append(10**50)

    for _ in range(Q):
        x = int(input())
        idx1 = bisect_left(S, x)
        idx2 = bisect_left(T, x)
        ans = 10 ** 11
        cand1 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1])
        ans = min(ans, cand1)
        cand2 = (x - S[idx1 - 1]) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand2)
        cand3 = (S[idx1] - x) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand3)
        cand4 = (S[idx1] - x) + abs(S[idx1] - T[idx2])
        ans = min(ans, cand4)
        cand5 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1])
        ans = min(ans, cand5)
        cand6 = (x - T[idx2 - 1]) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand6)
        cand7 = (T[idx2] - x) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand7)
        cand8 = (T[idx2] - x) + abs(T[idx2] - S[idx1])
        ans = min(ans, cand8)
        print(ans) main
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    A, B, Q = map(int, input().split())
    S = [-10**50]
    T = [-10**50]
    for _ in range(A): S.append(int(input()))
    for _ in range(B): T.append(int(input()))
    S.append(10**50)
    T.append(10**50)

    for _ in range(Q):
        x = int(input())
        idx1 = bisect_left(S, x)
        idx2 = bisect_left(T, x)
        ans = 10 ** 11
        cand1 = (x - S[idx1 - 1]) + abs(S[idx1 - 1] - T[idx2 - 1])
        ans = min(ans, cand1)
        cand2 = (x - S[idx1 - 1]) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand2)
        cand3 = (S[idx1] - x) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand3)
        cand4 = (S[idx1] - x) + abs(S[idx1] - T[idx2])
        ans = min(ans, cand4)
        cand5 = (x - T[idx2 - 1]) + abs(T[idx2 - 1] - S[idx1 - 1])
        ans = min(ans, cand5)
        cand6 = (x - T[idx2 - 1]) + (S[idx1] - T[idx2 - 1])
        ans = min(ans, cand6)
        cand7 = (T[idx2] - x) + (T[idx2] - S[idx1 - 1])
        ans = min(ans, cand7)
        cand8 = (T[idx2] - x) + abs(T[idx2] - S[idx1])
        ans = min(ans, cand8)
        print(ans)



if __name__ == "__main__":
    main()
