#include <cstdio>
#include <algorithm>
using namespace std;
int H, W, Q, a[50009], b[50009], x[50009]; bool used1[50009], used2[50009];
int main() {
	while (scanf("%d%d%d", &H, &W, &Q), H) {
		for (int i = 0; i < Q; i++) scanf("%d%d%d", &a[i], &b[i], &x[i]);
		fill(used1, used1 + H, false);
		fill(used2, used2 + W, false);
		int cnt1 = H, cnt2 = W;
		long long ret = 0;
		while (Q--) {
			if (a[Q] == 0 && !used1[b[Q]]) {
				used1[b[Q]] = true; cnt1--;
				if (x[Q] == 1) ret += cnt2;
			}
			if (a[Q] == 1 && !used2[b[Q]]) {
				used2[b[Q]] = true; cnt2--;
				if (x[Q] == 1) ret += cnt1;
			}
		}
		printf("%lld\n", ret);
	}
	return 0;
}