#include <bits/stdc++.h>
using namespace std;
long long n, k, m;
int l[500005], r[500005], x[500005];
int b[500005], dif[500005];
long long dp[500005], sum[500005];
vector<int> vec[500005];
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> m;
  for (int i = 1; i <= m; i++) {
    cin >> l[i] >> r[i] >> x[i];
  }
  for (int i = 0; i < k; i++) {
    for (int j = 1; j <= n; j++) dif[j] = 0;
    for (int j = 1; j <= m; j++) {
      if ((x[j] & (1 << i)) == 0) continue;
      dif[l[j]]++;
      dif[r[j] + 1]--;
    }
    for (int j = 1; j <= n; j++) dif[j] += dif[j - 1];
    for (int j = 1; j <= n; j++) {
      if (dif[j]) b[j] |= 1 << i;
    }
  }
  long long ans = 1;
  dp[0] = sum[0] = 1;
  for (int i = 0; i < k; i++) {
    for (int j = 1; j <= n; j++) vec[j].clear();
    for (int j = 1; j <= m; j++) {
      if (x[j] & (1 << i)) continue;
      vec[r[j]].push_back(l[j]);
    }
    int lb = 0;
    for (int j = 1; j <= n; j++) {
      dp[j] = 0;
      if ((b[j] & (1 << i)) == 0) {
        dp[j] = sum[j - 1];
        if (lb > 0) {
          dp[j] += 998244353 - sum[lb - 1];
          if (dp[j] >= 998244353) dp[j] -= 998244353;
        }
      }
      sum[j] = sum[j - 1] + dp[j];
      if (sum[j] >= 998244353) sum[j] -= 998244353;
      for (int k = 0; k < vec[j].size(); k++) lb = max(lb, vec[j][k]);
    }
    long long tmp = sum[n];
    if (lb > 0) tmp += 998244353 - sum[lb - 1], tmp %= 998244353;
    ans *= tmp, ans %= 998244353;
  }
  cout << ans << endl;
  return 0;
}
