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;
struct edge_t {
  int l;
  int r;
  int x;
};
int one_arr[5 * 100 * 1000 + 5];
int pre_sum[5 * 100 * 1000 + 5];
int left_end[5 * 100 * 1000 + 5];
long long dp[5 * 100 * 1000 + 5][2];
long long dp_sum[5 * 100 * 1000 + 5];
int one_mp[5 * 100 * 1000 + 5];
int zero_mp[5 * 100 * 1000 + 5];
int mod = 998244353;
long long each_k(int n, vector<edge_t> e, int k) {
  int mask = 1 << k;
  vector<edge_t> one;
  vector<edge_t> zero;
  memset(one_arr, 0, sizeof(one_arr));
  memset(one_mp, 0, sizeof(one_mp));
  memset(zero_mp, 0, sizeof(zero_mp));
  pre_sum[0] = 0;
  for (int i = 0; i < e.size(); i++) {
    if ((e[i].x & mask) == 0) {
      zero.push_back(e[i]);
    } else {
      one.push_back(e[i]);
      int l = e[i].l;
      int r = e[i].r;
      if (one_mp[l] == 0)
        one_mp[l] = r;
      else if (r > one_mp[l])
        one_mp[l] = r;
    }
  }
  int pre_r = 0;
  for (int i = 1; i <= n; i++) {
    if (one_mp[i] == 0) continue;
    int l = i;
    int r = one_mp[i];
    int max_l = max(l, pre_r);
    if (r <= pre_r) continue;
    for (int i = max_l; i <= r; i++) {
      one_arr[i] = 1;
    }
    pre_r = r;
  }
  for (int i = 1; i <= n; i++) {
    pre_sum[i] = pre_sum[i - 1] + one_arr[i];
    assert(pre_sum[i] <= i);
  }
  for (int i = 0; i < zero.size(); i++) {
    int len = zero[i].r + 1 - zero[i].l;
    len -= (pre_sum[zero[i].r] - pre_sum[zero[i].l - 1]);
    assert(len >= 0);
    zero[i].l -= pre_sum[zero[i].l - 1];
    zero[i].r = zero[i].l + len - 1;
  }
  int n_new = n - pre_sum[n];
  for (int i = 0; i < zero.size(); i++) {
    if (zero[i].r < zero[i].l) {
      return 0;
    }
  }
  for (int i = 0; i < zero.size(); i++) {
    int l = zero[i].l;
    int r = zero[i].r;
    if (zero_mp[l] == 0) {
      zero_mp[l] = r;
    } else if (r < zero_mp[l])
      zero_mp[l] = r;
  }
  zero.clear();
  int smallest_r = 10000 * 10000;
  for (auto i = n_new; i >= 1; i--) {
    int l = i;
    int r = zero_mp[i];
    if (r == 0) continue;
    if (r < smallest_r) {
      smallest_r = r;
      edge_t tmp;
      tmp.l = l;
      tmp.r = r;
      zero.push_back(tmp);
    }
  }
  memset(left_end, 0, sizeof(left_end));
  for (int i = 0; i < zero.size(); i++) {
    int l = zero[i].l;
    int r = zero[i].r;
    left_end[r] = l;
  }
  if (n_new == 0) return 1;
  dp[1][0] = 1;
  dp[1][1] = 1;
  if (left_end[1] != 0) {
    dp[1][1] = 0;
  }
  dp_sum[0] = 0;
  dp_sum[1] = dp[1][0];
  for (int i = 2; i <= n_new; i++) {
    dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
    dp[i][0] %= mod;
    if (left_end[i] == 0)
      dp[i][1] = dp[i][0];
    else {
      dp[i][1] = 0;
      dp[i][1] = (mod + dp_sum[i - 1] - dp_sum[left_end[i] - 1]) % mod;
    }
    dp_sum[i] = dp_sum[i - 1] + dp[i][0];
    dp_sum[i] %= mod;
  }
  return (dp[n_new][0] + dp[n_new][1]) % mod;
  return 1;
}
int main() {
  int n, k, m;
  vector<edge_t> e;
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 0; i < m; i++) {
    int l, r, x;
    edge_t tmp;
    scanf("%d %d %d", &l, &r, &x);
    tmp.l = l;
    tmp.r = r;
    tmp.x = x;
    e.push_back(tmp);
  }
  long long result = 1;
  for (int i = 0; i < k; i++) {
    long long t = each_k(n, e, i);
    result *= t % mod;
    result %= mod;
  }
  printf("%lld\n", result);
  return 0;
}
