### main

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

  grids = r.times.map{[false] * c}

  q.times do
    ai, bi, oi = gets.split.map(&:to_i)

    tf = (oi == 1)

    if ai == 0
      for i in (0...c)
        grids[bi][i] = tf
      end
    else
      for i in (0...r)
        grids[i][bi] = tf
      end
    end
  end

  count = 0
  for y in (0...r)
    for x in (0...c)
      count += 1 if grids[y][x]
    end
  end

  puts count
end