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;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
const double PI = acos(-1);
const double eps = (1e-9);
const long long int INF = 2e9;
const int M = 998244353;
const int N = (1e6) + 3;
vector<tuple<int, int, int> > query;
vector<int> v;
long long int pro(long long int a, long long int b) { return (a * b) % M; }
int val[N];
int ar[N];
long long int dp[N];
long long int compute(int n, int m) {
  fill(val, val + n + 1, 0);
  fill(ar, ar + n + 1, 0);
  fill(dp, dp + n + 1, 0);
  int i, l, r;
  for (i = 0; i < m; ++i) {
    tie(l, r, ignore) = query[i];
    if (v[i])
      val[l]++, val[r + 1]--;
    else
      ar[r] = max(ar[r], l);
  }
  dp[0] = 1;
  for (i = 1; i <= n; ++i) val[i] += val[i - 1];
  for (i = 1; i <= n; ++i)
    if (val[i] > 0) val[i] = 1;
  long long int sum = 1;
  int ptr = 0;
  for (i = 1; i <= n; ++i) {
    if (!val[i]) dp[i] = sum, sum += sum;
    while (ptr < ar[i]) sum += (M - dp[ptr]), ptr++;
    sum %= M;
  }
  return sum;
}
void solve() {
  int j, n, k, m, i, l, r, x;
  scanf("%d%d%d", &n, &k, &m);
  query.resize(m);
  for (i = 0; i < m; ++i)
    scanf("%d%d%d", &l, &r, &x), query[i] = make_tuple(l, r, x);
  v.resize(m);
  long long int ans = 1;
  for (i = 0; i < k; ++i) {
    for (j = 0; j < m; ++j) {
      x = get<2>(query[j]);
      if ((x & (1 << i)))
        v[j] = 1;
      else
        v[j] = 0;
    }
    ans = pro(ans, compute(n, m));
  }
  cout << ans << "\n";
}
int main() {
  int t = 1;
  while (t--) solve();
}
