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
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
using namespace std;
const long long inf = 1e9 + 228;
const long long infll = 4e18;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long double eps = 1e-14;
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
long long kek[1000000][2];
long long cnt_ok = 0, cnt_blocked = 0;
long long cnt_ok2 = 0, cnt_blocked2 = 0;
long long counter1[2][2];
long long counter2[1000000][2];
long long binpow(long long n, long long k) {
  if (!k) return 1;
  if (k & 1) return binpow(n, k - 1) * n % mod2;
  long long b = binpow(n, k / 2);
  return b * b % mod2;
}
void solve() {
  long long n, m, q;
  cin >> n >> m >> q;
  cnt_ok = m;
  map<pair<long long, long long>, long long> lol;
  cnt_ok = m;
  cnt_ok2 = n;
  for (long long i = 0; i < q; i++) {
    long long x, y, t;
    cin >> x >> y >> t;
    x--, y--;
    if (t == -1) {
      if (lol.count(make_pair(x, y))) {
        long long was = lol[make_pair(x, y)];
        if (x & 1) was ^= 1;
        if (kek[y][was] == 1) {
          if (kek[y][was ^ 1]) cnt_blocked--;
          if (!kek[y][was ^ 1]) cnt_ok++;
        }
        kek[y][was]--;
        counter1[y & 1][was]--;
        if (counter2[x][was ^ (y & 1)] == 1) {
          if (counter2[x][was ^ (y & 1) ^ 1] == 0) {
            cnt_ok2++;
          } else {
            cnt_blocked2--;
          }
        }
        counter2[x][was ^ (y & 1)]--;
        lol.erase(make_pair(x, y));
      }
    } else {
      if (lol.count(make_pair(x, y))) {
        long long was = lol[make_pair(x, y)];
        if (x & 1) was ^= 1;
        if (kek[y][was] == 1) {
          if (kek[y][was ^ 1]) cnt_blocked--;
          if (!kek[y][was ^ 1]) cnt_ok++;
        }
        kek[y][was]--;
        counter1[y & 1][was]--;
        if (counter2[x][was ^ (y & 1)] == 1) {
          if (counter2[x][was ^ (y & 1) ^ 1] == 0) {
            cnt_ok2++;
          } else {
            cnt_blocked2--;
          }
        }
        counter2[x][was ^ (y & 1)]--;
        lol.erase(make_pair(x, y));
      }
      lol[make_pair(x, y)] = t;
      if (x & 1) t ^= 1;
      if (kek[y][t] == 0) {
        if (kek[y][t ^ 1] == 0) {
          cnt_ok--;
        } else {
          cnt_blocked++;
        }
      }
      counter1[y & 1][t]++;
      if (counter2[x][t ^ (y & 1)] == 0) {
        if (counter2[x][t ^ (y & 1) ^ 1] == 0) {
          cnt_ok2--;
        } else {
          cnt_blocked2++;
        }
      }
      counter2[x][t ^ (y & 1)]++;
      kek[y][t]++;
    }
    long long ans = (cnt_blocked ? 0 : binpow(2, cnt_ok));
    ans -= (!counter1[0][0]) & (!counter1[1][1]);
    ans -= (!counter1[0][1]) & (!counter1[1][0]);
    if (!cnt_blocked2) {
      ans += binpow(2, cnt_ok2);
    }
    ans %= mod2;
    if (ans < 0) ans += mod2;
    cout << ans << '\n';
  }
}
signed main() {
  fast_io();
  cout << fixed << setprecision(10);
  long long q = 1;
  while (q--) solve();
}
