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 MOD = 998244353;
int sum(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
int mult(int a, int b) { return (a * 1LL * b) % MOD; }
struct Demand {
  int l, r, x;
  bool operator<(const Demand& d) const {
    if (l != d.l) return l < d.l;
    return r > d.r;
  }
};
const int N = (int)5e5 + 5;
int pw2[N];
int solve(int n, vector<Demand> dem, bool debug = false) {
  vector<int> a(n + 1, 0);
  vector<int> right(n, -1), left(n, -1);
  vector<Demand> newdem;
  sort((dem).begin(), (dem).end());
  int prev = -1;
  for (Demand d : dem) {
    if (d.x == 1) {
      a[d.r + 1] -= 1;
      a[d.l] += 1;
    } else {
      if (debug) printf("%d %d\n", d.l, d.r);
      while (!newdem.empty() && newdem.back().r >= d.r) newdem.pop_back();
      newdem.push_back(d);
    }
  }
  if (debug) {
    printf("\n");
    for (Demand d : newdem) printf("%d %d\n", d.l, d.r);
    printf("\n");
  }
  dem = newdem;
  for (Demand d : dem) {
    left[d.r] = d.l;
    right[d.l] = d.r;
  }
  for (int i = 0; i < n; ++i) a[i + 1] += a[i];
  for (int i = 0; i < n; ++i) a[i] = !!a[i];
  if (debug) {
    for (int i = 0; i < n; ++i) printf("%d ", a[i]);
    printf("\n");
  }
  vector<int> dp(n + 1);
  dp[0] = 1;
  int pref = 0;
  int sum1 = 0, sum2 = 0;
  for (int i = 0; i < n; ++i) {
    if (right[i] != -1) sum2 = sum(sum2, dp[i]);
    if (a[i] == 0) {
      pref += 1;
      sum1 = mult(sum1, 2);
    }
    dp[i + 1] = sub(pw2[pref], sum(sum1, sum2));
    if (left[i] != -1) {
      sum2 = sub(sum2, dp[left[i]]);
      sum1 = sum(sum1, dp[left[i]]);
    }
    if (debug) {
      printf("%d %d %d\n", dp[i + 1], left[i], right[i]);
    }
  }
  if (debug) printf("\n");
  return dp[n];
}
int main() {
  int n, k, m;
  scanf("%d %d %d", &n, &k, &m);
  pw2[0] = 1;
  for (int i = 0; i < n; ++i) pw2[i + 1] = mult(pw2[i], 2);
  vector<Demand> dem;
  for (int i = 0; i < m; ++i) {
    int l, r, x;
    scanf("%d %d %d", &l, &r, &x);
    --l;
    --r;
    dem.push_back({l, r, x});
  }
  int ans = 1;
  for (int b = 0; b < k; ++b) {
    vector<Demand> q;
    for (int i = 0; i < m; ++i)
      q.push_back({dem[i].l, dem[i].r, (dem[i].x >> b) & 1});
    ans = mult(ans, solve(n, q, false));
  }
  printf("%d\n", ans);
}
