PROGRAM ATCODER

implicit none
integer(16) :: a,b,q,s_ans(2),t_ans(2),i,cs,ct,m,j,ans(8),k
integer(16),allocatable :: s(:),t(:),x(:)

read*, a,b,q
allocate(s(a),t(b),x(q))
read*, s(1:a),t(1:b),x(1:q)

do i = 1, q, 1
  cs = bin_s(x(i),s,a)
  ct = bin_s(x(i),t,b)
  if ( cs == 1 .and. s(cs) >= x(i) ) then
    s_ans(1) = s(cs)
    s_ans(2) = s(cs)
  else if ( cs == a .and. s(cs) <= x(i) ) then
    s_ans(1) = s(cs)
    s_ans(2) = s(cs)
  else
    s_ans(1) = s(cs-1)
    s_ans(2) = s(cs)
  end if
  if ( ct == 1 .and. t(ct) >= x(i) ) then
    t_ans(1) = t(ct)
    t_ans(2) = t(ct)
  else if ( ct == b .and. t(ct) <= x(i) ) then
    t_ans(1) = t(ct)
    t_ans(2) = t(ct)
  else
    t_ans(1) = t(ct-1)
    t_ans(2) = t(ct)
  end if
  k = 1
  do m = 1, 2, 1
    do j = 1, 2, 1
      ans(k) = abs(x(i)-t_ans(m)) + abs(t_ans(m)-s_ans(j))
      k = k + 1
    end do
  end do
  do m = 1, 2, 1
    do j = 1, 2, 1
      ans(k) = abs(x(i)-s_ans(m)) + abs(s_ans(m)-t_ans(j))
      k = k + 1
    end do
  end do
  print'(i0)', minval(ans)
end do

contains
!!!!!! サブルーチンは↓
  logical function isOK(index,key,a,n) !indexが条件を満たすかどうか
    implicit none
    integer(16),intent(in) :: index,key,n
    integer(16),intent(in) :: a(n)
    if ( a(index) >= key ) then !a(index)がkey以下になる最小のindex
      isOK = .true.
    else
      isOK = .false.
    end if
  end function isOK

  integer function bin_s(key,a,n)
    implicit none
    integer(16),intent(in) :: key,n
    integer(16),intent(in) :: a(n)
    integer(16) :: ng,ok,mid
    ng = 0 ; ok = n + 1 !初期値の設定は問題によって違う
    !!!!!!while文はどんな場合でも変更しない
    do while ( abs(ok-ng) > 1 )
      mid = (ok+ng)/2
      if ( isOK(mid,key,a,n) ) then
        ok = mid
      else
        ng = mid
      end if
    end do
    bin_s = ok
    if ( bin_s > n ) then
      bin_s = n
    end if
  end function bin_s
!!!!!!

END PROGRAM ATCODER