#include <bits/stdc++.h>
using namespace std;
int read() {
  int sum = 0, f = 1;
  char st = getchar();
  while (st < '0' || st > '9') {
    if (st == '-') f = -1;
    st = getchar();
  }
  while ('0' <= st && st <= '9') {
    sum = (sum << 3) + (sum << 1) + st - '0';
    st = getchar();
  }
  return sum * f;
}
int n, m, k;
int b[500010], c[500010];
bool v[500010];
long long f[500010];
struct qqq {
  int l, r, x;
} a[500010];
const int mod = 998244353;
int main() {
  cin >> n >> k >> m;
  for (int i = 1; i <= m; i++) {
    a[i].l = read(), a[i].r = read(), a[i].x = read();
  }
  long long an = 1;
  for (int p = 0; p < k; ++p) {
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    for (int i = 1; i <= m; ++i) {
      int x = a[i].x & 1;
      a[i].x >>= 1;
      if (x)
        b[a[i].l]++, b[a[i].r + 1]--;
      else
        c[a[i].r] = max(c[a[i].r], a[i].l);
    }
    for (int i = 1; i <= n; ++i) {
      b[i] += b[i - 1];
      c[i] = max(c[i - 1], c[i]);
    }
    long long sum = 1, ans = 0;
    f[0] = 1;
    int l = 0;
    for (int i = 1; i <= n; ++i) {
      f[i] = 0;
      if (b[i]) continue;
      while (l < c[i - 1]) {
        sum = (sum - f[l] + mod) % mod;
        f[l++] = 0;
      }
      f[i] = sum;
      sum = (sum + f[i]) % mod;
    }
    while (l < c[n]) f[l++] = 0;
    for (int i = 0; i <= n; i++) {
      ans = (ans + f[i]) % mod;
    }
    an = an * ans % mod;
  }
  cout << an << endl;
  return 0;
}
