#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long max_n = 1000050;
long long mod = 998244353;
long long p2[max_n];
long long cnt_oe[2], cnt_row[max_n][2], cnt_col[max_n][2];
set<long long> bad_cols, bad_rows, non_empty_cols, non_empty_rows;
map<pair<long long, long long>, long long> grid;
long long n, m, k;
void update_dimension(long long pos, long long oddity, long long op,
                      long long cnt[max_n][2], set<long long> &bad,
                      set<long long> &non_empty) {
  cnt[pos][oddity] += op;
  if ((cnt[pos][0] > 0) && (cnt[pos][1] > 0)) {
    if (!bad.count(pos)) bad.insert(pos);
  } else {
    if (bad.count(pos)) bad.erase(pos);
  }
  if (cnt[pos][0] + cnt[pos][1] > 0) {
    if (!non_empty.count(pos)) non_empty.insert(pos);
  } else {
    if (non_empty.count(pos)) non_empty.erase(pos);
  }
}
void update(long long x, long long y, long long val) {
  long long oddity_pos = (x + y) & 1;
  if (grid.count(make_pair(x, y))) {
    long long oddity = oddity_pos ^ grid[make_pair(x, y)];
    cnt_oe[oddity]--;
    update_dimension(x, oddity, -1, cnt_row, bad_rows, non_empty_rows);
    update_dimension(y, oddity, -1, cnt_col, bad_cols, non_empty_cols);
    grid.erase(make_pair(x, y));
  }
  if (val == -1) return;
  grid[make_pair(x, y)] = val;
  long long oddity = oddity_pos ^ grid[make_pair(x, y)];
  cnt_oe[oddity]++;
  update_dimension(x, oddity, 1, cnt_row, bad_rows, non_empty_rows);
  update_dimension(y, oddity, 1, cnt_col, bad_cols, non_empty_cols);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  p2[0] = 1;
  for (long long i = 1; i < max_n; i++) p2[i] = (p2[i - 1] * 2) % mod;
  cin >> n >> m >> k;
  for (long long i = 1; i <= k; i++) {
    long long x, y, val;
    cin >> x >> y >> val;
    update(x, y, val);
    if ((!bad_cols.empty()) && (!bad_rows.empty()))
      cout << 0 << "\n";
    else if (!bad_cols.empty())
      cout << p2[n - (long long)non_empty_rows.size()] << "\n";
    else if (!bad_rows.empty())
      cout << p2[m - (long long)non_empty_cols.size()] << "\n";
    else {
      long long ans = 0;
      if ((cnt_oe[0] == 0) && (cnt_oe[1] == 0)) {
        ans = p2[n] + p2[m] - 2;
        if (ans >= mod) ans -= mod;
      } else {
        ans = p2[n - (long long)non_empty_rows.size()] +
              p2[m - (long long)non_empty_cols.size()] - 1 +
              (cnt_oe[0] && cnt_oe[1]);
        if (ans >= mod) ans -= mod;
      }
      cout << ans << "\n";
    }
  }
}
