#!/usr/bin/env python3

from bisect import bisect_right



def main():

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

    s = [int(eval(input())) for _ in range(A)]

    t = [int(eval(input())) for _ in range(B)]

    # print(s,t)

    s = [-10**12] + s + [10**12]

    t = [-10**12] + t + [10**12]



    for _ in range(Q):

        x = int(eval(input()))

        i = bisect_right(s,x)

        j = bisect_right(t,x)

        # print(i,j,x)

        ans = []



        ans.append(max(abs(s[i-1] - x), abs(t[j-1] - x)))

        ans.append(max(abs(s[i] - x), abs(t[j] - x)))

        ans.append(abs(s[i-1] - x) + abs(t[j] - x) + min(abs(s[i-1]-x), abs(t[j]-x)))

        ans.append(abs(s[i] - x) + abs(t[j-1] - x) + min(abs(s[i]-x), abs(t[j-1]-x)))



        print((min(ans)))



if __name__ == "__main__":

    main()

from bisect import bisect_left



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

INF = 10**12

s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]

t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]



for _ in range(Q):

    x = int(eval(input()))

    si = bisect_left(s,x)

    ti = bisect_left(t,x)

    sl = [s[si-1],s[si]]

    tl = [t[ti-1],t[ti]]

    ans = INF

    for i in range(2):

        for j in range(2):

            ans = min(ans, abs(x-sl[i])+abs(sl[i]-tl[j]), abs(x-tl[j])+abs(tl[j]-sl[i]))

    print(ans)
#!/usr/bin/env python3
from bisect import bisect_right


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


if __name__ == "__main__":
    main()

from bisect import bisect_left

A, B, Q = list(map(int, input().split()))
INF = 10**12
s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
for _ in range(Q):
    x = int(eval(input()))
    si = bisect_left(s, x)
    ti = bisect_left(t, x)
    sl = [s[si - 1], s[si]]
    tl = [t[ti - 1], t[ti]]
    ans = INF
    for i in range(2):
        for j in range(2):
            ans = min(
                ans,
                abs(x - sl[i]) + abs(sl[i] - tl[j]),
                abs(x - tl[j]) + abs(tl[j] - sl[i]),
            )
    print(ans)

-#!/usr/bin/env python3 -from bisect import bisect_right +from bisect import bisect_left - -def main(): -    A, B, Q = list(map(int, input().split())) -    s = [int(eval(input())) for _ in range(A)] -    t = [int(eval(input())) for _ in range(B)] -    # print(s,t) -    s = [-(10**12)] + s + [10**12] -    t = [-(10**12)] + t + [10**12] -    for _ in range(Q): -        x = int(eval(input())) -        i = bisect_right(s, x) -        j = bisect_right(t, x) -        # print(i,j,x) -        ans = [] -        ans.append(max(abs(s[i - 1] - x), abs(t[j - 1] - x))) -        ans.append(max(abs(s[i] - x), abs(t[j] - x))) -        ans.append( -            abs(s[i - 1] - x) + abs(t[j] - x) + min(abs(s[i - 1] - x), abs(t[j] - x)) -        ) -        ans.append( -            abs(s[i] - x) + abs(t[j - 1] - x) + min(abs(s[i] - x), abs(t[j - 1] - x)) -        ) -        print((min(ans))) - - -if __name__ == "__main__": -    main() +A, B, Q = list(map(int, input().split())) +INF = 10**12 +s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF] +t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF] +for _ in range(Q): +    x = int(eval(input())) +    si = bisect_left(s, x) +    ti = bisect_left(t, x) +    sl = [s[si - 1], s[si]] +    tl = [t[ti - 1], t[ti]] +    ans = INF +    for i in range(2): +        for j in range(2): +            ans = min( +                ans, +                abs(x - sl[i]) + abs(sl[i] - tl[j]), +                abs(x - tl[j]) + abs(tl[j] - sl[i]), +            ) +    print(ans)