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;
template <typename T>
T getint() {
  T x = 0, p = 1;
  char ch;
  do {
    ch = getchar();
  } while (ch <= ' ');
  if (ch == '-') p = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * p;
}
template <typename T1, typename T2>
bool umin(T1 &x, const T2 &y) {
  if (x > y) return x = y, true;
  return false;
}
template <typename T1, typename T2>
bool umax(T1 &x, const T2 &y) {
  if (x < y) return x = y, true;
  return false;
}
const int maxn = (int)5e5 + 10;
const int inf = (int)1e9 + 5;
const int mod = 998244353;
const long long llinf = (long long)1e18 + 5;
const double pi = acos(-1.0);
mt19937 gen(123532);
int mul(int x, int y) { return 1LL * x * y % mod; }
void sub(int &x, int y) {
  x -= y;
  if (x < 0) x += mod;
  if (x >= mod) x -= mod;
}
int X[maxn];
int l[maxn], r[maxn], x[maxn];
int mxl[maxn];
int n, k, m;
int t[4 * maxn];
int add[maxn], f[maxn];
int solve() {
  memset(add, 0, sizeof add);
  for (int i = 0; i < m; ++i) {
    if (x[i]) {
      add[l[i]]++;
      add[r[i] + 1]--;
    }
  }
  for (int i = 1; i <= n; ++i) {
    add[i] += add[i - 1];
  }
  for (int i = 1; i <= n; ++i) {
    add[i] = (add[i] > 0);
  }
  memset(f, 0, sizeof f);
  f[0] = 1;
  int lastzero = -1;
  int sum = 1;
  for (int i = 1; i <= n; ++i) {
    if (add[i] == 0) {
      f[i] = sum;
      sub(sum, -sum);
    }
    if (mxl[i] > 0) {
      while (lastzero + 1 < mxl[i]) {
        ++lastzero;
        sub(sum, f[lastzero]);
        f[lastzero] = 0;
      }
    }
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k >> m;
  for (int i = 0; i < m; ++i) {
    cin >> l[i] >> r[i] >> X[i];
  }
  int res = 1;
  for (int b = 0; b < k; ++b) {
    for (int i = 0; i < m; ++i) {
      x[i] = (X[i] >> b & 1);
    }
    memset(mxl, 0, sizeof mxl);
    for (int i = 0; i < m; ++i)
      if (x[i] == 0) {
        mxl[r[i]] = max(mxl[r[i]], l[i]);
      }
    res = mul(res, solve());
  }
  cout << res << endl;
  return 0;
}
