#include <bits/stdc++.h>
using namespace std;
const int maxN = 5e5 + 10, mod = 998244353;
struct Node {
  int l, r, x;
} a[maxN + 1];
int n, m, k;
int f[maxN + 1];
int s[maxN + 1], L[maxN + 1];
inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int SUB(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
inline int solve(int t) {
  for (int i = 0; i <= n + 1; i++) s[i] = f[i] = L[i] = 0;
  for (int i = 1; i <= m; i++)
    if (a[i].x & (1 << t))
      s[a[i].l]++, s[a[i].r + 1]--;
    else
      L[a[i].r] = max(L[a[i].r], a[i].l);
  int sum, now = 0;
  sum = f[0] = 1;
  for (int i = 1; i <= n; i++) {
    s[i] += s[i - 1];
    if (!s[i]) f[i] = sum, sum = ADD(sum, f[i]);
    while (now < L[i]) sum = SUB(sum, f[now]), now++;
  }
  return sum;
}
int main() {
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 1; i <= m; i++) scanf("%d %d %d", &a[i].l, &a[i].r, &a[i].x);
  int ans = 1;
  for (int i = 0; i < k; i++) ans = 1ll * ans * solve(i) % mod;
  printf("%d", ans);
  return 0;
}
