#include <stdio.h>
#include <string.h>

#define SEGTREE_MAX 65536

#define INTERNAL_SEGTREE_MAX (SEGTREE_MAX*2-1)

typedef struct {
	short stand;
	short sit;
} segtree_t;

segtree_t segtree[INTERNAL_SEGTREE_MAX];

void segtree_init(void) {
	memset(segtree,0,sizeof(segtree));
}

/* internal */
void segtree_update(int youso) {
	int min;
	min=0x7fff;
	if(segtree[youso*2+1].stand<min)min=segtree[youso*2+1].stand;
	if(segtree[youso*2+2].stand<min)min=segtree[youso*2+2].stand;
	segtree[youso].stand=min;

	min=0x7fff;
	if(segtree[youso*2+1].sit<min)min=segtree[youso*2+1].sit;
	if(segtree[youso*2+2].sit<min)min=segtree[youso*2+2].sit;
	segtree[youso].sit=min;

	if(youso>0)segtree_update((youso-1)/2);
}

/* internal */
int segtree_getnum_internal(
		int youso,int target,int start,int end,int isstand,
		int kstart,int kend) {
	if(youso>=INTERNAL_SEGTREE_MAX)return 0;
	if(end<=kstart || kend<=start)return 0;
	else if(start<=kstart && kend<=end) {
		if((isstand?segtree[youso].stand:segtree[youso].sit)>target) {
			return kend-kstart;
		} else {
			return
				segtree_getnum_internal(youso*2+1,
					target,start,end,isstand,
					kstart,kstart+(kend-kstart)/2)+
				segtree_getnum_internal(youso*2+2,
					target,start,end,isstand,
					kstart+(kend-kstart)/2,kend);
		}
	} else {
		return
			segtree_getnum_internal(youso*2+1,
				target,start,end,isstand,
				kstart,kstart+(kend-kstart)/2)+
			segtree_getnum_internal(youso*2+2,
				target,start,end,isstand,
				kstart+(kend-kstart)/2,kend);
	}
}

void segtree_set(int youso,int zikan,int isstand) {
	int youso2=youso+SEGTREE_MAX-1;
	if(isstand) {
		segtree[youso2].stand=zikan;
		segtree[youso2].sit=0;
	} else {
		segtree[youso2].sit=zikan;
		segtree[youso2].stand=0;
	}
	segtree_update((youso2-1)/2);
}

/* [start,end)ツづargetツづヲツづィツ妥・ツつォツつ「ツ要ツ素ツづ個青板づーツ仰づ淞づゥ */
int segtree_getnum(int target,int start,int end,int isstand) {
	return segtree_getnum_internal(0,target,start,end,isstand,
		0,SEGTREE_MAX);
}

int width,height;
segtree_t gyou_data[50000];

int main(void) {
	int query_num,i;
	int q_isretu,q_id,q_order;
	int result;
	while(1) {
		scanf("%d%d%d",&height,&width,&query_num);
		if(height==0 && width==0 && query_num==0)break;
		segtree_init();
		memset(gyou_data,0,sizeof(gyou_data));
		for(i=1;i<=query_num;i++) {
			scanf("%d%d%d",&q_isretu,&q_id,&q_order);
			if(q_isretu) {
				segtree_set(q_id,i,q_order);
			} else {
				if(q_order)gyou_data[q_id].stand=i;
				else gyou_data[q_id].sit=i;
			}
		}
		result=0;
		for(i=0;i<height;i++) {
			if(gyou_data[i].stand>gyou_data[i].sit) {
				result+=width-segtree_getnum(gyou_data[i].stand,
					0,width,0);
			} else {
				result+=segtree_getnum(gyou_data[i].sit,
					0,width,1);
			}
		}
		printf("%d\n",result);
	}
	return 0;
}