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;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int N = 5e5 + 5, M = 998244353, INF = 0x3f3f3f3f;
void Main();
void dprint() { cerr << '\n'; }
template <typename T, typename... U>
void dprint(const T& x, const U&... y) {
  ((sizeof...(y) == 0) ? (cerr << x) : (cerr << x << ' '));
  dprint(y...);
}
template <typename T>
void dprint(const T& a, int l, int r, char c) {
  for (int i = l; i <= r; ++i) {
    cerr << a[i];
    if (i == r)
      cerr << '\n';
    else
      cerr << c;
  }
}
template <typename... U>
void debug(const U&... y) {
  cerr << "debug: ";
  dprint(y...);
};
void print() { cout << '\n'; }
template <typename T, typename... U>
void print(const T& x, const U&... y) {
  ((sizeof...(y) == 0) ? (cout << x) : (cout << x << ' '));
  print(y...);
}
template <typename T>
void print(const T& a, int l, int r, char c) {
  for (int i = l; i <= r; ++i) {
    cout << a[i];
    if (i == r)
      cout << '\n';
    else
      cout << c;
  }
}
void input() {}
template <typename T, typename... U>
void input(T& x, U&... y) {
  cin >> x;
  input(y...);
}
template <typename T>
void input(T& a, int l, int r, bool f) {
  for (int i = l; i <= r; ++i) cin >> a[i];
}
template <typename T>
void Max(T& a, T b) {
  a < b ? a = b : 1;
}
template <typename T>
void Min(T& a, T b) {
  a > b ? a = b : 1;
}
template <typename T>
void Add(T& a, T b) {
  a += b, a > M ? a -= M : 1, a < 0 ? a += M : 1;
}
template <typename T>
void Mul(T& a, T b) {
  a = a * b % M;
}
template <typename T>
T Mod(const T a) {
  return (a % M + M) % M;
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(0), cin.tie(0);
  Main();
}
int L[N], R[N], X[N], pos[N], dp[N], a[N];
ll calc(int p, int n, int k, int m) {
  fill(dp, dp + n + 2, 0);
  fill(a, a + n + 2, 0);
  fill(pos, pos + n + 2, 0);
  for (int i = 1; i <= m; ++i)
    if (X[i] & (1 << p))
      ++a[L[i]], --a[R[i] + 1];
    else
      Max(pos[R[i]], L[i]);
  for (int i = 2; i <= n + 1; ++i) Add(a[i], a[i - 1]), Max(pos[i], pos[i - 1]);
  int j = 0, sum = 1;
  dp[0] = 1;
  for (int i = 1; i <= n + 1; ++i)
    if (!a[i]) {
      while (j < pos[i - 1]) Add(sum, -dp[j++]);
      dp[i] = a[i] ? 0 : sum;
      Add(sum, dp[i]);
    }
  return dp[n + 1];
}
void Main() {
  int n, k, m;
  input(n, k, m);
  for (int i = 1; i <= m; ++i) input(L[i], R[i], X[i]);
  ll ans = 1;
  for (int i = 0; i < k; ++i) Mul(ans, calc(i, n, k, m));
  print(ans);
}
