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 long long MOD = 998244353;
mt19937_64 rnd(time(0));
vector<pair<int, int> > v[2][31];
long long n, m, k, d, T, Q, a[600001], pr[600001];
bool tt[600001];
long long binpow(long long h, long long r, long long md = MOD) {
  long long l = 1;
  while (r) {
    if (r & 1) l *= h, l %= md;
    h *= h;
    h %= md;
    r /= 2;
  }
  return l;
}
long long gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (x && y) {
    x %= y;
    swap(x, y);
  }
  return x + y;
}
long long solve(int h) {
  vector<pair<int, int> > v0 = v[0][h], v1 = v[1][h];
  long long mx = 0;
  for (int i = 1; i <= n; i++) a[i] = 0, tt[i] = 0;
  for (int i = 0; i < v1.size(); i++)
    a[v1[i].first] = max((long long)v1[i].second, a[v1[i].first]);
  long long p = 0;
  for (int i = 1; i <= n; i++) {
    p = max(p, a[i]);
    if (i > p) tt[i] = 1;
  }
  for (int i = 1; i <= n; i++) a[i] = 0;
  for (int i = 0; i < v0.size(); i++) {
    a[v0[i].second + 1] = max((long long)v0[i].first, a[v0[i].second + 1]);
    mx = max(mx, (long long)v0[i].first);
  }
  for (int i = 1; i <= n; i++) a[i] = max(a[i], a[i - 1]);
  pr[0] = 1;
  long long l = 0;
  if (mx == 0) l = 1;
  for (int i = 1; i <= n; i++) {
    if (tt[i]) {
      long long o = 0;
      if (a[i] == 0)
        o = pr[i - 1];
      else
        o = pr[i - 1] - pr[a[i] - 1];
      if (o < 0) o += MOD;
      pr[i] = pr[i - 1] + o;
      pr[i] %= MOD;
      if (i >= mx) l += o, l %= MOD;
    } else
      pr[i] = pr[i - 1], pr[i] %= MOD;
  }
  return l;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> m;
  for (int i = 1; i <= m; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    long long j = 0;
    while (j < k) {
      v[z % 2][j].push_back(make_pair(x, y));
      j++;
      z /= 2;
    }
  }
  long long ans = 1;
  for (int i = 0; i < k; i++) {
    ans *= (solve(i));
    ans %= MOD;
  }
  cout << ans << "\n";
  return 0;
}
