CodeEff/ECCO huggingface dataset:
# Original solution
#!/usr/bin/env python3
import sys
from bisect import bisect_right


def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    b, d = bisect_right(s, x), bisect_right(t, x)
    ret = 10e18

    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            ret = min(ret, d1, d2)
    print(ret)


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    INF = 10e18
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    s = [-INF] + [int(next(tokens)) for _ in range(A)] + [INF]  # type: "List[int]"
    t = [-INF] + [int(next(tokens)) for _ in range(B)] + [INF]  # type: "List[int]"

    for x in range(Q):
        x = int(eval(input()))
        solve(A, B, Q, s, t, x)


if __name__ == "__main__":
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
from bisect import bisect_right

INF = 10e11

def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    b, d = bisect_right(s, x), bisect_right(t, x)
    ret = INF

    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            ret = min(ret, d1, d2)
    print(ret)


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    s = [-INF] + [int(next(tokens)) for _ in range(A)] + [INF]  # type: "List[int]"
    t = [-INF] + [int(next(tokens)) for _ in range(B)] + [INF]  # type: "List[int]"

    for x in range(Q):
        x = int(eval(input()))
        solve(A, B, Q, s, t, x)


if __name__ == "__main__":
    main()
# Original solution
INF = 1e20

A, B, Q = [int(i) for i in input().split()]
S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
X = [int(eval(input())) for _ in range(Q)]

from bisect import bisect_left

for x in X:
    s = bisect_left(S, x)
    t = bisect_left(T, x)
    mi = INF
    for ss in [S[s], S[s - 1]]:
        for tt in [T[t], T[t - 1]]:
            mi = min(mi, abs(ss - x) + abs(tt - ss), abs(tt - x) + abs(ss - tt))
    print(mi)


# Optimized solution
INF = 1e20

A, B, Q = [int(i) for i in input().split()]
S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
X = [int(eval(input())) for _ in range(Q)]

from bisect import bisect_left

mins = []
for x in X:
    s = bisect_left(S, x)
    t = bisect_left(T, x)
    mi = INF
    for ss in [S[s], S[s - 1]]:
        for tt in [T[t], T[t - 1]]:
            mi = min(mi, abs(ss - x) + abs(tt - ss), abs(tt - x) + abs(ss - tt))
    mins.append(str(mi))
print(("\n".join(mins)))
# Original solution
from bisect import bisect
A, B, Q = list(map(int, input().split()))
S, T =[None] * (A+2), [None] * (B+2)
S[0], T[0] = -10**20, -10**20
for i in range(A):
    S[i+1] = int(eval(input()))
for i in range(B):
    T[i+1] = int(eval(input()))
S[A+1] = 10**20
T[B+1] = 10**20

lenS, lenT = len(S), len(T)
for _ in range(Q):
    x = int(eval(input()))
    si, ti = bisect(S, x, 0, lenS), bisect(T, x, 0, lenT)
    sLength0, sLength1 = x - S[si-1], S[si] - x
    tLength0, tLength1 = x - T[ti-1], T[ti] - x
    Ans = (max(sLength0, tLength0), max(sLength1, tLength1), sLength0 + tLength1 + min(sLength0, tLength1), sLength1 + tLength0 + min(sLength1, tLength0))
    print((min(Ans)))

# Optimized solution
import sys
from bisect import bisect
F = sys.stdin
A, B, Q = list(map(int, F.readline().strip("\n").split(" ")))
S, T =[None] * (A+2), [None] * (B+2)
S[0], T[0] = -10**20, -10**20
for i in range(A):
    S[i+1] = int(F.readline().strip("\n"))
for i in range(B):
    T[i+1] = int(F.readline().strip("\n"))
S[A+1] = 10**20
T[B+1] = 10**20

