import sys

import re

import math

import collections

import bisect

import itertools

import fractions

import functools

import copy

import heapq

import decimal

import statistics

import queue



# import numpy as np



sys.setrecursionlimit(10 ** 9)

INF = 10 ** 16

MOD = 10 ** 9 + 7

# MOD = 998244353



ni = lambda: int(sys.stdin.readline())

ns = lambda: list(map(int, sys.stdin.readline().split()))

na = lambda: list(map(int, sys.stdin.readline().split()))

na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])





# ===CODE===



def disLR(a, idx):

    small = a[max(0, idx - 1)]

    large = a[min(len(a) - 1, idx)]

    return small, large





def main():

    a, b, q = ns()

    s = [ni() for _ in range(a)]

    t = [ni() for _ in range(b)]



    for _ in range(q):

        ans = INF



        x = ni()

        tmpans = [0] * 4



        idxs = bisect.bisect_left(s, x)

        sml, lrg = disLR(s, idxs)

        tmpans[0] += abs(x - sml)

        tmpans[1] += abs(x - lrg)

        idxsml = bisect.bisect_left(t, sml)

        tmpans[0] += min([abs(sml - i) for i in disLR(t, idxsml)])

        idxlrg = bisect.bisect_left(t, lrg)

        tmpans[1] += min([abs(lrg - i) for i in disLR(t, idxlrg)])



        idxt = bisect.bisect_left(t, x)

        sml, lrg = disLR(t, idxt)

        tmpans[2] += abs(x - sml)

        tmpans[3] += abs(x - lrg)

        idxsml = bisect.bisect_left(s, sml)

        tmpans[2] += min([abs(sml - i) for i in disLR(s, idxsml)])

        idxlrg = bisect.bisect_left(s, lrg)

        tmpans[3] += min([abs(lrg - i) for i in disLR(s, idxlrg)])

        ans = min(ans, min(tmpans))

        print(ans)





if __name__ == '__main__':

    main()

import sys

import re

import math

import collections

import bisect

import itertools

import fractions

import functools

import copy

import heapq

import decimal

import statistics

import queue



# import numpy as np



sys.setrecursionlimit(10 ** 9)

INF = 10 ** 16

MOD = 10 ** 9 + 7

# MOD = 998244353



ni = lambda: int(sys.stdin.readline())

ns = lambda: list(map(int, sys.stdin.readline().split()))

na = lambda: list(map(int, sys.stdin.readline().split()))

na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])





# ===CODE===



def disLR(a, idx):

    small = a[max(0, idx - 1)]

    large = a[min(len(a) - 1, idx)]

    return [small, large]





def main():

    a, b, q = ns()

    s = [ni() for _ in range(a)]

    t = [ni() for _ in range(b)]



    for _ in range(q):

        ans = INF



        x = ni()



        idxs = bisect.bisect_left(s, x)

        a1 = disLR(s, idxs)



        idxt = bisect.bisect_left(t, x)

        a2 = disLR(t, idxt)



        for ta1 in a1:

            for ta2 in a2:

                tmp1 = abs(x - ta1) + abs(ta2 - ta1)

                tmp2 = abs(x - ta2) + abs(ta1 - ta2)

                ans = min(ans, tmp1, tmp2)



        print(ans)





if __name__ == '__main__':

    main()

import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np
sys.setrecursionlimit(10**9)
INF = 10**16
MOD = 10**9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])
# ===CODE===
def disLR(a, idx):
    small = a[max(0, idx - 1)]
    large = a[min(len(a) - 1, idx)]
    return small, large


def main():
    a, b, q = ns()
    s = [ni() for _ in range(a)]
    t = [ni() for _ in range(b)]
    for _ in range(q):
        ans = INF
        x = ni()
        tmpans = [0] * 4
        idxs = bisect.bisect_left(s, x)
        sml, lrg = disLR(s, idxs)
        tmpans[0] += abs(x - sml)
        tmpans[1] += abs(x - lrg)
        idxsml = bisect.bisect_left(t, sml)
        tmpans[0] += min([abs(sml - i) for i in disLR(t, idxsml)])
        idxlrg = bisect.bisect_left(t, lrg)
        tmpans[1] += min([abs(lrg - i) for i in disLR(t, idxlrg)])
        idxt = bisect.bisect_left(t, x)
        sml, lrg = disLR(t, idxt)
        tmpans[2] += abs(x - sml)
        tmpans[3] += abs(x - lrg)
        idxsml = bisect.bisect_left(s, sml)
        tmpans[2] += min([abs(sml - i) for i in disLR(s, idxsml)])
        idxlrg = bisect.bisect_left(s, lrg)
        tmpans[3] += min([abs(lrg - i) for i in disLR(s, idxlrg)])
        ans = min(ans, min(tmpans))
        print(ans)


if __name__ == "__main__":
    main()

import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np
sys.setrecursionlimit(10**9)
INF = 10**16
MOD = 10**9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])
# ===CODE===
def disLR(a, idx):
    small = a[max(0, idx - 1)]
    large = a[min(len(a) - 1, idx)]
    return [small, large]


def main():
    a, b, q = ns()
    s = [ni() for _ in range(a)]
    t = [ni() for _ in range(b)]
    for _ in range(q):
        ans = INF
        x = ni()
        idxs = bisect.bisect_left(s, x)
        a1 = disLR(s, idxs)
        idxt = bisect.bisect_left(t, x)
        a2 = disLR(t, idxt)
        for ta1 in a1:
            for ta2 in a2:
                tmp1 = abs(x - ta1) + abs(ta2 - ta1)
                tmp2 = abs(x - ta2) + abs(ta1 - ta2)
                ans = min(ans, tmp1, tmp2)
        print(ans)


if __name__ == "__main__":
    main()

-    return small, large +    return [small, large] -        tmpans = [0] * 4 -        sml, lrg = disLR(s, idxs) -        tmpans[0] += abs(x - sml) -        tmpans[1] += abs(x - lrg) -        idxsml = bisect.bisect_left(t, sml) -        tmpans[0] += min([abs(sml - i) for i in disLR(t, idxsml)]) -        idxlrg = bisect.bisect_left(t, lrg) -        tmpans[1] += min([abs(lrg - i) for i in disLR(t, idxlrg)]) +        a1 = disLR(s, idxs) -        sml, lrg = disLR(t, idxt) -        tmpans[2] += abs(x - sml) -        tmpans[3] += abs(x - lrg) -        idxsml = bisect.bisect_left(s, sml) -        tmpans[2] += min([abs(sml - i) for i in disLR(s, idxsml)]) -        idxlrg = bisect.bisect_left(s, lrg) -        tmpans[3] += min([abs(lrg - i) for i in disLR(s, idxlrg)]) -        ans = min(ans, min(tmpans)) +        a2 = disLR(t, idxt) +        for ta1 in a1: +            for ta2 in a2: +                tmp1 = abs(x - ta1) + abs(ta2 - ta1) +                tmp2 = abs(x - ta2) + abs(ta1 - ta2) +                ans = min(ans, tmp1, tmp2)