import bisect



s_len, t_len, q = list(map(int, input().split()))



shrines = []

temples = []

for _ in range(s_len):

    shrines.append(int(eval(input())))

for _ in range(t_len):

    temples.append(int(eval(input())))





def distance(s_i, t_i, x):

    """

    s_i と t_i を最短でまわる距離。無効なインデックスなら inf を返す

    """

    if 0 <= s_i < s_len and 0 <= t_i < t_len:

        s = shrines[s_i]

        t = temples[t_i]

        if s >= x <= t:

            return max(s, t) - x

        elif s <= x >= t:

            return x - min(s, t)

        else:

            return abs(s - t) + min(abs(x - t), abs(x - s))

    else:

        return float('inf')





def solve(x):

    s_i = bisect.bisect_left(shrines, x)

    t_i = bisect.bisect_left(temples, x)

    return min([

        distance(s_i, t_i, x),

        distance(s_i, t_i - 1, x),

        distance(s_i - 1, t_i, x),

        distance(s_i - 1, t_i - 1, x),

    ])





for _ in range(q):

    print((solve(int(eval(input())))))

import bisect

import cmath

import heapq

import itertools

import math

import operator

import os

import re

import string

import sys

from collections import Counter, deque, defaultdict

from copy import deepcopy

from decimal import Decimal

from fractions import gcd

from functools import lru_cache, reduce

from operator import itemgetter, mul, add, xor



import numpy as np



if os.getenv("LOCAL"):

    sys.stdin = open("_in.txt", "r")



sys.setrecursionlimit(10 ** 9)

INF = float("inf")

IINF = 10 ** 18

MOD = 10 ** 9 + 7

# MOD = 998244353





A, B, Q = list(map(int, sys.stdin.buffer.readline().split()))

S = [int(sys.stdin.buffer.readline()) for _ in range(A)]

T = [int(sys.stdin.buffer.readline()) for _ in range(B)]

X = [int(sys.stdin.buffer.readline()) for _ in range(Q)]



st_i = np.searchsorted(T, S).tolist()

ts_i = np.searchsorted(S, T).tolist()

st = []

ts = []



for s, i in zip(S, st_i):

    d = INF

    if 0 < i:

        d = min(d, abs(T[i - 1] - s))

    if i < len(T):

        d = min(d, abs(T[i] - s))

    st.append(d)

for t, i in zip(T, ts_i):

    d = INF

    if 0 < i:

        d = min(d, abs(S[i - 1] - t))

    if i < len(S):

        d = min(d, abs(S[i] - t))

    ts.append(d)



ans = []

for x in X:

    d = INF

    si = bisect.bisect_left(S, x)

    if 0 < si:

        d = min(d, abs(S[si - 1] - x) + st[si - 1])

    if si < len(S):

        d = min(d, abs(S[si] - x) + st[si])

    ti = bisect.bisect_left(T, x)

    if 0 < ti:

        d = min(d, abs(T[ti - 1] - x) + ts[ti - 1])

    if ti < len(T):

        d = min(d, abs(T[ti] - x) + ts[ti])

    ans .append(d)



print(*ans, sep='\n')

import bisect

s_len, t_len, q = list(map(int, input().split()))
shrines = []
temples = []
for _ in range(s_len):
    shrines.append(int(eval(input())))
for _ in range(t_len):
    temples.append(int(eval(input())))


def distance(s_i, t_i, x):
    """
    s_i と t_i を最短でまわる距離。無効なインデックスなら inf を返す
    """
    if 0 <= s_i < s_len and 0 <= t_i < t_len:
        s = shrines[s_i]
        t = temples[t_i]
        if s >= x <= t:
            return max(s, t) - x
        elif s <= x >= t:
            return x - min(s, t)
        else:
            return abs(s - t) + min(abs(x - t), abs(x - s))
    else:
        return float("inf")


def solve(x):
    s_i = bisect.bisect_left(shrines, x)
    t_i = bisect.bisect_left(temples, x)
    return min(
        [
            distance(s_i, t_i, x),
            distance(s_i, t_i - 1, x),
            distance(s_i - 1, t_i, x),
            distance(s_i - 1, t_i - 1, x),
        ]
    )


for _ in range(q):
    print((solve(int(eval(input())))))

