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;
long long n, k, m, x, y, l;
vector<pair<long long, pair<long long, long long> > > v;
vector<long long> mx, fc;
long long dpt(long long state, long long lst0) {
  if (mx[state - 1] != 0 and lst0 < mx[state - 1]) {
    return 0;
  }
  if (state > n) {
    return 1;
  }
  if (fc[state] == 1) return dpt(state + 1, lst0);
  long long p = dpt(state + 1, lst0);
  long long q = dpt(state + 1, state);
  return (p + q) % 998244353;
}
long long dp[600000];
long long dpt() {
  dp[0] = 0;
  long long j = 0;
  long long ck = 0;
  for (long long i = 1; i <= n; i++) {
    if (j == 0) {
      if (fc[i]) {
        dp[i] = dp[i - 1];
        j = max(j, mx[i]);
      } else {
        if (ck == 0) {
          ck = 1;
          dp[i] = (dp[i - 1] + 1) % 998244353;
          j = max(j, mx[i]);
        } else {
          long long cur = (dp[i - 1] + 1) % 998244353;
          dp[i] = (dp[i - 1] + cur) % 998244353;
          j = max(j, mx[i]);
        }
      }
    } else {
      if (fc[i]) {
        dp[i] = dp[i - 1];
        j = max(j, mx[i]);
      } else {
        if (ck == 0) {
          ck = 1;
          dp[i] = (dp[i - 1] + 1) % 998244353;
          j = max(j, mx[i]);
          continue;
        }
        long long cur = dp[i - 1];
        cur = ((cur - dp[j - 1]) % 998244353 + 998244353) % 998244353;
        dp[i] = (dp[i - 1] + cur) % 998244353;
        j = max(j, mx[i]);
      }
    }
  }
  if (j == 0)
    dp[n] = (dp[n] + 1) % 998244353;
  else
    dp[n] = ((dp[n] - dp[j - 1]) % 998244353 + 998244353) % 998244353;
  return dp[n];
}
long long f(long long ps) {
  vector<long long> tmp(n + 10);
  mx.clear();
  fc.clear();
  mx.resize(n + 10);
  fc.resize(n + 10);
  for (auto it : v) {
    x = it.first;
    y = it.second.first;
    l = it.second.second;
    if (l & (1 << ps))
      tmp[x]++, tmp[y + 1]--;
    else
      mx[y] = max(mx[y], x);
  }
  for (long long i = 1; i <= n; i++) {
    fc[i] = (tmp[i] > 0);
    tmp[i + 1] += tmp[i];
  }
  return dpt();
}
int main() {
  cin >> n >> k >> m;
  while (m--) {
    cin >> x >> y >> l;
    v.push_back({x, {y, l}});
  }
  sort(v.begin(), v.end());
  long long ans = 1;
  for (long long i = 0; i < k; i++) {
    ans = (1LL * ans * f(i)) % 998244353;
  }
  cout << ans << endl;
  return 0;
}
