#include <cstdio>
#include <cstring>
using namespace std;

typedef long long int64;

const int MAX_W = 50000;
const int MAX_Q = 50000;

int H, W, Q;
int ts[MAX_Q], as[MAX_Q], cmd[MAX_Q];
bool visited[2][MAX_W];

bool init(){
	scanf("%d%d%d", &H, &W, &Q);
	for(int i=0; i<Q; i++){
		scanf("%d%d%d", ts+i, as+i, cmd+i);
	}
	memset(visited, false, sizeof(visited));
	return H>0;
}

int64 solve(){
	int64 ret = 0;
	int64 count[2];
	count[0] = count[1] = 0;
	for(int i=Q-1; i>=0; i--){
		int t = ts[i], x = as[i];
		if(visited[t][x]){
			continue;
		}
		visited[t][x] = true;
		count[t]++;
		if(cmd[i] == 1){
			ret += (t == 0 ? W : H) - count[1 - t];
		}
	}

	return ret;
}

int main(){
	while(init()){
		printf("%lld\n", solve());
	}

	return 0;
}