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;
namespace io {
const int l = 1 << 20;
char buf[l], *s, *t, c;
inline void gc() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, l, stdin);
    c = s == t ? EOF : *s++;
  } else
    c = *s++;
}
template <class IT>
inline void gi(IT &x) {
  x = 0;
  gc();
  while (c < '0' || c > '9') gc();
  while ('0' <= c && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    gc();
  }
}
char buf0[20];
int a;
template <class IT>
inline void pi(IT x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  do buf0[++a] = x % 10 + 48;
  while (x /= 10);
  while (a) putchar(buf0[a--]);
  putchar('\n');
}
};  // namespace io
using io::gi;
using io::pi;
template <class IT>
inline void cmax(IT &a, IT b) {
  if (a < b) a = b;
}
template <class IT>
inline void cmin(IT &a, IT b) {
  if (b < a) a = b;
}
template <class IT>
inline bool bmax(IT &a, IT b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <class IT>
inline bool bmin(IT &a, IT b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
const int N = 500005;
const long long p = 998244353ll;
inline long long add(long long a) { return a < p ? a : a - p; }
inline long long sub(long long a) { return a < 0ll ? a + p : a; }
struct seg {
  int l, r, X, x;
} T[N];
int V[N], A[N], B[N], L[N], R[N];
pair<int, int> P[N];
inline bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.first < b.first || (a.first == b.first && a.second > b.second);
}
long long SM[N];
inline long long sol(int n0, int m0) {
  int n = 0, m = 0, i, p0;
  pair<int, int> cur;
  for (i = (1); i <= (n0); ++i) V[i] = 0;
  for (i = (1); i <= (m0); ++i)
    if (T[i].x) {
      ++V[T[i].l];
      --V[T[i].r + 1];
    }
  for (i = (1); i <= (n0); ++i) {
    if (V[i] += V[i - 1])
      A[i] = B[i] = 0;
    else
      A[i] = B[i] = ++n;
  }
  A[n0 + 1] = n + 1;
  for (i = (n0); i >= (1); --i)
    if (!A[i]) A[i] = A[i + 1];
  for (i = (1); i <= (n0); ++i)
    if (!B[i]) B[i] = B[i - 1];
  for (i = (1); i <= (m0); ++i)
    if (!T[i].x) {
      cur = make_pair(A[T[i].l], B[T[i].r]);
      if (cur.first > cur.second) return 0ll;
      P[++m] = cur;
    }
  m0 = m;
  m = 0;
  sort(P + 1, P + m0 + 1, cmp);
  for (i = (1); i <= (m0); ++i) {
    cur = P[i];
    while (m && L[m] <= cur.first && cur.second <= R[m]) --m;
    L[++m] = cur.first;
    R[m] = cur.second;
  }
  SM[1] = 1ll;
  for (i = (2); i <= (n + 1); ++i) {
    p0 = L[lower_bound(R + 1, R + m + 1, i - 1) - R - 1] + 1;
    cmax(p0, 1);
    if (p0 < i)
      SM[i] = sub(SM[i - 1] - SM[p0 - 1]);
    else
      SM[i] = 0ll;
    SM[i] = add(SM[i] + SM[i - 1]);
  }
  return sub(SM[n + 1] - SM[L[m]]);
}
inline void ac() {
  int n, k, m, i, b;
  long long s = 1ll;
  gi(n);
  gi(k);
  gi(m);
  for (i = (1); i <= (m); ++i) {
    gi(T[i].l);
    gi(T[i].r);
    gi(T[i].X);
  }
  for (b = (0); b < (k); ++b) {
    for (i = (1); i <= (m); ++i) T[i].x = T[i].X >> b & 1;
    s = s * sol(n, m) % p;
  }
  cout << s;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ac();
  return 0;
}
