#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 5e5 + 5, M = 998244353;
int n, k, m, ls[N], rs[N], xs[N];
int solve(int bit) {
  vector<int> dp(n + 2), a(n + 2), asum(n + 2), dpsum(n + 2), f(n + 2);
  vector<pii> ranges;
  for (int i = 1; i <= m; ++i) {
    if (xs[i] & 1 << bit) {
      ++a[ls[i]], --a[rs[i] + 1];
    } else {
      ranges.emplace_back(ls[i], rs[i]);
    }
  }
  sort(ranges.begin(), ranges.end(),
       [](pii x, pii y) { return x.second < y.second; });
  for (int i = 1, idx = 0; i <= n + 1; ++i) {
    f[i] = f[i - 1];
    while (idx < ranges.size() && ranges[idx].second < i) {
      f[i] = max(f[i], ranges[idx++].first);
    }
  }
  partial_sum(a.begin() + 1, a.begin() + 1 + n, asum.begin() + 1);
  dp[0] = dpsum[0] = 1;
  for (int i = 1; i <= n + 1; ++i) {
    if (asum[i]) {
      dp[i] = 0;
    } else {
      dp[i] = (dpsum[i - 1] - (f[i] ? dpsum[f[i] - 1] : 0) + M) % M;
    }
    dpsum[i] = (dpsum[i - 1] + dp[i]) % M;
  }
  return dp[n + 1];
}
int main() {
  cin >> n >> k >> m;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &ls[i], &rs[i], &xs[i]);
  }
  int ans = 1;
  for (int i = 0; i < k; ++i) ans = 1ll * ans * solve(i) % M;
  cout << ans << endl;
}
