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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long MOD = 998244353;
inline long long mod(long long x_) { return (x_) % MOD; }
long long modpow(long long x_, long long N_) {
  if (N_ == 0) return 1;
  long long a = modpow(x_, N_ / 2);
  a = (a * a) % MOD;
  if (N_ % 2) a = (a * x_) % MOD;
  return a;
}
long long inv(long long x_) { return modpow(x_, MOD - 2); }
class mi {
 public:
  mi(long long v = 0) { value = v; }
  mi operator+(long long rs) { return mod(value + rs); }
  mi operator-(long long rs) { return mod(value - rs + MOD); }
  mi operator*(long long rs) { return mod(value * rs); }
  mi operator/(long long rs) { return mod(value * inv(rs)); }
  mi& operator+=(long long rs) {
    *this = (*this) + rs;
    return *this;
  }
  mi& operator-=(long long rs) {
    *this = (*this) - rs;
    return *this;
  }
  mi& operator*=(long long rs) {
    *this = (*this) * rs;
    return *this;
  }
  mi& operator/=(long long rs) {
    *this = (*this) / rs;
    return *this;
  }
  operator long long&() { return value; }
  long long value;
};
void program();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  program();
}
const int MX = 6e5;
int n, k, m, l[MX], r[MX], x[MX];
int a[MX];
int cb;
int SEGA[MX * 4];
int mn[MX];
long long dpSum[MX];
void addSegA(int i, int j, int x, int p = 0, int l = 0, int r = n) {
  if (j < l || i > r) return;
  if (i <= l && j >= r) {
    SEGA[p] |= x;
    return;
  }
  int m = (l + r) / 2;
  addSegA(i, j, x, p * 2 + 1, l, m);
  addSegA(i, j, x, p * 2 + 2, m + 1, r);
}
int getSegA(int i, int p = 0, int l = 0, int r = n) {
  if (i < l || i > r) return 0;
  if (l == r) return SEGA[p];
  int m = (l + r) / 2;
  int a = getSegA(i, p * 2 + 1, l, m);
  int b = getSegA(i, p * 2 + 2, m + 1, r);
  return a | b | SEGA[p];
}
void program() {
  cin >> n >> k >> m;
  for (int i = int(0); i < int(m); i++)
    cin >> l[i] >> r[i] >> x[i], l[i]--, r[i]--;
  for (int i = int(0); i < int((n + 1) * 4); i++) SEGA[i] = 0;
  for (int i = int(0); i < int(m); i++) addSegA(l[i], r[i], x[i]);
  for (int i = int(0); i < int(n + 1); i++) a[i] = getSegA(i);
  mi ans = 1;
  for (int currentBit = int(0); currentBit < int(k); currentBit++) {
    cb = currentBit;
    for (int i = int(0); i < int(n + 1); i++) mn[i] = -1;
    for (int i = int(0); i < int(m); i++) {
      if (x[i] & (1 << cb)) continue;
      mn[r[i] + 1] = max(mn[r[i] + 1], l[i]);
    }
    for (int i = int(1); i < int(n + 1); i++) mn[i] = max(mn[i], mn[i - 1]);
    for (int i = int(0); i < int(n + 1); i++) {
      long long cur = 0;
      if ((a[i] & (1 << cb)) == 0) {
        if (i != 0) cur = dpSum[i - 1];
        if (mn[i] >= 1) cur -= dpSum[mn[i] - 1];
        if (mn[i] == -1) cur++;
        cur %= MOD;
      }
      if (i == 0)
        dpSum[i] = cur;
      else
        dpSum[i] = dpSum[i - 1] + cur;
    }
    mi mult = dpSum[n] - dpSum[n - 1];
    ans *= mult;
  }
  cout << ans << endl;
}
