program lazy_faith
  implicit none
  integer(8)              :: a, b, q, x, i, k
  integer(8), allocatable :: s(:), t(:)
  read(*,*) a, b, q
  allocate(s(a+2_8),t(b+2_8))
  s(1_8) = 0
  do i = 2_8, a+1_8
    read(*,*) s(i)
  end do
  s(a+2_8) = 10_8**12_8
  t(1_8) = 0_8
  do i = 2_8, b+1_8
    read(*,*) t(i)
  end do
  t(b+2_8) = 10_8**12_8
  call merge_sort(a+2_8,s)
  call merge_sort(b+2_8,t)
  do k = 1_8, q
    read(*,*) x
    call answer(a+2_8,s,b+2_8,t,x)
  end do
  deallocate(s,t)
  stop
contains
  subroutine answer(a,s,b,t,x)
    implicit none
    integer(8), intent(in) :: a, s(a), b, t(b), x
    integer(8)             :: i, j, m(4_8)
    i = bisection(x,s)
    j = bisection(x,t)
    m(1) = min(abs(s(i    )-x),abs(t(j    )-x)) + abs(s(i    )-t(j    ))
    m(2) = min(abs(s(i    )-x),abs(t(j+1_8)-x)) + abs(s(i    )-t(j+1_8))
    m(3) = min(abs(s(i+1_8)-x),abs(t(j    )-x)) + abs(s(i+1_8)-t(j    ))
    m(4) = min(abs(s(i+1_8)-x),abs(t(j+1_8)-x)) + abs(s(i+1_8)-t(j+1_8))
    write(*,'(i0)') minval(m)
    return
  end subroutine answer

  !min{i | x < y(i)}
  function bisection(x,y) result(idx)
    implicit none
    integer(8), intent(in) :: x, y(:)
    integer(8)             :: idx, top, mid, btm
    idx = -1_8
    if (x .lt. minval(y)) then
      idx = 0_8
      return
    end if
    if (x .gt. maxval(y)) then
      idx = size(y)+1_8
      return
    end if
    top = size(y)
    btm = 1_8
    do
      mid = (top + btm) / 2_8
      if (x .lt. y(mid)) then
        top = mid
      else
        btm = mid
      end if
      if (top .eq. btm+1_8) exit
    end do
    idx = mid
    return
  end function bisection

  subroutine merge_sort(n,c)
    implicit none
    integer(8), intent(in)    :: n
    integer(8), intent(inout) :: c(n)
    integer(8)                :: number, length, i, ubound
    number = n
    length = 1_8
    do while (number .gt. 1_8)
       do i = 1_8, number/2_8
          ubound = min(2_8*i*length,n)
          call merge(c(2_8*(i-1_8)*length+1_8:(2_8*i-1_8)*length),c((2_8*i-1_8)*length+1_8:ubound))
       end do
       length = 2_8*length
       number = (number+1_8)/2_8
    end do
    return
  end subroutine merge_sort

  subroutine merge(c1,c2)
    implicit none
    integer(8), intent(inout) :: c1(:), c2(:)
    integer(8)                :: c(size(c1)+size(c2))
    integer(8)                :: i1, i2, n1, n2
    i1 = 1_8
    i2 = 1_8
    n1 = size(c1)
    n2 = size(c2)
    do while (i1 .le. n1 .and. i2 .le. n2)
       if (c1(i1) .le. c2(i2)) then
          c(i1+i2-1_8) = c1(i1)
          i1 = i1+1_8
       else
          c(i1+i2-1_8) = c2(i2)
          i2 = i2+1_8
       end if
    end do
    if (i1 .le. n1) then
       c(i1+i2-1_8:n1+n2) = c1(i1:n1)
    else if (i2 .le. n2) then
       c(i1+i2-1_8:n1+n2) = c2(i2:n2)
    end if
    c1 = c(1_8:n1)
    c2 = c(n1+1_8:n1+n2)
    return
  end subroutine merge
end program lazy_faith