lenS, lenT = len(S), len(T)
for _ in range(Q):
    x = int(F.readline().strip("\n"))
    si, ti = bisect(S, x, 0, lenS), bisect(T, x, 0, lenT)
    sLength0, sLength1 = x - S[si-1], S[si] - x
    tLength0, tLength1 = x - T[ti-1], T[ti] - x
    Ans = (max(sLength0, tLength0), max(sLength1, tLength1), sLength0 + tLength1 + min(sLength0, tLength1), sLength1 + tLength0 + min(sLength1, tLength0))
    print((min(Ans)))
# Original solution
A, B, Q = list(map(int, input().split()))

INF = 10 ** 11 + 1
S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
X = [int(eval(input())) for _ in range(Q)]

def bsr(a, v):
	lo, hi = 0, len(a) - 1
	while lo <= hi:
		mi = (lo + hi) // 2
		if v < a[mi]:
			hi = mi - 1
		else:
			lo = mi + 1
	return lo

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	cost = []
	for m in [S[sr], S[sl]]:
		for n in [T[tr], T[tl]]:
			cost += [abs(x - m) + abs(m - n), abs(x - n) + abs(m - n)]
	print((min(cost)))


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

INF = 10 ** 11 + 1
S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
X = [int(eval(input())) for _ in range(Q)]

def bsr(a, v):
	lo, hi = 0, len(a)
	while lo < hi:
		mi = (lo + hi) // 2
		if v < a[mi]:
			hi = mi
		else:
			lo = mi + 1
	return lo

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	cost = []
	for m in [S[sr], S[sl]]:
		for n in [T[tr], T[tl]]:
			cost += [abs(x - m) + abs(m - n), abs(x - n) + abs(m - n)]
	print((min(cost)))
# Original solution
import bisect

A, B, Q = list(map(int, input().split()))
S = [int(eval(input())) for _ in range(A)]
T = [int(eval(input())) for _ in range(B)]
X = [int(eval(input())) for _ in range(Q)]
"""
def bsr(a, v, lo=0, hi=None):
	if None == hi:
		hi = len(a) - 1
	while lo <= hi:
		mi = (lo + hi) // 2
		if a[mi] <= v:
			lo = mi + 1
		else:
			hi = mi - 1
	return lo
"""
bsr = bisect.bisect_right

INF = 10 ** 18
s = [-INF] + S + [INF]
t = [-INF] + T + [INF]

for x in X:
	sp = bsr(s, x)
	tp = bsr(t, x)
	cost = []
	cost += [abs(s[sp - 0] - x) + abs(s[sp - 0] - t[tp - 0])]
	cost += [abs(s[sp - 1] - x) + abs(s[sp - 1] - t[tp - 0])]
	cost += [abs(s[sp - 0] - x) + abs(s[sp - 0] - t[tp - 1])]
	cost += [abs(s[sp - 1] - x) + abs(s[sp - 1] - t[tp - 1])]
	cost += [abs(t[tp - 0] - x) + abs(s[sp - 0] - t[tp - 0])]
	cost += [abs(t[tp - 1] - x) + abs(s[sp - 0] - t[tp - 1])]
	cost += [abs(t[tp - 0] - x) + abs(s[sp - 1] - t[tp - 0])]
	cost += [abs(t[tp - 1] - x) + abs(s[sp - 1] - t[tp - 1])]
	print((min(cost)))


# Optimized solution
# お約束
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def parse(args, *params):
    return tuple(p(v) for p, v in zip(params, next(args).split()))

from bisect import bisect_right as bsr

# エントリーポイント
def main(args):
    A, B, Q = parse(args, int, int, int)
    S = list(int(next(args)) for _ in range(A))
    T = list(int(next(args)) for _ in range(B))
    X = tuple(int(next(args)) for _ in range(Q))

    s = [-INF] + S + [INF]
    t = [-INF] + T + [INF]
    for x in X:
        sr = bsr(s, x)
        sl = sr - 1
        tr = bsr(t, x)
        tl = tr - 1
        min_cost = INF
        for st in [s[sl], s[sr]]:
            for tt in [t[tl], t[tr]]:
                min_cost = min(min_cost, abs(st - x) + abs(tt - st))
                min_cost = min(min_cost, abs(tt - x) + abs(tt - st))
        print(min_cost)

