program abc119d
  implicit none
  integer a, b, q, i, si, ti
  integer(8) s_west, s_east, t_west, t_east, d(4)
  integer(8), dimension(:), allocatable :: s, t, x
  integer(8), parameter :: inf = 10_8**11

  read *, a, b, q
  allocate(s(a), t(b), x(q))
  read *, s, t, x
  s = [-inf, s, inf]
  t = [-inf, t, inf]
  do i = 1, q
     si = bsrch(s, x(i))
     ti = bsrch(t, x(i))
     s_west = x(i) - s(si - 1)
     s_east = s(si) - x(i)
     t_west = x(i) - t(ti - 1)
     t_east = t(ti) - x(i)
     d(1) = merge(s_west, t_west, s_west > t_west)
     d(2) = merge(s_east, t_east, s_east > t_east)
     d(3) = merge(s_west + t_east * 2, s_west * 2 + t_east, s_west > t_east)
     d(4) = merge(t_west + s_east * 2, t_west * 2 + s_east, t_west > s_east)
     print *, minval(d)
  end do
contains
  integer function bsrch(ary, v)
    integer(8), intent(in) :: ary(:), v
    integer low, mid, high

    low = lbound(ary, 1)
    high = ubound(ary, 1)

    do while (low < high)
       mid = low + (high - low) / 2
       if (ary(mid) < v) then
          low = mid + 1
       else
          high = mid
       end if
    end do
    bsrch = low
  end function bsrch
end program abc119d
