### main

loop do
  r, c, q = gets.split.map(&:to_i)
  break if (r | c | q) == 0

  rows = r.times.map{[0, false]}
  cols = c.times.map{[0, false]}

  for k in (1..q)
    ai, bi, oi = gets.split.map(&:to_i)

    tf = (oi == 1)

    if ai == 0
      rows[bi] = [k, tf]
    else
      cols[bi] = [k, tf]
    end
  end

  count = 0
  for i in (0...r)
    ri = rows[i]
    for j in (0...c)
      cj = cols[j]
      tf = (ri[0] >= cj[0]) ? ri[1] : cj[1]
      count += 1 if tf
    end
  end

  puts count
end