import sys
if __name__ == '__main__':
    main(iter(sys.stdin.read().split("\n")))
# Original solution
import bisect
A, B, Q = list(map(int,input().split()))
s = [-10**20] + [int(eval(input())) for k in range(A)] + [10**20,10**20]
t = [-10**20] + [int(eval(input())) for k in range(B)] + [10**20,10**20]

for _ in range(Q):
    x = int(eval(input()))
    print((min(
        max(s[bisect.bisect_left(s,x)],t[bisect.bisect_left(t,x)])-x,
        x-min(s[bisect.bisect_left(s,x)-1],t[bisect.bisect_left(t,x)-1]),
        s[bisect.bisect_left(s,x)]-x + s[bisect.bisect_left(s,x)]-t[bisect.bisect_left(t,x)-1],
        t[bisect.bisect_left(t,x)]-x + t[bisect.bisect_left(t,x)]-s[bisect.bisect_left(s,x)-1],
        x-s[bisect.bisect_left(s,x)-1] + t[bisect.bisect_left(t,x)]-s[bisect.bisect_left(s,x)-1],
        x-t[bisect.bisect_left(t,x)-1] + s[bisect.bisect_left(s,x)]-t[bisect.bisect_left(t,x)-1])))


# Optimized solution
import bisect
A, B, Q = list(map(int,input().split()))
s = [-10**20] + [int(eval(input())) for k in range(A)] + [10**20,10**20]
t = [-10**20] + [int(eval(input())) for k in range(B)] + [10**20,10**20]

for _ in range(Q):
    x = int(eval(input()))
    S = bisect.bisect_left(s,x)
    T = bisect.bisect_left(t,x)
    print((min(
        max(s[S],t[T])-x,
        x-min(s[S-1],t[T-1]),
        s[S]-x + s[S]-t[T-1],
        t[T]-x + t[T]-s[S-1],
        x-s[S-1] + t[T]-s[S-1],
        x-t[T-1] + s[S]-t[T-1])))
# Original solution
import bisect
A, B, Q = list(map(int,input().split()))
s = [-10**20] + [int(eval(input())) for k in range(A)] + [10**20,10**20]
t = [-10**20] + [int(eval(input())) for k in range(B)] + [10**20,10**20]

for _ in range(Q):
    x = int(eval(input()))
    S = bisect.bisect_left(s,x)
    T = bisect.bisect_left(t,x)
    print((min(
        max(s[S],t[T])-x,
        x-min(s[S-1],t[T-1]),
        s[S]-x + s[S]-t[T-1],
        t[T]-x + t[T]-s[S-1],
        x-s[S-1] + t[T]-s[S-1],
        x-t[T-1] + s[S]-t[T-1])))


# Optimized solution
import bisect
import sys
def input():
    return sys.stdin.readline()[:-1]
def main():
    A, B, Q = list(map(int,input().split()))
    s = [-10**20] + [int(eval(input())) for k in range(A)] + [10**20,10**20]
    t = [-10**20] + [int(eval(input())) for k in range(B)] + [10**20,10**20]

    for _ in range(Q):
        x = int(eval(input()))
        S = bisect.bisect_left(s,x)
        T = bisect.bisect_left(t,x)
        print((min(
            max(s[S],t[T])-x,
            x-min(s[S-1],t[T-1]),
            s[S]-x + s[S]-t[T-1],
            t[T]-x + t[T]-s[S-1],
            x-s[S-1] + t[T]-s[S-1],
            x-t[T-1] + s[S]-t[T-1])))
if __name__ == '__main__':
    main()
# Original solution
import bisect

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

