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 MD = 998244353;
const int M = 5e5 + 100;
int n, m, k;
int l[M], r[M], x[M], p2[M];
bool check(vector<int> &v) {
  for (int i = 0; i < m; i++) {
    int a = -1;
    for (int j = l[i]; j <= r[i]; j++) a &= v[j];
    if (a != x[i]) return false;
  }
  return true;
}
int acc;
void gen(vector<int> &t) {
  if (t.size() == n) {
    if (check(t)) {
      for (auto &x : t) cerr << x << " ";
      cerr << "\n";
      acc++;
    }
    return;
  }
  for (int x = 0; x < 1 << k; x++) {
    t.push_back(x);
    gen(t);
    t.pop_back();
  }
}
void solve() {
  acc = 0;
  vector<int> t;
  gen(t);
  cerr << "ans: " << acc << "\n";
}
int main() {
  p2[0] = 1;
  for (int i = 1; i < M; i++) p2[i] = p2[i - 1] * 2ll % MD;
  while (scanf("%d %d %d", &n, &k, &m) == 3) {
    for (int i = 0; i < m; i++) scanf("%d %d %d", &l[i], &r[i], &x[i]);
    for (int i = 0; i < m; i++) l[i]--, r[i]--;
    vector<int> ids(m, 0);
    for (int i = 0; i < m; i++) ids[i] = i;
    sort(ids.begin(), ids.end(), [](int i, int j) -> bool {
      return r[i] == r[j] ? l[i] < l[j] : r[i] < r[j];
    });
    int res = 1;
    for (int ib = 0; ib < k; ib++) {
      vector<int> ids0, ids1;
      for (auto &id : ids)
        if (x[id] >> ib & 1)
          ids1.push_back(id);
        else
          ids0.push_back(id);
      vector<int> dp(n + 1, 1), s(n + 1, 0), sdp(n + 1, 0);
      int i1 = (int)ids1.size() - 1, left = n;
      for (int i = n - 1; i >= 0; i--) {
        while (i1 >= 0 && r[ids1[i1]] == i) left = min(left, l[ids1[i1--]]);
        if (i >= left) s[i] = 1;
      }
      for (int i = 1; i <= n; i++) s[i] += s[i - 1];
      int i0 = 0, le = -1, ri = -1;
      for (int i = 0; i <= n; i++) {
        if (s[i] - (i ? s[i - 1] : 0) == 1)
          dp[i] = 0;
        else if (i0 == 0)
          dp[i] = p2[i - (i ? s[i - 1] : 0)];
        else
          dp[i] = 1ll * (sdp[ri] - (le ? sdp[le - 1] : 0) + MD) % MD *
                  p2[i - ri - 1 - s[i - 1] + s[ri]] % MD;
        while (i0 < ids0.size() && r[ids0[i0]] == i) {
          int id = ids0[i0];
          if (s[r[id]] - (l[id] ? s[l[id] - 1] : 0) == r[id] - l[id] + 1)
            res = 0;
          le = max(le, l[id]), ri = max(ri, r[id]);
          i0++;
        }
        sdp[i] = ((i ? sdp[i - 1] : 0) + dp[i]) % MD;
      }
      int tres = dp[n];
      res = 1ll * res * tres % MD;
    }
    printf("%d\n", res);
  }
  return 0;
}
