#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, m, k, x, y, z, fl[2], val[1000001];
map<int, int> mp[1000001], ban[1000001];
int add(int a, int b) {
  if (a + b >= mod) return a + b - mod;
  return a + b;
}
int del(int a, int b) {
  if (a - b < 0) return a - b + mod;
  return a - b;
}
struct node {
  int p[1000001][2], cnt[3];
  void clean(int a, int c) {
    cnt[(p[a][0] == 0) + (p[a][1] == 0)]--;
    p[a][c]--;
    cnt[(p[a][0] == 0) + (p[a][1] == 0)]++;
  }
  void ins(int a, int c) {
    cnt[(p[a][0] == 0) + (p[a][1] == 0)]--;
    p[a][c]++;
    cnt[(p[a][0] == 0) + (p[a][1] == 0)]++;
  }
  int find() {
    if (cnt[0]) return 0;
    return val[cnt[2]];
  }
} t1, t2;
int main() {
  val[0] = 1;
  for (int i = 1; i <= 1000000; i++) val[i] = add(val[i - 1], val[i - 1]);
  scanf("%d%d%d", &n, &m, &k);
  t1.cnt[2] = n;
  t2.cnt[2] = m;
  for (int i = 1; i <= k; i++) {
    scanf("%d%d%d", &x, &y, &z);
    if (ban[x][y]) {
      fl[(x & 1) ^ (y & 1) ^ (mp[x][y] & 1)]--;
      t1.clean(x, mp[x][y] ^ (y & 1));
      t2.clean(y, mp[x][y] ^ (x & 1));
      ban[x][y] = 0;
    }
    if (z >= 0) {
      ban[x][y] = 1;
      fl[(x & 1) ^ (y & 1) ^ (z & 1)]++;
      t1.ins(x, z ^ (y & 1));
      t2.ins(y, z ^ (x & 1));
      mp[x][y] = z;
    }
    printf("%d\n", del(add(t1.find(), t2.find()),
                       add(((int)(fl[0] == 0)), ((int)(fl[1] == 0)))));
  }
}