Z=[-10**10]
T=[-10**10]

for i in range(A):
    s=int(eval(input()))
    Z.append(s)
Z.append(10**11)
for i in range(B):
    t=int(eval(input()))
    T.append(t)
T.append(10**11)
    
for i in range(Q):
    x=int(eval(input()))
    a=max(Z[bisect.bisect_left(Z,x)],T[bisect.bisect_left(T,x)])-x
    b=x-min(Z[bisect.bisect_left(Z,x)-1],T[bisect.bisect_left(T,x)-1])
    c=Z[bisect.bisect_left(Z,x)]-T[bisect.bisect_left(T,x)-1]+(x-T[bisect.bisect_left(T,x)-1])
    d=Z[bisect.bisect_left(Z,x)]-T[bisect.bisect_left(T,x)-1]+(Z[bisect.bisect_left(Z,x)]-x)
    e=T[bisect.bisect_left(T,x)]-Z[bisect.bisect_left(Z,x)-1]+(x-Z[bisect.bisect_left(Z,x)-1])
    f=T[bisect.bisect_left(T,x)]-Z[bisect.bisect_left(Z,x)-1]+(T[bisect.bisect_left(T,x)]-x)
    print((min(a,b,c,d,e,f)))

# Optimized solution
import bisect
import sys
input = sys.stdin.readline
A,B,Q=list(map(int,input().split()))

Z=[-10**10]
T=[-10**10]

for i in range(A):
    s=int(eval(input()))
    Z.append(s)
Z.append(10**11)
for i in range(B):
    t=int(eval(input()))
    T.append(t)
T.append(10**11)
    
for i in range(Q):
    x=int(eval(input()))
    a=max(Z[bisect.bisect_left(Z,x)],T[bisect.bisect_left(T,x)])-x
    b=x-min(Z[bisect.bisect_left(Z,x)-1],T[bisect.bisect_left(T,x)-1])
    c=Z[bisect.bisect_left(Z,x)]-T[bisect.bisect_left(T,x)-1]+(x-T[bisect.bisect_left(T,x)-1])
    d=Z[bisect.bisect_left(Z,x)]-T[bisect.bisect_left(T,x)-1]+(Z[bisect.bisect_left(Z,x)]-x)
    e=T[bisect.bisect_left(T,x)]-Z[bisect.bisect_left(Z,x)-1]+(x-Z[bisect.bisect_left(Z,x)-1])
    f=T[bisect.bisect_left(T,x)]-Z[bisect.bisect_left(Z,x)-1]+(T[bisect.bisect_left(T,x)]-x)
    print((min(a,b,c,d,e,f)))
# Original solution
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(eval(input()))


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


# inputs
A, B, Q = 0, 0, 0
S = []
T = []
X = []


def set_inputs():
    global A, B, Q, S, T, X
    A, B, Q = get_list_of_int()
    for _ in range(A):
        S.append(get_int())
    for _ in range(B):
        T.append(get_int())
    for _ in range(Q):
        X.append(get_int())


def main():
    set_inputs()

    for i in range(Q):
        ns = abs(max([S[j] - X[i] for j in range(A) if S[j] - X[i] <= 0] + [-inf]))
        ps = abs(min([S[j] - X[i] for j in range(A) if S[j] - X[i] >= 0] + [inf]))
        nt = abs(max([T[j] - X[i] for j in range(B) if T[j] - X[i] <= 0] + [-inf]))
        pt = abs(min([T[j] - X[i] for j in range(B) if T[j] - X[i] >= 0] + [inf]))
        print((min(max(ns, nt), max(ps, pt), ns * 2 + pt, ns + pt * 2, nt * 2 + ps, nt + ps * 2)))


if __name__ == '__main__':
    main()


# Optimized solution
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(eval(input()))


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


# inputs
A, B, Q = 0, 0, 0
S = []
T = []
X = []


