#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int r, c, q;
	
	while (scanf("%d %d %d", &r, &c, &q) && r){
		int row[50000], col[50000];
		vector<int> rIn, cIn;
		vector<int> rOut, cOut;
		int ans = 0;
		for (int i = 0; i < r; i++) row[i] = -99999;
		for (int i = 0; i < c; i++) col[i] = -99999;
		
		for (int i = 1; i <= q; i++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			if (a == 0) row[b] = c ? i : -i;
			else col[b] = c ? i : -i;
		}
		
		for (int i = 0; i < r; i++){
			if (row[i] != -99999){
				(row[i] > 0) ? (rIn.push_back(row[i])) : (rOut.push_back(-row[i]));
			}
		}
		
		for (int i = 0; i < c; i++){
			if (col[i] != -99999){
				(col[i] > 0) ? (cIn.push_back(col[i])) : (cOut.push_back(-col[i]));
			}
		}
		
		sort(rIn.begin(), rIn.end()); sort(rOut.begin(), rOut.end());
		sort(cIn.begin(), cIn.end()); sort(cOut.begin(), cOut.end());
		
		for (int i = 0; i < rIn.size(); i++){
			int minus = cOut.size() - (lower_bound(cOut.begin(), cOut.end(), rIn[i]) - cOut.begin());
			minus += cIn.size() - (lower_bound(cIn.begin(), cIn.end(), rIn[i]) - cIn.begin());
			ans += c - minus;
		}
		
		for (int i = 0; i < cIn.size(); i++){
			int minus = rOut.size() - (lower_bound(rOut.begin(), rOut.end(), cIn[i]) - rOut.begin());
			minus += rIn.size() - (lower_bound(rIn.begin(), rIn.end(), cIn[i]) - rIn.begin());
			ans += r - minus;
		}
		printf("%d\n", ans);
	}
	
	return (0);
}