#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;
struct data{ int A, B, O;};
const int MAX = 50001;
const int Row = 0;
const int Col = 1;

bool fin[2][MAX];
int r,c,q;

int main(){
  
  while(cin >> r >> c >> q && r+c+q){
    memset(fin,false,sizeof(fin));
    
    vector<data> V(q);
    
    for(int i = 0; i < q; i++) cin >> V[i].A >> V[i].B >> V[i].O;
    
    int delR = 0, delC = 0;
    long long ans = 0;
    
    for(int i = V.size()-1; i >= 0; i--){

      if(V[i].A){
	// column
	if(fin[Col][V[i].B]) continue;

	if(V[i].O) ans += r-delC;
	  fin[Col][V[i].B] = true;
	  delR++;
	
      }else{
	// row
	if(fin[Row][V[i].B]) continue;

	if(V[i].O)  ans += c-delR;
	  fin[Row][V[i].B] = true;
	  delC++;
      }
    }
    
    cout << ans << endl;
  }
  return 0;
}