def set_inputs():
    global A, B, Q, S, T, X
    A, B, Q = get_list_of_int()
    for _ in range(A):
        S.append(get_int())
    for _ in range(B):
        T.append(get_int())
    for _ in range(Q):
        X.append(get_int())


def main():
    set_inputs()

    for i in range(Q):
        nsi = bisect_left(S, X[i])
        if nsi == 0:
            ns = inf
        else:
            ns = X[i] - S[nsi-1]
        psi = bisect_left(S, X[i])
        if psi == A:
            ps = inf
        else:
            ps = S[nsi] - X[i]
        nti = bisect_left(T, X[i])
        if nti == 0:
            nt = inf
        else:
            nt = X[i] - T[nti-1]
        pti = bisect_left(T, X[i])
        if pti == B:
            pt = inf
        else:
            pt = T[nti] - X[i]
        print((min(max(ns, nt), max(ps, pt), ns * 2 + pt, ns + pt * 2, nt * 2 + ps, nt + ps * 2)))


if __name__ == '__main__':
    main()
# Original solution
import bisect

a, b, q = list(map(int, input().split()))
s = sorted([int(eval(input())) for _ in range(a)])
t = sorted([int(eval(input())) for _ in range(b)])

for _ in range(q):
    x = int(eval(input()))
    s_i = bisect.bisect_left(s, x)
    t_i = bisect.bisect_left(t, x)

    s0, s1, t0, t1 = None, None, None, None
    ans = 10 ** 11
    if s_i > 0:
        s0 = x - s[s_i-1]
    if s_i < a:
        s1 = s[s_i] - x
    if t_i > 0:
        t0 = x - t[t_i-1]
    if t_i < b:
        t1 = t[t_i] - x

    if s0 is not None and t0 is not None:
        ans = min(ans, max(s0, t0))
    if s1 is not None and t1 is not None:
        ans = min(ans, max(s1, t1))
    if s0 is not None and t1 is not None:
        ans = min(ans, s0*2 + t1, t1*2 + s0)
    if s1 is not None and t0 is not None:
        ans = min(ans, s1*2 + t0, t0*2 + s1)

    print(ans)

# Optimized solution
import bisect
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

a, b, q = list(map(int, input().split()))
s = sorted([int(eval(input())) for _ in range(a)])
t = sorted([int(eval(input())) for _ in range(b)])

for _ in range(q):
    x = int(eval(input()))
    s_i = bisect.bisect_left(s, x)
    t_i = bisect.bisect_left(t, x)

    s0, s1, t0, t1 = None, None, None, None
    ans = 10 ** 11
    if s_i > 0:
        s0 = x - s[s_i-1]
    if s_i < a:
        s1 = s[s_i] - x
    if t_i > 0:
        t0 = x - t[t_i-1]
    if t_i < b:
        t1 = t[t_i] - x

    if s0 is not None and t0 is not None:
        ans = min(ans, max(s0, t0))
    if s1 is not None and t1 is not None:
        ans = min(ans, max(s1, t1))
    if s0 is not None and t1 is not None:
        ans = min(ans, s0*2 + t1, t1*2 + s0)
    if s1 is not None and t0 is not None:
        ans = min(ans, s1*2 + t0, t0*2 + s1)

    print(ans)
# Original solution
# D
a, b, q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(a)]
t = [int(eval(input())) for i in range(b)]
x = [int(eval(input())) for i in range(q)]

def route(start, mid, end):
    return abs(start-mid) + abs(mid-end)

