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 int INF = (is_same<int, long long>::value ? 1e18 + 666 : 1e9 + 666);
template <class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void UseFiles(const string &s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
void run();
signed main() {
  iostream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  run();
}
const int mod = 998244353;
vector<pair<int, int>> remove_inside(const vector<pair<int, int>> &v) {
  int mx = -INF;
  vector<pair<int, int>> ans;
  for (auto &[l, r] : v) {
    if (cmax(mx, r)) {
      ans.push_back({l, r});
    }
  }
  return ans;
}
vector<pair<int, int>> remove_outside(const vector<pair<int, int>> &v) {
  vector<pair<int, int>> ans;
  for (int i = ((int)(v).size()) - 1; i > -1; --i) {
    if (((int)(ans).size()) && v[i].second >= ans.back().second) {
      continue;
    }
    ans.push_back(v[i]);
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
int solve(int n, const vector<pair<int, int>> &segs0,
          const vector<pair<int, int>> &segs1) {
  int it0 = 0, it1 = 0;
  vector<int> dp(n + 2, 0);
  dp[0] = 1;
  for (int i = 1; i <= n + 1; ++i) {
    while (it0 < ((int)(segs0).size()) && segs0[it0].second < i) {
      ++it0;
    }
    while (it1 < ((int)(segs1).size()) && segs1[it1].second < i) {
      ++it1;
    }
    int l = 0;
    if (it0 > 0) {
      l = segs0[it0 - 1].first + 1;
    }
    dp[i] = dp[i - 1];
    if (l > 0) {
      dp[i] -= dp[l - 1];
      if (dp[i] < 0) {
        dp[i] += mod;
      }
    }
    if (it1 < ((int)(segs1).size()) && segs1[it1].first < i) {
      dp[i] = 0;
    }
    dp[i] += dp[i - 1];
    if (dp[i] >= mod) {
      dp[i] -= mod;
    }
  }
  return (dp.back() - dp[n] + mod) % mod;
}
void run() {
  int n, m, k;
  cin >> n >> k >> m;
  vector<array<int, 3>> segs(m);
  for (auto &[l, r, x] : segs) {
    cin >> l >> r >> x;
    --l;
  }
  sort(segs.begin(), segs.end(),
       [](const array<int, 3> &a, const array<int, 3> &b) {
         if (a[0] != b[0]) {
           return a < b;
         }
         return a > b;
       });
  long long ans = 1;
  vector<pair<int, int>> segs0, segs1;
  for (int i = 0; i < k; ++i) {
    for (auto &[l, r, x] : segs) {
      if (x & (1 << i)) {
        segs1.push_back({l, r});
      } else {
        segs0.push_back({l, r});
      }
    }
    segs0 = remove_outside(segs0);
    segs1 = remove_inside(segs1);
    ans *= solve(n, segs0, segs1);
    ans %= mod;
    segs0.clear();
    segs1.clear();
  }
  cout << ans << endl;
}