import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
A, B, Q = list(map(int, sys.stdin.buffer.readline().split()))
S = [int(sys.stdin.buffer.readline()) for _ in range(A)]
T = [int(sys.stdin.buffer.readline()) for _ in range(B)]
X = [int(sys.stdin.buffer.readline()) for _ in range(Q)]
st_i = np.searchsorted(T, S).tolist()
ts_i = np.searchsorted(S, T).tolist()
st = []
ts = []
for s, i in zip(S, st_i):
    d = INF
    if 0 < i:
        d = min(d, abs(T[i - 1] - s))
    if i < len(T):
        d = min(d, abs(T[i] - s))
    st.append(d)
for t, i in zip(T, ts_i):
    d = INF
    if 0 < i:
        d = min(d, abs(S[i - 1] - t))
    if i < len(S):
        d = min(d, abs(S[i] - t))
    ts.append(d)
ans = []
for x in X:
    d = INF
    si = bisect.bisect_left(S, x)
    if 0 < si:
        d = min(d, abs(S[si - 1] - x) + st[si - 1])
    if si < len(S):
        d = min(d, abs(S[si] - x) + st[si])
    ti = bisect.bisect_left(T, x)
    if 0 < ti:
        d = min(d, abs(T[ti - 1] - x) + ts[ti - 1])
    if ti < len(T):
        d = min(d, abs(T[ti] - x) + ts[ti])
    ans.append(d)
print(*ans, sep="\n")

+import cmath +import heapq +import itertools +import math +import operator +import os +import re +import string +import sys +from collections import Counter, deque, defaultdict +from copy import deepcopy +from decimal import Decimal +from fractions import gcd +from functools import lru_cache, reduce +from operator import itemgetter, mul, add, xor +import numpy as np -s_len, t_len, q = list(map(int, input().split())) -shrines = [] -temples = [] -for _ in range(s_len): -    shrines.append(int(eval(input()))) -for _ in range(t_len): -    temples.append(int(eval(input()))) - - -def distance(s_i, t_i, x): -    """ -    s_i と t_i を最短でまわる距離。無効なインデックスなら inf を返す -    """ -    if 0 <= s_i < s_len and 0 <= t_i < t_len: -        s = shrines[s_i] -        t = temples[t_i] -        if s >= x <= t: -            return max(s, t) - x -        elif s <= x >= t: -            return x - min(s, t) -        else: -            return abs(s - t) + min(abs(x - t), abs(x - s)) -    else: -        return float("inf") - - -def solve(x): -    s_i = bisect.bisect_left(shrines, x) -    t_i = bisect.bisect_left(temples, x) -    return min( -        [ -            distance(s_i, t_i, x), -            distance(s_i, t_i - 1, x), -            distance(s_i - 1, t_i, x), -            distance(s_i - 1, t_i - 1, x), -        ] -    ) - - -for _ in range(q): -    print((solve(int(eval(input()))))) +if os.getenv("LOCAL"): +    sys.stdin = open("_in.txt", "r") +sys.setrecursionlimit(10**9) +INF = float("inf") +IINF = 10**18 +MOD = 10**9 + 7 +# MOD = 998244353 +A, B, Q = list(map(int, sys.stdin.buffer.readline().split())) +S = [int(sys.stdin.buffer.readline()) for _ in range(A)] +T = [int(sys.stdin.buffer.readline()) for _ in range(B)] +X = [int(sys.stdin.buffer.readline()) for _ in range(Q)] +st_i = np.searchsorted(T, S).tolist() +ts_i = np.searchsorted(S, T).tolist() +st = [] +ts = [] +for s, i in zip(S, st_i): +    d = INF +    if 0 < i: +        d = min(d, abs(T[i - 1] - s)) +    if i < len(T): +        d = min(d, abs(T[i] - s)) +    st.append(d) +for t, i in zip(T, ts_i): +    d = INF +    if 0 < i: +        d = min(d, abs(S[i - 1] - t)) +    if i < len(S): +        d = min(d, abs(S[i] - t)) +    ts.append(d) +ans = [] +for x in X: +    d = INF +    si = bisect.bisect_left(S, x) +    if 0 < si: +        d = min(d, abs(S[si - 1] - x) + st[si - 1]) +    if si < len(S): +        d = min(d, abs(S[si] - x) + st[si]) +    ti = bisect.bisect_left(T, x) +    if 0 < ti: +        d = min(d, abs(T[ti - 1] - x) + ts[ti - 1]) +    if ti < len(T): +        d = min(d, abs(T[ti] - x) + ts[ti]) +    ans.append(d) +print(*ans, sep="\n")