description: A matrix of size n × m, such that each cell of it contains either 0 or 1, is considered beautiful if the sum in every contiguous submatrix of size 2 × 2 is exactly 2, i. e. every "square" of size 2 × 2 contains exactly two 1's and exactly two 0's.
  
  You are given a matrix of size n × m. Initially each cell of this matrix is empty. Let's denote the cell on the intersection of the x-th row and the y-th column as (x, y). You have to process the queries of three types:
  
    * x y -1 — clear the cell (x, y), if there was a number in it; 
    * x y 0 — write the number 0 in the cell (x, y), overwriting the number that was there previously (if any); 
    * x y 1 — write the number 1 in the cell (x, y), overwriting the number that was there previously (if any). 
  
  
  
  After each query, print the number of ways to fill the empty cells of the matrix so that the resulting matrix is beautiful. Since the answers can be large, print them modulo 998244353.
  
  Input
  
  The first line contains three integers n, m and k (2 ≤ n, m ≤ 10^6; 1 ≤ k ≤ 3 ⋅ 10^5) — the number of rows in the matrix, the number of columns, and the number of queries, respectively.
  
  Then k lines follow, the i-th of them contains three integers x_i, y_i, t_i (1 ≤ x_i ≤ n; 1 ≤ y_i ≤ m; -1 ≤ t_i ≤ 1) — the parameters for the i-th query.
  
  Output
  
  For each query, print one integer — the number of ways to fill the empty cells of the matrix after the respective query, taken modulo 998244353.
  
  Example
  
  Input
  
  
  2 2 7
  1 1 1
  1 2 1
  2 1 1
  1 1 0
  1 2 -1
  2 1 -1
  1 1 -1
  
  
  Output
  
  
  3
  1
  0
  1
  2
  3
  6
solution: #include <bits/stdc++.h>
  using namespace std;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  const long long maxn = 2e6 + 5, mod = 998244353, inf = 1e9;
  const long double pi = 4 * atan(1.0), eps = 1e-9;
  void solve();
  signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ;
    long long tc = 1;
    for (long long test = (long long)(1); test <= (long long)(tc); ++test) {
      solve();
    }
    return 0;
  }
  long long pw[maxn];
  map<pair<long long, long long>, long long> g;
  long long n, m, q;
  long long cntr;
  long long cntc;
  long long fixr2[maxn][2];
  long long fixc2[maxn][2];
  long long sfixr, sfixc;
  long long bfixr, bfixc;
  long long fix[2];
  long long di[] = {-1, 0, 1, 0};
  long long dj[] = {0, 1, 0, -1};
  void solve() {
    pw[0] = 1;
    for (long long i = (long long)(1); i <= (long long)(maxn - 1); ++i)
      pw[i] = pw[i - 1] * 2 % mod;
    cin >> n >> m >> q;
    for (long long i = (long long)(1); i <= (long long)(q); ++i) {
      long long a, b, s;
      cin >> a >> b >> s;
      if (g.count({a, b})) {
        sfixr -= (fixr2[a][0] or fixr2[a][1]);
        sfixc -= (fixc2[b][0] or fixc2[b][1]);
        bfixr -= (fixr2[a][0] and fixr2[a][1]);
        bfixc -= (fixc2[b][0] and fixc2[b][1]);
        fixr2[a][(b & 1) ^ g[{a, b}]]--;
        fixc2[b][(a & 1) ^ g[{a, b}]]--;
        sfixr += (fixr2[a][0] or fixr2[a][1]);
        sfixc += (fixc2[b][0] or fixc2[b][1]);
        bfixr += (fixr2[a][0] and fixr2[a][1]);
        bfixc += (fixc2[b][0] and fixc2[b][1]);
        for (long long dir = (long long)(0); dir <= (long long)(3); ++dir) {
          long long ti = a + di[dir];
          long long tj = b + dj[dir];
          if (ti == a)
            cntr -= (g.count({ti, tj}) and g[{ti, tj}] == g[{a, b}]);
          else
            cntc -= (g.count({ti, tj}) and g[{ti, tj}] == g[{a, b}]);
        }
        fix[(a + b & 1) ^ g[{a, b}]]--;
        g.erase({a, b});
      }
      if (s >= 0) {
        g[{a, b}] = s;
        fix[(a + b & 1) ^ g[{a, b}]]++;
        for (long long dir = (long long)(0); dir <= (long long)(3); ++dir) {
          long long ti = a + di[dir];
          long long tj = b + dj[dir];
          if (ti == a)
            cntr += (g.count({ti, tj}) and g[{ti, tj}] == g[{a, b}]);
          else
            cntc += (g.count({ti, tj}) and g[{ti, tj}] == g[{a, b}]);
        }
        sfixr -= (fixr2[a][0] or fixr2[a][1]);
        sfixc -= (fixc2[b][0] or fixc2[b][1]);
        bfixr -= (fixr2[a][0] and fixr2[a][1]);
        bfixc -= (fixc2[b][0] and fixc2[b][1]);
        fixr2[a][(b & 1) ^ g[{a, b}]]++;
        fixc2[b][(a & 1) ^ g[{a, b}]]++;
        sfixr += (fixr2[a][0] or fixr2[a][1]);
        sfixc += (fixc2[b][0] or fixc2[b][1]);
        bfixr += (fixr2[a][0] and fixr2[a][1]);
        bfixc += (fixc2[b][0] and fixc2[b][1]);
      }
      long long ans = 0;
      if (!cntr and !bfixr) {
        ans += pw[n - sfixr];
      }
      if (!cntc and !bfixc) {
        ans += pw[m - sfixc];
      }
      ans -= (!fix[0]) + (!fix[1]);
      cout << (ans % mod + mod) % mod << '\n';
    }
  }
  