#include <bits/stdc++.h>
using namespace std;
const long long mxN = 1e6 + 6, md = 998244353;
long long R[mxN][2], C[mxN][2], G[2], P[mxN];
;
long long N, M;
long long A, B;
map<pair<long long, long long>, long long> mp;
pair<long long, long long> empty(long long x, long long y) {
  bool f1 = (!R[x][0] && !R[x][1]);
  bool f2 = (!C[y][0] && !C[y][1]);
  return {f1, f2};
}
pair<long long, long long> conflict(long long x, long long y) {
  bool f1 = (R[x][0] && R[x][1]);
  bool f2 = (C[y][0] && C[y][1]);
  return {f1, f2};
}
long long chess() {
  bool f1 = (G[0] && G[1]);
  bool f2 = (G[0] || G[1]);
  return (f1 ? 0 : (f2 ? 1 : 2));
}
void clear(long long x, long long y) {
  if (mp.count({x, y})) {
    long long z = mp[{x, y}];
    mp.erase(mp.find({x, y}));
    auto [f1, f2] = conflict(x, y);
    R[x][(x + y + z) & 1]--;
    C[y][(x + y + z) & 1]--;
    G[(x + y + z) & 1]--;
    auto [f3, f4] = conflict(x, y);
    auto [a, b] = empty(x, y);
    N += a, M += b;
    A += f3 - f1, B += f4 - f2;
  }
}
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  P[0] = 1;
  for (long long i = 1; i < mxN; i++) P[i] = 2 * P[i - 1] % md;
  long long n, m, k;
  cin >> n >> m >> k;
  N = n, M = m;
  while (k--) {
    long long x, y, t;
    cin >> x >> y >> t;
    clear(x, y);
    if (t != -1) {
      auto [a, b] = empty(x, y);
      N -= a, M -= b;
      auto [f1, f2] = conflict(x, y);
      R[x][(x + y + t) & 1]++;
      C[y][(x + y + t) & 1]++;
      G[(x + y + t) & 1]++;
      mp[{x, y}] = t;
      auto [f3, f4] = conflict(x, y);
      A += f3 - f1, B += f4 - f2;
    }
    long long ans = P[M] * (!B) + P[N] * (!A) - chess();
    cout << (ans % md + md) % md << '\n';
  }
}
