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 mxN = 5e5, M = 998244353, I2 = (M + 1) / 2;
int n, k, m, c[mxN + 1], lz[mxN], rz[mxN];
array<int, 3> a[mxN];
long long ans = 1, dp[mxN + 1], p2[mxN + 1], pI2[mxN + 1];
void solve(int n, vector<array<int, 2>> v) {
  v.insert(v.begin(), {-1, -1});
  dp[0] = 1;
  long long s1 = 0, s2 = 0;
  for (int i = 1, j = 0; i < v.size(); ++i) {
    s1 = (s1 + dp[i - 1]) % M;
    s2 = (s2 + dp[i - 1] * p2[v[i][1] - v[i - 1][1]]) % M;
    while (v[j][1] < v[i][0]) {
      s1 = (s1 + M - dp[j]) % M;
      s2 = (s2 + M - dp[j] * p2[v[j + 1][1] - v[j][1]] % M) % M;
      ++j;
    }
    dp[i] = (s2 + M - s1 +
             (p2[v[j][1] - v[i][0] + 1] + M - 1) *
                 p2[v[i][0] - v[j - 1][1] - 1] % M * dp[j - 1]) %
            M;
  }
  ans = ans * dp[v.size() - 1] % M;
  while (v.back()[1] < n - 1) {
    ans = ans * 2 % M;
    --n;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> m;
  p2[0] = pI2[0] = 1;
  for (int i = 1; i <= n; ++i) {
    p2[i] = p2[i - 1] * 2 % M;
    pI2[i] = pI2[i - 1] * I2 % M;
  }
  for (int i = 0; i < m; ++i) {
    cin >> a[i][0] >> a[i][1] >> a[i][2], --a[i][0], --a[i][1];
  }
  sort(a, a + m);
  for (int j = 0; j < k; ++j) {
    memset(c, 0, 4 * (n + 1));
    for (int i = 0; i < m; ++i)
      if (a[i][2] >> j & 1) ++c[a[i][0]], --c[a[i][1] + 1];
    int nz = 0;
    for (int i = 0; i < n; ++i) {
      c[i + 1] += c[i];
      nz += !c[i];
      lz[i] = nz;
      rz[i] = c[i] ? nz + 1 : nz;
    }
    vector<array<int, 2>> v1;
    for (int i = 0; i < m; ++i) {
      if (a[i][2] >> j & 1 ^ 1) {
        if (rz[a[i][0]] - 1 > lz[a[i][1]] - 1) {
          cout << 0;
          return 0;
        }
        v1.push_back({rz[a[i][0]] - 1, lz[a[i][1]] - 1});
      }
    }
    vector<array<int, 2>> v2;
    for (array<int, 2> a : v1) {
      if (v2.size() && a[0] == v2.back()[0] && a[1] > v2.back()[1]) continue;
      while (v2.size() && a[1] <= v2.back()[1]) v2.pop_back();
      v2.push_back(a);
    }
    solve(nz, v2);
  }
  cout << ans;
}
