#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int r, c, q;
        cin >> r >> c >> q;
        if(r == 0)
            return 0;

        vector<int> a(q), b(q), order(q);
        for(int i=0; i<q; ++i)
            cin >> a[i] >> b[i] >> order[i];

        vector<bool> rCheck(r, false);
        vector<bool> cCheck(c, false);

        int ret = 0;
        for(int i=q-1; i>=0; --i){
            if(a[i] == 0){
                if(rCheck[b[i]])
                    continue;
                rCheck[b[i]] = true;
                if(order[i] == 1)
                    ret += c;
                -- r;
            }else{
                if(cCheck[b[i]])
                    continue;
                cCheck[b[i]] = true;
                if(order[i] == 1)
                    ret += r;
                -- c;
            }
        }

        cout << ret << endl;
    }
}