program main
  implicit none

  integer :: ak, bk, mk
  integer, allocatable :: a(:), b(:), m(:,:), total(:)
  integer :: i, j

  read (*,*) ak, bk, mk

  allocate(a(ak))
  allocate(b(bk))
  allocate(m(3,mk))

  read(*,*) a
  read(*,*) b
  read(*,*) m

  if(mk <= bk .and. mk <= ak) then
     allocate(total(mk))
     do i = 1, mk
        total(i) = a(m(1,i)) + b(m(2,i)) - m(3,i)
        write(*,*) minval(total)

        deallocate(total)
    end do

 else
    if(ak >= bk) then
       allocate(total(bk))
       do i = 1, bk
          total(i) = a(m(1,i)) + b(m(2,i)) - m(3,i)
          write(*,*) minval(total)
          deallocate(total)
       end do

    else
       do i = 1, ak
          allocate(total(ak))
          total(i) = a(m(1,i)) + b(m(2,i)) - m(3,i)
          write(*,*) minval(total)

          deallocate(total)
       end do

    end if

 end if
 deallocate(a,b,m)
 stop
 
end program main

