#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int mo = 998244353;
inline int inc(int x, int y) {
  if ((x += y) >= mo) x -= mo;
  return x;
}
inline void Inc(int &x, int y) { x = inc(x, y); }
inline int dec(int x, int y) {
  if ((x -= y) < 0) x += mo;
  return x;
}
inline void Dec(int &x, int y) { x = dec(x, y); }
map<pair<int, int>, int> co;
int cnt[2], n, m, Q, pw[N];
struct Node {
  int cnt[2][N], fre, tot;
  inline void init(int x) {
    fre = x;
    tot = 0;
  }
  inline void ins(int x, int y, int c) {
    int t = (y & 1) ^ c;
    cnt[t][x]++;
    if (cnt[t][x] == 1 && !cnt[!t][x]) fre--;
    if (cnt[t][x] == 1 && cnt[!t][x]) tot++;
  }
  inline void era(int x, int y, int c) {
    int t = (y & 1) ^ c;
    cnt[t][x]--;
    if (!cnt[t][x] && !cnt[!t][x]) fre++;
    if (!cnt[t][x] && cnt[!t][x]) tot--;
  }
  inline int query() {
    if (tot) return 0;
    return pw[fre];
  }
} rnm, cnm;
inline void era(int x, int y) {
  if (co.find(make_pair(x, y)) == co.end()) return;
  cnt[(x + y + co[make_pair(x, y)]) & 1]--;
  rnm.era(x, y, co[make_pair(x, y)]);
  cnm.era(y, x, co[make_pair(x, y)]);
  co.erase(make_pair(x, y));
}
inline void ins(int x, int y, int c) {
  co[make_pair(x, y)] = c;
  rnm.ins(x, y, c);
  cnm.ins(y, x, c);
  cnt[(x + y + co[make_pair(x, y)]) & 1]++;
}
inline void solve() {
  scanf("%d %d %d", &n, &m, &Q);
  rnm.init(n);
  cnm.init(m);
  pw[0] = 1;
  for (int i = (1); i <= (max(n, m)); i++) pw[i] = inc(pw[i - 1], pw[i - 1]);
  for (int asd_a = (1); asd_a <= (Q); asd_a++) {
    int x, y, c;
    scanf("%d %d %d", &x, &y, &c);
    era(x, y);
    if (~c) ins(x, y, c);
    printf("%d\n", dec(inc(rnm.query(), cnm.query()), inc(!cnt[0], !cnt[1])));
  }
}
int main() { solve(); }
