program answer
  implicit none

  integer :: A, B, M, x, y, i, nosum, sum
  integer, allocatable :: as(:),  bs(:), c(:,:), d(:), e(:), f(:)
  
  read(*,*) A, B, M
  allocate(as(A))
  allocate(bs(B))
  allocate(c(M,3))
  allocate(d(A))
  allocate(e(B))
  allocate(f(M))
  read(*,*) as
  read(*,*) bs
  read(*,*) c

  nosum=minval(as)+minval(bs)

  do i = 1,M
     f(i)=as(c(1,i))+bs(c(2,i))-c(3,i)
  end do
  
  if(min(A,B)<=M) then
     if (min(A,B)==A) then
      do i = 1,A
        d(i)=f(i)
      end do
        sum=minval(d)
     else 
        do i = 1, B
        e(i)=f(i)
        end do
     sum=minval(e)
     end if
  else
     sum =minval(f)
  end if
  
  if (nosum<=sum) then
     sum = nosum
  end if

  write(*,*) sum

  deallocate (as)
  deallocate (bs)
  deallocate (c)
  deallocate (d)
  deallocate (e)

  stop
 end program answer