for i in range(q):
    ans = 10000000000000000000000000
    # jinja
    j_list = [jin-x[i] for jin in s if (jin-x[i])<= 0]
    if len(j_list) != 0:
        j_w = j_list[-1] + x[i]
        t_list = [ter-j_w for ter in t if ter-j_w<=0]
        if len(t_list) != 0:
            t_w = t_list[-1] + j_w
            ans = min(route(x[i], j_w,t_w), ans)
        t_list = [ter-j_w for ter in t if ter-j_w>0]
        if len(t_list) != 0:
            t_e = t_list[0] + j_w
            ans = min(route(x[i], j_w,t_e), ans)
    j_list = [jin-x[i] for jin in s if (jin-x[i]) > 0]
    if len(j_list) != 0:
        j_e = j_list[0] + x[i]
        t_list = [ter-j_e for ter in t if ter-j_e <= 0]
        if len(t_list) != 0:
            t_w = t_list[-1] + j_e
            ans = min(route(x[i], j_e,t_w), ans)
        t_list = [ter-j_e for ter in t if ter-j_e > 0]
        if len(t_list) != 0:
            t_e = t_list[0] + j_e
            ans = min(route(x[i], j_e,t_e), ans)

    t_list = [ter-x[i] for ter in t if ter-x[i]<=0]
    if len(t_list) != 0:
        t_w = t_list[-1] + x[i]
        j_list = [jin-t_w for jin in s if jin-t_w<=0]
        if len(j_list) != 0:
            j_w = j_list[-1] + t_w
            ans = min(route(x[i], t_w,j_w), ans)
        j_list = [jin-t_w for jin in s if jin-t_w>0]
        if len(j_list) != 0:
            j_e = j_list[0] + t_w
            ans = min(route(x[i], t_w,j_e), ans)
    t_list = [ter-x[i] for ter in t if ter-x[i]>0]
    if len(t_list) != 0:
        t_e = t_list[0] + x[i]
        j_list = [jin-t_e for jin in s if jin-t_e<=0]
        if len(j_list) != 0:
            j_w = j_list[-1] + t_e
            ans = min(route(x[i], t_e,j_w), ans)
        j_list = [jin-t_e for jin in s if jin-t_e>0]
        if len(j_list) != 0:
            j_e = j_list[0] + t_e
            ans = min(route(x[i], t_e,j_e), ans)
    print(ans)

# Optimized solution
import bisect
A, B, Q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
for q in range(Q):
    x = int(eval(input()))
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)
# Original solution
import bisect

def calc_distance(frm, x, y):
	#frmからx, yのに地点を通るのに必要な距離を計算する
	return min(abs(frm - x), abs(frm - y) ) + abs(x - y)

def calc_both_end(frm, us):
	#地点frmに囲まれた2点を返す。
	#片側しか囲われていない場合は最寄の2点
	if len(us) == 1:
		return us[0], us[0]

	idx = bisect.bisect_left(us, frm)
	if idx == 0:
		return us[0], us[1]
	elif idx == len(us):
		return us[len(us) - 2], us[len(us) - 1]
	else:
		return us[idx - 1], us[idx]

def find(ss, ts, x):
	s1, s2 = calc_both_end(x, ss)
	t1, t2 = calc_both_end(x, ts)
	ans = min(calc_distance(x, s1, t1), calc_distance(x, s1, t2), calc_distance(x, s2, t1), calc_distance(x, s2, t2))
	return ans

a, b, q = list(map(int, input().split()))
ss = [int(eval(input())) for _ in range(a)]
ts = [int(eval(input())) for _ in range(b)]
xs = [int(eval(input())) for _ in range(q)]

for x in xs:
	print((find(ss, ts, x)))

# Optimized solution
import bisect

def calc_distance(frm, x, y):
	return min(abs(frm - x), abs(frm - y) ) + abs(x - y)

def calc_2points(frm, us):
	idx = bisect.bisect_left(us, frm)
	return us[idx - 1], us[idx]

def calc_min(ss, ts, x):
	s1, s2 = calc_2points(x, ss)
	t1, t2 = calc_2points(x, ts)
	ans = min(calc_distance(x, s1, t1), calc_distance(x, s1, t2), calc_distance(x, s2, t1), calc_distance(x, s2, t2))
	return ans

