#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
const int mod = 998244353;
int l[N], r[N], x[N], a[N], pos[N];
long long f[N];
int main() {
  int n, m, k;
  long long ans = 1;
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &l[i], &r[i], &x[i]);
    r[i]++;
  }
  for (int p = 0; p < k; p++) {
    for (int i = 1; i <= n + 2; i++) a[i] = pos[i] = f[i] = 0;
    for (int i = 1; i <= m; i++) {
      if ((x[i] >> p) & 1)
        a[l[i]]++, a[r[i]]--;
      else
        pos[r[i]] = max(pos[r[i]], l[i]);
    }
    for (int i = 2; i <= n + 1; i++)
      a[i] += a[i - 1], pos[i] = max(pos[i], pos[i - 1]);
    f[0] = 1;
    int sum = 1, l = 0;
    for (int i = 1; i <= n + 1; i++) {
      while (l < pos[i]) sum = (sum + (mod - f[l])) % mod, f[l] = 0, ++l;
      f[i] = a[i] ? 0 : sum;
      sum = (sum + f[i]) % mod;
    }
    ans = ans * f[n + 1] % mod;
  }
  printf("%lld\n", ans);
}
