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;
long long mod = 1000000007;
long long mod2 = 998244353;
long long mod3 = 1000003;
long long mod4 = 998244853;
long long mod5 = 1000000009;
long long inf = 1LL << 60;
double pi = 3.141592653589793238462643383279L;
double eps = 1e-14;
int dh[4] = {1, -1, 0, 0};
int dw[4] = {0, 0, 1, -1};
int ddh[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int ddw[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
long long Pow(long long n, long long k) {
  long long ret = 1;
  long long now = n;
  while (k > 0) {
    if (k & 1) ret *= now;
    now *= now;
    k /= 2;
  }
  return ret;
}
long long beki(long long n, long long k, long long md) {
  long long ret = 1;
  long long now = n;
  while (k > 0) {
    if (k % 2 == 1) {
      ret *= now;
      ret %= md;
    }
    now *= now;
    now %= md;
    k /= 2;
  }
  return ret;
}
long long gyaku(long long n, long long md) { return beki(n, md - 2, md); }
long long popcount(long long n) {
  long long ret = 0;
  long long u = n;
  while (u > 0) {
    ret += u % 2;
    u /= 2;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k, m;
  cin >> n >> k >> m;
  int l[m], r[m], x[m];
  vector<pair<int, int>> v[n + 1], w[n + 1];
  for (long long i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> x[i];
    v[l[i]].push_back({r[i], x[i]});
    w[r[i]].push_back({l[i], x[i]});
  }
  long long ans = 1;
  long long sum[n + 2];
  for (long long i = 0; i < k; i++) {
    int u = 1 << i;
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long>>,
                   greater<pair<long long, long long>>>
        q;
    fill(sum, sum + n + 2, 0);
    int las = 0;
    sum[0] = 0;
    sum[1] = 1;
    int cnt = 0;
    for (long long j = 1; j < n + 1; j++) {
      for (long long e = 0; e < v[j].size(); e++) {
        int num = v[j][e].second;
        num /= u;
        if (num % 2) {
          cnt++;
        }
      }
      if (cnt == 0) {
        sum[j + 1] = sum[j] - sum[las] + mod2;
        sum[j + 1] %= mod2;
        (sum[j + 1] += sum[j]) %= mod2;
      } else {
        sum[j + 1] = sum[j];
      }
      for (long long e = 0; e < w[j].size(); e++) {
        int num = w[j][e].second;
        num /= u;
        if (num % 2)
          cnt--;
        else
          las = max(las, w[j][e].first);
      }
    }
    long long summ = sum[n + 1] - sum[las] + mod2;
    summ %= mod2;
    (ans *= summ) %= mod2;
  }
  cout << ans << endl;
}
