#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define fr(i,c) for(__typeof (c.begin()) i=c.begin(); i!=c.end(); i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;

int h,w,q;
int a[50000],b[50000],o[50000];
bool row[50000],col[50000];
int main(){
  while(cin>>h>>w>>q,h){
    rep(i,q)cin>>a[q-i-1]>>b[q-i-1]>>o[q-i-1];
    memset(row,0,sizeof(row)); memset(col,0,sizeof(col));
    ll ans=0;
    int nrow=0, ncol=0;
    rep(i,q){
      if(a[i]==0){
        if(row[b[i]])continue;
        row[b[i]]=1; nrow++;
        if(o[i])ans+=w-ncol;
      }
      else{
        if(col[b[i]])continue;
        col[b[i]]=1; ncol++;
        if(o[i])ans+=h-nrow;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}