#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-10, pi = acos(-1);
const int N = 2e6 + 10, M = 1e6 + 10, ha = 131, INF = 0x3f3f3f3f,
          mod = 998244353;
int m, n, k;
int a[N][2];
int b[N][2];
int f1, f2;
int xx, yy;
map<pair<int, int>, int> mp;
long long s[N];
int flag[2];
void add(int x, int y, int p) {
  flag[x + y + p & 1]++;
  if (a[x][0] + a[x][1] == 0) xx++;
  if (b[y][0] + b[y][1] == 0) yy++;
  if (a[x][y + p & 1] == 0 && a[x][y + p + 1 & 1]) f1++;
  a[x][y + p & 1]++;
  if (b[y][x + p & 1] == 0 && b[y][x + p + 1 & 1]) f2++;
  b[y][x + p & 1]++;
}
void del(int x, int y, int p) {
  flag[x + y + p & 1]--;
  if (a[x][0] + a[x][1] == 1) xx--;
  if (b[y][0] + b[y][1] == 1) yy--;
  if (a[x][y + p & 1] == 1 && a[x][y + p + 1 & 1]) f1--;
  a[x][y + p & 1]--;
  if (b[y][x + p & 1] == 1 && b[y][x + p + 1 & 1]) f2--;
  b[y][x + p & 1]--;
}
long long ans;
void cal() {
  if (f1 && f2) {
    ans = 0;
    return;
  }
  if (f1) {
    ans = s[m - yy];
  } else if (f2) {
    ans = s[n - xx];
  } else {
    ans = (s[n - xx] + s[m - yy] - 2) % mod + mod;
    if (flag[1] && flag[0])
      ans += 2;
    else if (flag[1] || flag[0])
      ans++;
    ans = (ans + mod) % mod;
  }
}
void solve() {
  s[0] = 1;
  for (int i = 1; i < N; i++) s[i] = s[i - 1] * 2 % mod;
  scanf("%d%d%d", &n, &m, &k);
  int x, y, op;
  while (k--) {
    scanf("%d%d%d", &x, &y, &op);
    if (mp.count(pair<int, int>(x, y)) && mp[pair<int, int>(x, y)] >= 0)
      del(x, y, mp[pair<int, int>(x, y)]);
    if (op >= 0) add(x, y, op);
    mp[pair<int, int>(x, y)] = op;
    cal();
    printf("%lld\n", ans % mod);
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
