w, h, t = gets.chomp.split.map(&:to_i)
p = gets.to_i
arr, map = [], []
p.times{arr << gets.chomp.split.map(&:to_i)}
h.times{map << gets.chomp.split.map(&:to_i)}
sum = 0
arr.sort_by{|x, y, t| t}.each{|x, y, tm|
    break if tm > t
    sum += 1 if map[y][x] == 1
}
puts sum
