You are given three integers n, k, m and m conditions (l_1, r_1, x_1), (l_2, r_2, x_2), ..., (l_m, r_m, x_m).

Calculate the number of distinct arrays a, consisting of n integers such that: 

  * 0 ≤ a_i < 2^k for each 1 ≤ i ≤ n; 
  * bitwise AND of numbers a[l_i] \& a[l_i + 1] \& ... \& a[r_i] = x_i for each 1 ≤ i ≤ m. 



Two arrays a and b are considered different if there exists such a position i that a_i ≠ b_i. 

The number can be pretty large so print it modulo 998244353.

Input

The first line contains three integers n, k and m (1 ≤ n ≤ 5 ⋅ 10^5, 1 ≤ k ≤ 30, 0 ≤ m ≤ 5 ⋅ 10^5) — the length of the array a, the value such that all numbers in a should be smaller than 2^k and the number of conditions, respectively.

Each of the next m lines contains the description of a condition l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 0 ≤ x_i < 2^k) — the borders of the condition segment and the required bitwise AND value on it.

Output

Print a single integer — the number of distinct arrays a that satisfy all the above conditions modulo 998244353.

Examples

Input


4 3 2
1 3 3
3 4 6


Output


3


Input


5 2 3
1 3 2
2 5 0
3 3 3


Output


33

Note

You can recall what is a bitwise AND operation [here](https://en.wikipedia.org/wiki/Bitwise_operation#AND).

In the first example, the answer is the following arrays: [3, 3, 7, 6], [3, 7, 7, 6] and [7, 3, 7, 6].
#include <bits/stdc++.h>
using namespace std;
const int n = 5e5 + 10;
const long long MOD = 998244353;
int N, K, M;
int L[n], R[n], X[n];
vector<tuple<int, int, int> > A;
int cnt[n];
bool vis[n];
long long dp[n];
long long to[n];
long long pw[n];
long long calc() {
  sort(A.begin(), A.end());
  stack<int> S;
  fill_n(vis, M + 1, true);
  for (auto t : A) {
    int l, r, ind;
    tie(l, r, ind) = t;
    r *= -1;
    while (S.size() && R[S.top()] >= R[ind]) {
      vis[S.top()] = false;
      S.pop();
    }
    S.push(ind);
  }
  vector<int> X;
  X.push_back(M);
  L[M] = R[M] = 0;
  for (int i = 0; i < ((int)(A).size()); i++) {
    int ind = get<2>(A[i]);
    if (vis[ind]) {
      X.push_back(ind);
    }
  }
  X.push_back(M + 1);
  L[M + 1] = R[M + 1] = N + 1;
  fill_n(dp, M + 2, 0);
  fill_n(to, M + 2, 0);
  dp[0] = 1;
  deque<tuple<int, int, int> > Q;
  for (int i = 1; i < ((int)(X).size()); i++) {
    if (i != 1) dp[i] = dp[i - 1];
    Q.push_back({R[X[i - 1]] + 1, R[X[i]], i - 1});
    to[i - 1] = pw[cnt[R[X[i]]] - cnt[R[X[i - 1]]]] - 1 + MOD;
    to[i - 1] %= MOD;
    dp[i] += to[i - 1] * dp[i - 1];
    dp[i] %= MOD;
    while (get<0>(Q[0]) < L[X[i]]) {
      int l, r, ind;
      tie(l, r, ind) = Q[0];
      if (r < L[X[i]]) {
        Q.pop_front();
        dp[i] -= to[ind] * dp[ind] % MOD;
        dp[i] = (dp[i] + MOD) % MOD;
        to[ind] = 0;
      } else {
        dp[i] -= dp[ind] * to[ind] % MOD;
        dp[i] = (dp[i] + MOD) % MOD;
        l = L[X[i]];
        get<0>(Q[0]) = l;
        to[ind] = (pw[cnt[r] - cnt[l - 1]] - 1) *
                  pw[cnt[l - 1] - cnt[R[X[ind]]]] % MOD;
        dp[i] += dp[ind] * to[ind];
        dp[i] = (dp[i] + MOD) % MOD;
      }
    }
  }
  return dp[((int)(X).size()) - 1];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  pw[0] = 1;
  for (int i = 1; i < n; i++) {
    pw[i] = 2 * pw[i - 1] % MOD;
  }
  cin >> N >> K >> M;
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i] >> X[i];
  }
  long long res = 1;
  for (int b = 0; b < K; b++) {
    A.clear();
    fill_n(cnt, N + 10, 0);
    for (int i = 0; i < M; i++) {
      if (X[i] & (1 << b)) {
        cnt[L[i]]++;
        cnt[R[i] + 1]--;
      } else {
        A.push_back({L[i], -R[i], i});
      }
    }
    for (int i = 1; i < N + 5; i++) {
      cnt[i] += cnt[i - 1];
    }
    for (int i = 0; i < N + 5; i++) {
      if (!cnt[i])
        cnt[i] = 1;
      else
        cnt[i] = 0;
    }
    for (int i = 1; i < N + 5; i++) {
      cnt[i] += cnt[i - 1];
    }
    res *= calc();
    res %= MOD;
  }
  cout << res << endl;
  return 0;
}
