#include <bits/stdc++.h>
const int maxn = 500005, maxk = 31, mod = 998244353;
int n, k, m, ans;
int cnt[maxk][maxn], maxx[maxk][maxn], f[maxn];
inline int max(int a, int b) { return a > b ? a : b; }
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= m; i++) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    for (int j = 0; j < k; j++) {
      if ((x >> j) & 1)
        cnt[j][l]++, cnt[j][r + 1]--;
      else
        maxx[j][r + 1] = max(maxx[j][r + 1], l);
    }
  }
  for (int i = 0; i < k; i++)
    for (int j = 1; j <= n + 1; j++) {
      cnt[i][j] += cnt[i][j - 1];
      maxx[i][j] = max(maxx[i][j], maxx[i][j - 1]);
    }
  ans = 1;
  for (int i = 0; i < k; i++) {
    int pos = 0, sum = 0;
    for (int j = 0; j <= n + 1; j++) f[j] = 0;
    f[0] = sum = 1;
    for (int j = 1; j <= n + 1; j++) {
      while (pos < maxx[i][j]) sum = (sum - f[pos] + mod) % mod, pos++;
      if (cnt[i][j] == 0)
        f[j] = sum;
      else
        f[j] = 0;
      sum = (sum + f[j]) % mod;
    }
    ans = 1ll * ans * f[n + 1] % mod;
  }
  printf("%d\n", ans);
  return 0;
}
