Buggy python submission (verdict: Time Limit Exceeded):
import bisect
A, B, Q = map(int,input().split())
s = [-10**20] + [int(input()) for k in range(A)] + [10**20,10**20]
t = [-10**20] + [int(input()) for k in range(B)] + [10**20,10**20]

for _ in range(Q):
    x = int(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]))


Fixed submission:
import bisect
A, B, Q = map(int,input().split())
S = [-float("inf")] + sorted([int(input()) for k in range(A)]) + [float("inf")]
T = [-float("inf")] + sorted([int(input()) for k in range(B)]) + [float("inf")]
X = [int(input()) for k in range(Q)]

for x in X:
    p = bisect.bisect_left(S,x)
    q = bisect.bisect_left(T,x)
    t1 = max(abs(S[p]-x),abs(T[q]-x))
    t2 = max(abs(S[p-1]-x),abs(T[q-1]-x))
    t3 = abs(S[p-1]-x)+abs(S[p-1]-T[q])
    t4 = abs(T[q-1]-x)+abs(S[p]-T[q-1])    
    t5 = abs(S[p]-x)+abs(S[p]-T[q-1])    
    t6 = abs(T[q]-x)+abs(S[p-1]-T[q])
    print(min(t1,t2,t3,t4,t5,t6))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
A, B, Q = map(int,input().split())
s = [-10**20] + [int(input()) for k in range(A)] + [10**20,10**20]
t = [-10**20] + [int(input()) for k in range(B)] + [10**20,10**20]

for _ in range(Q):
    x = int(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]))


Fixed submission:
import bisect
A, B, Q = map(int,input().split())
S = [-float("inf")] + sorted([int(input()) for k in range(A)]) + [float("inf")]
T = [-float("inf")] + sorted([int(input()) for k in range(B)]) + [float("inf")]
X = [int(input()) for k in range(Q)]

for x in X:
    p = bisect.bisect_left(S,x)
    q = bisect.bisect_left(T,x)
    t1 = max(abs(S[p]-x),abs(T[q]-x))
    t2 = max(abs(S[p-1]-x),abs(T[q-1]-x))
    t3 = abs(S[p-1]-x)+abs(S[p-1]-T[q])
    t4 = abs(T[q-1]-x)+abs(S[p]-T[q-1])    
    t5 = abs(S[p]-x)+abs(S[p]-T[q-1])    
    t6 = abs(T[q]-x)+abs(S[p-1]-T[q])
    print(min(t1,t2,t3,t4,t5,t6))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
A, B, Q = map(int,input().split())
S = [-float("inf")] + sorted([int(input()) for k in range(A)]) + [float("inf")]
T = [-float("inf")] + sorted([int(input()) for k in range(B)]) + [float("inf")]
X = [int(input()) for k in range(Q)]

for x in X:
    p = bisect.bisect_left(S,x)
    q = bisect.bisect_left(T,x)
    t1 = max(abs(S[p]-x),abs(T[q]-x))
    t2 = max(abs(S[p-1]-x),abs(T[q-1]-x))
    t3 = abs(S[p-1]-x)+abs(S[p-1]-T[q])
    t4 = abs(T[q-1]-x)+abs(S[p]-T[q-1])    
    t5 = abs(S[p]-x)+abs(S[p]-T[q-1])    
    t6 = abs(T[q]-x)+abs(S[p-1]-T[q])
    print(min(t1,t2,t3,t4,t5,t6))

Fixed submission:
import bisect
A, B, Q = map(int,input().split())
S = [-float("inf")] + sorted([int(input()) for k in range(A)]) + [float("inf")]
T = [-float("inf")] + sorted([int(input()) for k in range(B)]) + [float("inf")]
X = [int(input()) for k in range(Q)]

for x in X:
    p = bisect.bisect_left(S,x)
    q = bisect.bisect_left(T,x)
    t1 = max(abs(S[p]-x),abs(T[q]-x))
    t2 = max(abs(S[p-1]-x),abs(T[q-1]-x))
    t3 = abs(S[p-1]-x)+abs(S[p-1]-T[q])
    t4 = abs(T[q-1]-x)+abs(S[p]-T[q-1])    
    t5 = abs(S[p]-x)+abs(S[p]-T[q-1])    
    t6 = abs(T[q]-x)+abs(S[p-1]-T[q])
    print(min(t1,t2,t3,t4,t5,t6))