### main

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

  rows = []
  cols = []

  orders = q.times.map{gets.split.map(&:to_i)}

  count = 0

  while ! orders.empty?
    ai, bi, oi = orders.pop

    if ai != 0
      if rows[bi].nil?
        rows[bi] = true
        count += r if oi != 0
        c -= 1
      end
    else
      if cols[bi].nil?
        cols[bi] = true
        count += c if oi != 0
        r -= 1
      end
    end
  end

  puts count
end