x=[]

for i,j in enumerate(map(int,input().split())):

    c=[]

    for l in range(j):

        t=int(eval(input()))

        x.append((i,l,t))

        c.append([t])

x.sort(key=lambda x:x[2])

l=[-10**20]*2

for y in x:

    if y[0] != 2: 

        l[y[0]]=y[2]

    else:

        c[y[1]]+=l[:]

l=[10**20]*2

for y in x[::-1]:

    if y[0] != 2: 

        l[y[0]]=y[2]

    else:

        c[y[1]]+=l[:]

print(("\n".join(str(min(d[0]-min(d[1],d[2]),max(d[3],d[4])-d[0],

        d[4]-d[1]+min(d[0]-d[1],d[4]-d[0]),

        d[3]-d[2]+min(d[0]-d[2],d[3]-d[0])

        )) for d in c)

        ))

import sys

input = sys.stdin.readline

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

inf = 10**18

S = [-inf]

for _ in range(A):

    S.append(int(eval(input())))

S.append(inf)

T = [-inf]

for _ in range(B):

    T.append(int(eval(input())))

T.append(inf)

def f_s(x, l):

    mn, mx = -1, len(l)

    idx = mx//2

    while mx-mn>1:

        if l[idx] < x:

            idx, mn = (idx + mx)//2, idx

            continue

        idx, mx = (idx + mn)//2, idx

    return idx



for _ in range(Q):

    q = int(eval(input()))

    xi, yi = f_s(q, S), f_s(q, T)

    s1, s2 = S[xi], S[xi+1]

    t1, t2 = T[yi], T[yi+1]

    print((min([

        max(q-s1,q-t1),

        max(s2-q, t2-q),

        2*(s2-q) + q-t1,

        2*(t2-q) + q-s1,

        2*(q-s1) + t2-q,

        2*(q-t1) + s2-q,

        ])))

#    print(q, s1, s2, t1, t2)



#    print(S[xi], T[yi])

x = []
for i, j in enumerate(map(int, input().split())):
    c = []
    for l in range(j):
        t = int(eval(input()))
        x.append((i, l, t))
        c.append([t])
x.sort(key=lambda x: x[2])
l = [-(10**20)] * 2
for y in x:
    if y[0] != 2:
        l[y[0]] = y[2]
    else:
        c[y[1]] += l[:]
l = [10**20] * 2
for y in x[::-1]:
    if y[0] != 2:
        l[y[0]] = y[2]
    else:
        c[y[1]] += l[:]
print(
    (
        "\n".join(
            str(
                min(
                    d[0] - min(d[1], d[2]),
                    max(d[3], d[4]) - d[0],
                    d[4] - d[1] + min(d[0] - d[1], d[4] - d[0]),
                    d[3] - d[2] + min(d[0] - d[2], d[3] - d[0]),
                )
            )
            for d in c
        )
    )
)

import sys

input = sys.stdin.readline
A, B, Q = list(map(int, input().split()))
inf = 10**18
S = [-inf]
for _ in range(A):
    S.append(int(eval(input())))
S.append(inf)
T = [-inf]
for _ in range(B):
    T.append(int(eval(input())))
T.append(inf)


def f_s(x, l):
    mn, mx = -1, len(l)
    idx = mx // 2
    while mx - mn > 1:
        if l[idx] < x:
            idx, mn = (idx + mx) // 2, idx
            continue
        idx, mx = (idx + mn) // 2, idx
    return idx


for _ in range(Q):
    q = int(eval(input()))
    xi, yi = f_s(q, S), f_s(q, T)
    s1, s2 = S[xi], S[xi + 1]
    t1, t2 = T[yi], T[yi + 1]
    print(
        (
            min(
                [
                    max(q - s1, q - t1),
                    max(s2 - q, t2 - q),
                    2 * (s2 - q) + q - t1,
                    2 * (t2 - q) + q - s1,
                    2 * (q - s1) + t2 - q,
                    2 * (q - t1) + s2 - q,
                ]
            )
        )
    )
#    print(q, s1, s2, t1, t2)
#    print(S[xi], T[yi])

-x = [] -for i, j in enumerate(map(int, input().split())): -    c = [] -    for l in range(j): -        t = int(eval(input())) -        x.append((i, l, t)) -        c.append([t]) -x.sort(key=lambda x: x[2]) -l = [-(10**20)] * 2 -for y in x: -    if y[0] != 2: -        l[y[0]] = y[2] -    else: -        c[y[1]] += l[:] -l = [10**20] * 2 -for y in x[::-1]: -    if y[0] != 2: -        l[y[0]] = y[2] -    else: -        c[y[1]] += l[:] -print( -    ( -        "\n".join( -            str( -                min( -                    d[0] - min(d[1], d[2]), -                    max(d[3], d[4]) - d[0], -                    d[4] - d[1] + min(d[0] - d[1], d[4] - d[0]), -                    d[3] - d[2] + min(d[0] - d[2], d[3] - d[0]), -                ) +import sys + +input = sys.stdin.readline +A, B, Q = list(map(int, input().split())) +inf = 10**18 +S = [-inf] +for _ in range(A): +    S.append(int(eval(input()))) +S.append(inf) +T = [-inf] +for _ in range(B): +    T.append(int(eval(input()))) +T.append(inf) + + +def f_s(x, l): +    mn, mx = -1, len(l) +    idx = mx // 2 +    while mx - mn > 1: +        if l[idx] < x: +            idx, mn = (idx + mx) // 2, idx +            continue +        idx, mx = (idx + mn) // 2, idx +    return idx + + +for _ in range(Q): +    q = int(eval(input())) +    xi, yi = f_s(q, S), f_s(q, T) +    s1, s2 = S[xi], S[xi + 1] +    t1, t2 = T[yi], T[yi + 1] +    print( +        ( +            min( +                [ +                    max(q - s1, q - t1), +                    max(s2 - q, t2 - q), +                    2 * (s2 - q) + q - t1, +                    2 * (t2 - q) + q - s1, +                    2 * (q - s1) + t2 - q, +                    2 * (q - t1) + s2 - q, +                ] -            for d in c -) +#    print(q, s1, s2, t1, t2) +#    print(S[xi], T[yi])