#include <bits/stdc++.h>
using namespace std;
int add(int x, int y) { return ((x + y) % 998244353 + 998244353) % 998244353; }
int mul(int x, int y) { return (long long)x * y % 998244353; }
int maxL[500005];
int L[500005], R[500005], x[500005];
int dp[500005];
int p[500005];
int solveDp(int n, int m, int k, int bit) {
  for (int i = 1; i <= n; ++i) {
    p[i] = 0;
    maxL[i] = 0;
    dp[i] = 0;
  }
  for (int i = 0; i < m; ++i) {
    if (x[i] & (1 << bit)) {
      p[L[i]] += 1;
      p[R[i] + 1] -= 1;
    } else {
      maxL[R[i]] = max(maxL[R[i]], L[i]);
    }
  }
  for (int i = 1; i <= n; ++i) {
    p[i] += p[i - 1];
  }
  int myLeft = 0;
  dp[0] = 1;
  int sum = dp[0];
  for (int i = 1; i <= n; ++i) {
    if (p[i]) {
    } else {
      dp[i] = sum;
      sum = add(sum, dp[i]);
    }
    while (myLeft < maxL[i]) {
      sum = add(sum, -dp[myLeft]);
      ++myLeft;
    }
  }
  return sum;
}
void solve() {
  int n, k, m;
  scanf("%d %d %d ", &n, &k, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d ", &L[i], &R[i], &x[i]);
  }
  int ret = 1;
  for (int i = 0; i < k; ++i) {
    ret = mul(ret, solveDp(n, m, k, i));
  }
  printf("%d\n", ret);
}
int main() {
  solve();
  return 0;
}
