from bisect import bisect_left, bisect_right



def func(x, y, z):

    yi = bisect_right(y, x)



    if yi == 0 or yi == len(y):

        ans = 0

        if yi == len(y):

            yi -= 1

        ans += abs(y[yi] - x)

        x = y[yi]



        zi = bisect_right(z, x)

        ans += min(abs(z[zi % len(z)] - x), abs(z[(zi-1) % len(z)] - x))

        return ans

    else:

        ans1 = ans2 = 0

        ans1 += abs(y[yi-1] - x)

        x1 = y[yi-1]

        zi = bisect_right(z, x1)

        ans1 += min(abs(z[zi % len(z)] - x1), abs(z[(zi-1) % len(z)] - x1))



        ans2 += abs(y[yi] - x)

        x2 = y[yi]

        zi = bisect_right(z, x2)

        ans2 += min(abs(z[zi % len(z)] - x2), abs(z[(zi-1) % len(z)] - x2))

        return min(ans1, ans2)





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

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

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



for _ in range(q):

    x = int(eval(input()))



    print((min(func(x, s, t), func(x, t, s))))

from bisect import bisect_right



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

INF = 10**11

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_right(s, x)

    ti = bisect_right(t, x)



    ans = INF * 10

    for ss in [s[si-1], s[si]]:

        for tt in [t[ti-1], t[ti]]:

            ans = min(ans,

                      abs(x - ss) + abs(ss - tt),

                      abs(x - tt) + abs(tt - ss))

    print(ans)

from bisect import bisect_left, bisect_right


def func(x, y, z):
    yi = bisect_right(y, x)
    if yi == 0 or yi == len(y):
        ans = 0
        if yi == len(y):
            yi -= 1
        ans += abs(y[yi] - x)
        x = y[yi]
        zi = bisect_right(z, x)
        ans += min(abs(z[zi % len(z)] - x), abs(z[(zi - 1) % len(z)] - x))
        return ans
    else:
        ans1 = ans2 = 0
        ans1 += abs(y[yi - 1] - x)
        x1 = y[yi - 1]
        zi = bisect_right(z, x1)
        ans1 += min(abs(z[zi % len(z)] - x1), abs(z[(zi - 1) % len(z)] - x1))
        ans2 += abs(y[yi] - x)
        x2 = y[yi]
        zi = bisect_right(z, x2)
        ans2 += min(abs(z[zi % len(z)] - x2), abs(z[(zi - 1) % len(z)] - x2))
        return min(ans1, ans2)


a, b, q = list(map(int, input().split()))
s = [int(eval(input())) for _ in range(a)]
t = [int(eval(input())) for _ in range(b)]
for _ in range(q):
    x = int(eval(input()))
    print((min(func(x, s, t), func(x, t, s))))

from bisect import bisect_right

a, b, q = list(map(int, input().split()))
INF = 10**11
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_right(s, x)
    ti = bisect_right(t, x)
    ans = INF * 10
    for ss in [s[si - 1], s[si]]:
        for tt in [t[ti - 1], t[ti]]:
            ans = min(ans, abs(x - ss) + abs(ss - tt), abs(x - tt) + abs(tt - ss))
    print(ans)

-from bisect import bisect_left, bisect_right - - -def func(x, y, z): -    yi = bisect_right(y, x) -    if yi == 0 or yi == len(y): -        ans = 0 -        if yi == len(y): -            yi -= 1 -        ans += abs(y[yi] - x) -        x = y[yi] -        zi = bisect_right(z, x) -        ans += min(abs(z[zi % len(z)] - x), abs(z[(zi - 1) % len(z)] - x)) -        return ans -    else: -        ans1 = ans2 = 0 -        ans1 += abs(y[yi - 1] - x) -        x1 = y[yi - 1] -        zi = bisect_right(z, x1) -        ans1 += min(abs(z[zi % len(z)] - x1), abs(z[(zi - 1) % len(z)] - x1)) -        ans2 += abs(y[yi] - x) -        x2 = y[yi] -        zi = bisect_right(z, x2) -        ans2 += min(abs(z[zi % len(z)] - x2), abs(z[(zi - 1) % len(z)] - x2)) -        return min(ans1, ans2) - +from bisect import bisect_right -s = [int(eval(input())) for _ in range(a)] -t = [int(eval(input())) for _ in range(b)] +INF = 10**11 +s = [-INF] + [int(eval(input())) for _ in range(a)] + [INF] +t = [-INF] + [int(eval(input())) for _ in range(b)] + [INF] -    print((min(func(x, s, t), func(x, t, s)))) +    si = bisect_right(s, x) +    ti = bisect_right(t, x) +    ans = INF * 10 +    for ss in [s[si - 1], s[si]]: +        for tt in [t[ti - 1], t[ti]]: +            ans = min(ans, abs(x - ss) + abs(ss - tt), abs(x - tt) + abs(tt - ss)) +    print(ans)