#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def bisect(a: "List[int]", x: int):
    lb = 0
    rb = len(a) + 1
    while lb + 1 < rb:
        m = (lb + rb) // 2
        if a[m - 1] >= x:
            rb = m
        else:
            lb = m
    return lb


def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    for xk in x:
        i = bisect(s, xk)
        j = bisect(t, xk)
        m = float("inf")
        if i > 0 and j > 0:
            m2 = max(xk - s[i - 1], xk - t[j - 1])
            m = min(m, m2)
        if i > 0 and j < B:
            ld = xk - s[i - 1]
            rd = t[j] - xk
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j > 0:
            rd = s[i] - xk
            ld = xk - t[j - 1]
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j < B:
            m2 = max(s[i] - xk, t[j] - xk)
            m = min(m, m2)
        print(m)


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 = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    t = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(A, B, Q, s, t, x)


if __name__ == '__main__':
    main() import sys sys try:
    from typing import List
except ImportError:
    pass except ImportError:
    pass from typing import List def bisect(a: "List[int]", x: int):
    lb = 0
    rb = len(a) + 1
    while lb + 1 < rb:
        m = (lb + rb) // 2
        if a[m - 1] >= x:
            rb = m
        else:
            lb = m
    return lb bisect lb = 0 lb 0 rb = len(a) + 1 rb len(a) + 1 len(a) len a 1 while lb + 1 < rb:
        m = (lb + rb) // 2
        if a[m - 1] >= x:
            rb = m
        else:
            lb = m
     lb + 1 < rb lb + 1 lb 1 rb m = (lb + rb) // 2 m (lb + rb) // 2 lb + rb lb rb 2 if a[m - 1] >= x:
            rb = m
        else:
            lb = m
     a[m - 1] >= x a[m - 1] a m - 1 m 1 x rb = m rb m lb = m lb m return lb lb a: "List[int]" a x: int x def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    for xk in x:
        i = bisect(s, xk)
        j = bisect(t, xk)
        m = float("inf")
        if i > 0 and j > 0:
            m2 = max(xk - s[i - 1], xk - t[j - 1])
            m = min(m, m2)
        if i > 0 and j < B:
            ld = xk - s[i - 1]
            rd = t[j] - xk
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j > 0:
            rd = s[i] - xk
            ld = xk - t[j - 1]
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j < B:
            m2 = max(s[i] - xk, t[j] - xk)
            m = min(m, m2)
        print(m) solve for xk in x:
        i = bisect(s, xk)
        j = bisect(t, xk)
        m = float("inf")
        if i > 0 and j > 0:
            m2 = max(xk - s[i - 1], xk - t[j - 1])
            m = min(m, m2)
        if i > 0 and j < B:
            ld = xk - s[i - 1]
            rd = t[j] - xk
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j > 0:
            rd = s[i] - xk
            ld = xk - t[j - 1]
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j < B:
            m2 = max(s[i] - xk, t[j] - xk)
            m = min(m, m2)
        print(m) xk x i = bisect(s, xk) i bisect(s, xk) bisect s xk j = bisect(t, xk) j bisect(t, xk) bisect t xk m = float("inf") m float("inf") float "inf" if i > 0 and j > 0:
            m2 = max(xk - s[i - 1], xk - t[j - 1])
            m = min(m, m2)
         i > 0 and j > 0 i > 0 i 0 j > 0 j 0 m2 = max(xk - s[i - 1], xk - t[j - 1]) m2 max(xk - s[i - 1], xk - t[j - 1]) max xk - s[i - 1] xk s[i - 1] s i - 1 i 1 xk - t[j - 1] xk t[j - 1] t j - 1 j 1 m = min(m, m2) m min(m, m2) min m m2 if i > 0 and j < B:
            ld = xk - s[i - 1]
            rd = t[j] - xk
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
         i > 0 and j < B i > 0 i 0 j < B j B ld = xk - s[i - 1] ld xk - s[i - 1] xk s[i - 1] s i - 1 i 1 rd = t[j] - xk rd t[j] - xk t[j] t j xk m2 = min(ld + ld + rd, ld + rd + rd) m2 min(ld + ld + rd, ld + rd + rd) min ld + ld + rd ld + ld ld ld rd ld + rd + rd ld + rd ld rd rd m = min(m, m2) m min(m, m2) min m m2 if i < A and j > 0:
            rd = s[i] - xk
            ld = xk - t[j - 1]
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
         i < A and j > 0 i < A i A j > 0 j 0 rd = s[i] - xk rd s[i] - xk s[i] s i xk ld = xk - t[j - 1] ld xk - t[j - 1] xk t[j - 1] t j - 1 j 1 m2 = min(ld + ld + rd, ld + rd + rd) m2 min(ld + ld + rd, ld + rd + rd) min ld + ld + rd ld + ld ld ld rd ld + rd + rd ld + rd ld rd rd m = min(m, m2) m min(m, m2) min m m2 if i < A and j < B:
            m2 = max(s[i] - xk, t[j] - xk)
            m = min(m, m2)
         i < A and j < B i < A i A j < B j B m2 = max(s[i] - xk, t[j] - xk) m2 max(s[i] - xk, t[j] - xk) max s[i] - xk s[i] s i xk t[j] - xk t[j] t j xk m = min(m, m2) m min(m, m2) min m m2 print(m) print m A: int A B: int B Q: int Q s: "List[int]" s t: "List[int]" t x: "List[int]" x 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 = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    t = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(A, B, Q, s, t, x) main def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
     iterate_tokens for line in sys.stdin:
            for word in line.split():
                yield word
     line sys.stdin sys stdin for word in line.split():
                yield word
     word line.split() line.split line split yield word word tokens = iterate_tokens() tokens iterate_tokens() iterate_tokens A = int(next(tokens)) A int(next(tokens)) int next(tokens) next tokens B = int(next(tokens)) B int(next(tokens)) int next(tokens) next tokens Q = int(next(tokens)) Q int(next(tokens)) int next(tokens) next tokens int(next(tokens)) for _ in range(A) for _ in range(A) _ range(A) range A for _ in range(A) int(next(tokens)) int next(tokens) next tokens s = [int(next(tokens)) for _ in range(A)] s [int(next(tokens)) for _ in range(A)] int(next(tokens)) for _ in range(B) for _ in range(B) _ range(B) range B for _ in range(B) int(next(tokens)) int next(tokens) next tokens t = [int(next(tokens)) for _ in range(B)] t [int(next(tokens)) for _ in range(B)] int(next(tokens)) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) int(next(tokens)) int next(tokens) next tokens x = [int(next(tokens)) for _ in range(Q)] x [int(next(tokens)) for _ in range(Q)] solve(A, B, Q, s, t, x) solve A B Q s t x if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def bisect(a: "List[int]", x: int):
    lb = 0
    rb = len(a) + 1
    while lb + 1 < rb:
        m = (lb + rb) // 2
        if a[m - 1] >= x:
            rb = m
        else:
            lb = m
    return lb def bisect(a: "List[int]", x: int):
    lb = 0
    rb = len(a) + 1
    while lb + 1 < rb:
        m = (lb + rb) // 2
        if a[m - 1] >= x:
            rb = m
        else:
            lb = m
    return lb bisect def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    for xk in x:
        i = bisect(s, xk)
        j = bisect(t, xk)
        m = float("inf")
        if i > 0 and j > 0:
            m2 = max(xk - s[i - 1], xk - t[j - 1])
            m = min(m, m2)
        if i > 0 and j < B:
            ld = xk - s[i - 1]
            rd = t[j] - xk
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j > 0:
            rd = s[i] - xk
            ld = xk - t[j - 1]
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j < B:
            m2 = max(s[i] - xk, t[j] - xk)
            m = min(m, m2)
        print(m) def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    for xk in x:
        i = bisect(s, xk)
        j = bisect(t, xk)
        m = float("inf")
        if i > 0 and j > 0:
            m2 = max(xk - s[i - 1], xk - t[j - 1])
            m = min(m, m2)
        if i > 0 and j < B:
            ld = xk - s[i - 1]
            rd = t[j] - xk
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j > 0:
            rd = s[i] - xk
            ld = xk - t[j - 1]
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j < B:
            m2 = max(s[i] - xk, t[j] - xk)
            m = min(m, m2)
        print(m) solve 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 = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    t = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(A, B, Q, s, t, x) 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 = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    t = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(A, B, Q, s, t, x) main
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def bisect(a: "List[int]", x: int):
    lb = 0
    rb = len(a) + 1
    while lb + 1 < rb:
        m = (lb + rb) // 2
        if a[m - 1] >= x:
            rb = m
        else:
            lb = m
    return lb


def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    for xk in x:
        i = bisect(s, xk)
        j = bisect(t, xk)
        m = float("inf")
        if i > 0 and j > 0:
            m2 = max(xk - s[i - 1], xk - t[j - 1])
            m = min(m, m2)
        if i > 0 and j < B:
            ld = xk - s[i - 1]
            rd = t[j] - xk
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j > 0:
            rd = s[i] - xk
            ld = xk - t[j - 1]
            m2 = min(ld + ld + rd, ld + rd + rd)
            m = min(m, m2)
        if i < A and j < B:
            m2 = max(s[i] - xk, t[j] - xk)
            m = min(m, m2)
        print(m)


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 = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    t = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(A, B, Q, s, t, x)


if __name__ == '__main__':
    main()
