program main
  implicit none
  integer :: A,B,Q
  integer(8),allocatable :: S(:)
  integer(8),allocatable :: T(:)
  integer(8) :: xtmp
  integer(8) :: xtmp_loc(1)
  integer(8) :: cand(2)
  integer(8),allocatable :: x(:)
  integer :: i
  
  read(*,*) A,B,Q
  allocate(S(A),T(B),x(Q))
  do i = 1,A
     read(*,*) S(i)
  end do
  do i = 1,B
     read(*,*) T(i)
  end do
  do i = 1,Q
     read(*,*) X(i)
  end do

  do i = 1,Q
     ! first visit T
     cand(1)=0
     xtmp=X(i)
     cand(1) = cand(1) + minval( abs(T(:)-xtmp))
     xtmp_loc = T( minloc( abs(T(:)-xtmp)) )
     xtmp = xtmp_loc(1)
     cand(1) = cand(1) + minval( abs(S(:)-xtmp))

     ! first visit S
     cand(2)=0
     xtmp=X(i)
     cand(2) = cand(2) + minval( abs(S(:)-xtmp))
     xtmp_loc = S( minloc( abs(S(:)-xtmp)) )
     xtmp = xtmp_loc(1)
     cand(2) = cand(2) + minval( abs(T(:)-xtmp))
     write(*,'(i0)') minval(cand)
  end do
     
  stop
end program main
