#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5, mod = 998244353;
int n, m, K, set_zero;
int l[maxn], r[maxn], x[maxn][50], c[maxn], key[maxn];
long long dp[maxn], sum[maxn];
inline int lower_bit(int x) { return x & (-x); }
void insert(int k, int x) {
  for (int i = k; i <= n; i += lower_bit(i)) c[i] += x;
}
int ask(int x) {
  int ss = 0;
  while (x) {
    ss += c[x];
    x -= lower_bit(x);
  }
  return ss;
}
int main() {
  int y;
  scanf("%d%d%d", &n, &K, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &l[i], &r[i], &y);
    for (int k = 0; k < K; k++) {
      x[i][k] = y % 2;
      y /= 2;
    }
  }
  long long ans = 1;
  for (int k = 0; k < K; k++) {
    for (int i = 1; i <= n + 1; i++)
      c[i] = 0, key[i] = 0, dp[i] = 0, sum[i] = 0;
    for (int i = 1; i <= m; i++) {
      if (x[i][k])
        insert(l[i], 1), insert(r[i] + 1, -1);
      else
        key[r[i]] = max(key[r[i]], l[i]);
    }
    dp[0] = 1;
    set_zero = -1;
    sum[0] = 1;
    for (int i = 1; i <= n; i++) {
      if (ask(i))
        dp[i] = 0;
      else
        dp[i] = (sum[i - 1] - (set_zero >= 0 ? sum[set_zero] : 0) + mod) % mod;
      sum[i] = (sum[i - 1] + dp[i]) % mod;
      if (key[i]) set_zero = max(set_zero, key[i] - 1);
    }
    ans = ans * ((sum[n] - (set_zero >= 0 ? sum[set_zero] : 0) + mod) % mod) %
          mod;
  }
  cout << ans;
  return 0;
}
