#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
struct modint {
  int x;
  modint(int o = 0) { x = o; }
  modint &operator=(int o) { return x = o, *this; }
  modint &operator+=(modint o) {
    return x = x + o.x >= 998244353 ? x + o.x - 998244353 : x + o.x, *this;
  }
  modint &operator-=(modint o) {
    return x = x - o.x < 0 ? x - o.x + 998244353 : x - o.x, *this;
  }
  modint &operator*=(modint o) { return x = 1ll * x * o.x % 998244353, *this; }
  modint &operator^=(int b) {
    modint a = *this, c = 1;
    for (; b; b >>= 1, a *= a)
      if (b & 1) c *= a;
    return x = c.x, *this;
  }
  modint &operator/=(modint o) { return *this *= o ^= 998244353 - 2; }
  modint &operator+=(int o) {
    return x = x + o >= 998244353 ? x + o - 998244353 : x + o, *this;
  }
  modint &operator-=(int o) {
    return x = x - o < 0 ? x - o + 998244353 : x - o, *this;
  }
  modint &operator*=(int o) { return x = 1ll * x * o % 998244353, *this; }
  modint &operator/=(int o) { return *this *= ((modint(o)) ^= 998244353 - 2); }
  template <class I>
  friend modint operator+(modint a, I b) {
    return a += b;
  }
  template <class I>
  friend modint operator-(modint a, I b) {
    return a -= b;
  }
  template <class I>
  friend modint operator*(modint a, I b) {
    return a *= b;
  }
  template <class I>
  friend modint operator/(modint a, I b) {
    return a /= b;
  }
  friend modint operator^(modint a, int b) { return a ^= b; }
  friend bool operator==(modint a, int b) { return a.x == b; }
  friend bool operator!=(modint a, int b) { return a.x != b; }
  bool operator!() { return !x; }
  modint operator-() { return x ? 998244353 - x : 0; }
};
const modint inv2 = ((998244353 + 1) / 2);
struct SegmentTree_AKIOI {
  unordered_map<int, int> mp[1000005];
  int c[1000005][2], cnt0;
  modint res;
  void del(int x, int y) {
    if (!mp[x].count(y)) return;
    cnt0 -= (c[x][0] > 0 && c[x][1] > 0);
    c[x][mp[x][y]]--;
    mp[x].erase(y);
    cnt0 += (c[x][0] > 0 && c[x][1] > 0);
    if (!c[x][0] && !c[x][1]) res *= 2;
  }
  void ins(int x, int y, int z) {
    cnt0 -= (c[x][0] > 0 && c[x][1] > 0);
    if (!c[x][0] && !c[x][1]) res *= inv2;
    z ^= (y & 1);
    mp[x][y] = z;
    c[x][z]++;
    cnt0 += (c[x][0] > 0 && c[x][1] > 0);
  }
} mp1, mp2;
int n, m, k, c[2];
unordered_map<int, int> mp[1000005];
signed main() {
  n = read(), m = read(), k = read();
  mp1.res = ((modint(2)) ^ n);
  mp2.res = ((modint(2)) ^ m);
  for (register int i = (1); i <= (k); ++i) {
    int x = read(), y = read(), z = read();
    if (mp[x].count(y))
      c[mp[x][y] ^ (x & 1) ^ (y & 1)]--, mp[x].erase(y), mp1.del(x, y),
          mp2.del(y, x);
    if (z != -1) {
      mp[x][y] = z;
      mp1.ins(x, y, z), mp2.ins(y, x, z), c[z ^ (x & 1) ^ (y & 1)]++;
    }
    modint res = 0;
    if (!mp1.cnt0) res += mp1.res;
    if (!mp2.cnt0) res += mp2.res;
    res -= (!c[0]), res -= (!c[1]);
    cout << res.x << endl;
  }
  return 0;
}
