Buggy python submission (verdict: Time Limit Exceeded):
A, B, Q = map(int, input().split())

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

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

#print(S)
#print(T)
#print()

#for x in X:
for _ in range(Q):
	x = int(input())
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	#print(sr, sl, tr, tl)
	#print(S[sr], S[sl], T[tr], T[tl])
	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(sr, sl, tr, tl, cost)
	print(min(cost))
	#break


Fixed submission:
import bisect
A, B, Q = map(int, input().split())

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

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

def bsr(a, v):
	return bisect.bisect_right(a, v)

#print(S)
#print(T)
#print()

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	#print(sr, sl, tr, tl)
	#print(S[sr], S[sl], T[tr], T[tl])
	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(sr, sl, tr, tl, cost)
	print(min(cost))
	#break

Buggy python submission (verdict: Time Limit Exceeded):
A, B, Q = map(int, input().split())

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

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

#print(S)
#print(T)
#print()

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	#print(sr, sl, tr, tl)
	#print(S[sr], S[sl], T[tr], T[tl])
	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(sr, sl, tr, tl, cost)
	print(min(cost))
	#break


Fixed submission:
import bisect
A, B, Q = map(int, input().split())

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

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

def bsr(a, v):
	return bisect.bisect_right(a, v)

#print(S)
#print(T)
#print()

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	#print(sr, sl, tr, tl)
	#print(S[sr], S[sl], T[tr], T[tl])
	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(sr, sl, tr, tl, cost)
	print(min(cost))
	#break

Buggy python submission (verdict: Runtime Error):
#import math
A, B, Q = map(int, input().split())

#inf = math.inf
inf = 2 **31 - 1

S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]
X = [int(input()) for _ in range(Q)]

def bsearch_sub(a, v, imin, imax):
	if imax < imin:
		return imax + 1
	else:
		imid = imin + (imax - imin) // 2
		if v < a[imid]:
			return bsearch_sub(a, v, imin, imid - 1)
		elif a[imid] <= v:
			return bsearch_sub(a, v, imid + 1, imax)

def bsearch(a, v):
	return bsearch_sub(a, v, 0, len(a) - 1)

#print(S)
#print(T)
#print()

for x in X:
	s, t = bsearch(S, x), bsearch(T, x)
	#print(s, t, x)
	s1, s2, t1, t2 = S[s - 1], S[s], T[t - 1], T[t]
	r = []
	for sv in [s1, s2]:
		for tv in [t1, t2]:
			r += [abs(x - sv) + abs(sv - tv)]
			r += [abs(x - tv) + abs(sv - tv)]
	print(min(r))


Fixed submission:
import bisect
A, B, Q = map(int, input().split())

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

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

def bsr(a, v):
	return bisect.bisect_right(a, v)

#print(S)
#print(T)
#print()

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	#print(sr, sl, tr, tl)
	#print(S[sr], S[sl], T[tr], T[tl])
	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(sr, sl, tr, tl, cost)
	print(min(cost))
	#break

Buggy python submission (verdict: Runtime Error):
import math
A, B, Q = map(int, input().split())

inf = math.inf

S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]
X = [int(input()) for _ in range(Q)]

def bsearch_sub(a, v, imin, imax):
	if imax < imin:
		return imax + 1
	else:
		imid = imin + (imax - imin) // 2
		if v < a[imid]:
			return bsearch_sub(a, v, imin, imid - 1)
		elif a[imid] <= v:
			return bsearch_sub(a, v, imid + 1, imax)

def bsearch(a, v):
	return bsearch_sub(a, v, 0, len(a) - 1)

#print(S)
#print(T)
#print()

for x in X:
	s, t = bsearch(S, x), bsearch(T, x)
	#print(s, t, x)
	s1, s2, t1, t2 = S[s - 1], S[s], T[t - 1], T[t]
	r = []
	for sv in [s1, s2]:
		for tv in [t1, t2]:
			r += [abs(x - sv) + abs(sv - tv)]
			r += [abs(x - tv) + abs(sv - tv)]
	print(min(r))


Fixed submission:
import bisect
A, B, Q = map(int, input().split())

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

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

def bsr(a, v):
	return bisect.bisect_right(a, v)

#print(S)
#print(T)
#print()

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	#print(sr, sl, tr, tl)
	#print(S[sr], S[sl], T[tr], T[tl])
	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(sr, sl, tr, tl, cost)
	print(min(cost))
	#break

Buggy python submission (verdict: Time Limit Exceeded):
A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

def bsearch_sub(a, v, imin, imax):
	if imax < imin:
		return (imax, imin)
	else:
		imid = imin + (imax - imin) // 2
		if v < a[imid]:
			return bsearch_sub(a, v, imin, imid - 1)
		elif a[imid] < v:
			return bsearch_sub(a, v, imid + 1, imax)
		else:
			return (imid, imid)

def bsearch(a, v):
	return bsearch_sub(a, v, 0, len(a) - 1)

#print(S, T)
for x in X:
	s = bsearch(S, x)
	sb, sd = [], []
	if 0 <= s[0] < A:
		sb += [S[s[0]]]
		sd += [S[s[0]] - x]
	if 0 <= s[1] < A:
		sb += [S[s[1]]]
		sd += [S[s[1]] - x]

	t = bsearch(T, x)
	tb, td = [], []
	if 0 <= t[0] < B:
		tb += [T[t[0]]]
		td += [T[t[0]] - x]
	if 0 <= t[1] < B:
		tb += [T[t[1]]]
		td += [T[t[1]] - x]

	r = []
	for sn in sd:
		for tn in td:
			if sn < 0 and tn < 0:
				r += [max([-sn, -tn])]
			elif 0 < sn and 0 < tn:
				r += [max([sn, tn])]
			else:
				r += [min([abs(sn), abs(tn)]) * 2 + max([abs(sn), abs(tn)])]
	print(min(r))

	#print(x, s, sb, sd)
	#print(x, t, tb, td)
	#print(x, bsearch(S, x), sb, bsearch(T, x), tb)


Fixed submission:
import bisect
A, B, Q = map(int, input().split())

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

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

def bsr(a, v):
	return bisect.bisect_right(a, v)

#print(S)
#print(T)
#print()

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	#print(sr, sl, tr, tl)
	#print(S[sr], S[sl], T[tr], T[tl])
	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(sr, sl, tr, tl, cost)
	print(min(cost))
	#break