INF = 10 ** 20
a, b, q = list(map(int, input().split()))
ss = [-INF] + [int(eval(input())) for _ in range(a)] + [INF]
ts = [-INF] + [int(eval(input())) for _ in range(b)] + [INF]
xs = [int(eval(input())) for _ in range(q)]

for x in xs:
	print((calc_min(ss, ts, x)))
# Original solution
import bisect

a, b, q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF] + [int(eval(input())) for i in range(a)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(b)] + [INF]
ans = []
for i in range(q):
    x = int(eval(input()))
    idxs = bisect.bisect(s, x)
    idxt = bisect.bisect(t, x)
    lis = []
    lis.append(x - min(s[idxs - 1], t[idxt -1]))
    lis.append(x - s[idxs - 1] + (t[idxt] - s[idxs - 1]))
    lis.append(t[idxt] - x + (t[idxt] - s[idxs - 1]))
    lis.append(x - t[idxt - 1] + (s[idxs] - t[idxt - 1]))
    lis.append(s[idxs] - x + (s[idxs] - t[idxt - 1]))
    lis.append(max(s[idxs], t[idxt]) - x)
    ans.append(min(lis))
for i in range(q):
    print((ans[i]))





# Optimized solution
import bisect
import sys
input = sys.stdin.readline
a, b, q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF] + [int(eval(input())) for i in range(a)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(b)] + [INF]
ans = []
for i in range(q):
    x = int(eval(input()))
    idxs = bisect.bisect(s, x)
    idxt = bisect.bisect(t, x)
    lis = []
    lis.append(x - min(s[idxs - 1], t[idxt -1]))
    lis.append(x - s[idxs - 1] + (t[idxt] - s[idxs - 1]))
    lis.append(t[idxt] - x + (t[idxt] - s[idxs - 1]))
    lis.append(x - t[idxt - 1] + (s[idxs] - t[idxt - 1]))
    lis.append(s[idxs] - x + (s[idxs] - t[idxt - 1]))
    lis.append(max(s[idxs], t[idxt]) - x)
    ans.append(min(lis))
for i in range(q):
    print((ans[i]))
# Original solution
import bisect
import sys
input = sys.stdin.readline
a, b, q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF] + [int(eval(input())) for i in range(a)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(b)] + [INF]
ans = []
for i in range(q):
    x = int(eval(input()))
    idxs = bisect.bisect(s, x)
    idxt = bisect.bisect(t, x)
    lis = []
    lis.append(x - min(s[idxs - 1], t[idxt -1]))
    lis.append(x - s[idxs - 1] + (t[idxt] - s[idxs - 1]))
    lis.append(t[idxt] - x + (t[idxt] - s[idxs - 1]))
    lis.append(x - t[idxt - 1] + (s[idxs] - t[idxt - 1]))
    lis.append(s[idxs] - x + (s[idxs] - t[idxt - 1]))
    lis.append(max(s[idxs], t[idxt]) - x)
    ans.append(min(lis))
for i in range(q):
    print((ans[i]))





# Optimized solution
import bisect
import sys
input = sys.stdin.readline
a, b, q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF] + [int(eval(input())) for i in range(a)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(b)] + [INF]
ans = []
for i in range(q):
    x = int(eval(input()))
    idxs = bisect.bisect(s, x)
    idxt = bisect.bisect(t, x)
    ans.append(min(x - min(s[idxs - 1], t[idxt -1]),
                     x - s[idxs - 1] + (t[idxt] - s[idxs - 1]),
                     t[idxt] - x + (t[idxt] - s[idxs - 1]),
                     x - t[idxt - 1] + (s[idxs] - t[idxt - 1]),
                     s[idxs] - x + (s[idxs] - t[idxt - 1]),
                     max(s[idxs], t[idxt]) - x,
                     x - min(s[idxs - 1], t[idxt -1])))
for i in range(q):
    print((ans[i]))