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;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T maxs(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T mins(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
template <long long mod>
struct mint {
  long long first;
  mint() : first(0) {}
  mint(long long first) : first((first % mod + mod) % mod) {}
  mint& fix() {
    first = (first % mod + mod) % mod;
    return *this;
  }
  mint operator-() const { return mint(0) - *this; }
  mint& operator+=(const mint& a) {
    if ((first += a.first) >= mod) first -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((first += mod - a.first) >= mod) first -= mod;
    return *this;
  }
  mint& operator*=(const mint& a) {
    (first *= a.first) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const { return mint(*this) += a; }
  mint operator-(const mint& a) const { return mint(*this) -= a; }
  mint operator*(const mint& a) const { return mint(*this) *= a; }
  bool operator<(const mint& a) const { return first < a.first; }
  bool operator==(const mint& a) const { return first == a.first; }
  friend istream& operator>>(istream& i, mint& a) {
    i >> a.first;
    return i;
  }
  friend ostream& operator<<(ostream& o, const mint& a) {
    o << a.first;
    return o;
  }
  mint<mod> expo(mint<mod> first, long long second) {
    mint<mod> a = 1;
    while (second) {
      if (second & 1) a = a * first;
      first = first * first;
      second /= 2;
    }
    return a;
  }
};
template <long long mod>
long long operator+=(long long& b, mint<mod> a) {
  return b = b + a.first;
};
long long a[500005];
vector<pair<pair<long long, long long>, long long>> v;
mint<998244353> dp[500005];
mint<998244353> pre[500005];
long long last[500005];
long long solve() {
  long long n, k, m;
  cin >> n >> k >> m;
  v.resize(m);
  for (long long i = 0; i < m; i++) cin >> v[i].first >> v[i].second;
  mint<998244353> ans = 1;
  for (long long j = 0; j < k; j++) {
    for (long long i = 0; i <= n + 1; i++) a[i] = 0, last[i] = 0;
    for (long long i = 0; i < m; i++) {
      long long first = v[i].second;
      if ((first & (1 << j)))
        a[v[i].first.first]++, a[v[i].first.second + 1]--;
      else
        maxs(last[v[i].first.second + 1], v[i].first.first);
    }
    for (long long i = 1; i <= n + 1; i++) a[i] += a[i - 1];
    for (long long i = 1; i <= n + 1; i++) maxs(last[i], last[i - 1]);
    for (long long i = 0; i <= n + 1; i++) dp[i] = pre[i] = 0;
    dp[0] = 1;
    pre[0] = 1;
    for (long long i = 1; i <= n + 1; i++) {
      if (a[i])
        dp[i] = 0;
      else {
        dp[i] = dp[i] + pre[i - 1];
        if (last[i] != 0) dp[i] -= pre[last[i] - 1];
      }
      pre[i] += (dp[i] + pre[i - 1]);
    }
    ans = ans * dp[n + 1];
  }
  cout << ans << "\n";
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
