#include <bits/stdc++.h>
using namespace std;
const long long maxm = 5e5 + 5;
const long long mod = 998244353;
struct Node {
  long long l, r, x;
} e[maxm];
long long cnt[maxm];
long long pre[maxm];
long long d[maxm];
long long n, k, m;
long long ans = 1;
long long solve(long long now) {
  for (long long i = 0; i <= n; i++) d[i] = pre[i] = cnt[i] = 0;
  for (long long i = 1; i <= m; i++) {
    if (e[i].x >> now & 1)
      cnt[e[i].l]++, cnt[e[i].r + 1]--;
    else
      pre[e[i].r] = max(pre[e[i].r], e[i].l);
  }
  for (long long i = 1; i <= n; i++) cnt[i] += cnt[i - 1];
  long long sum = d[0] = 1, last = 0;
  for (long long i = 1; i <= n; i++) {
    if (!cnt[i]) d[i] = sum, sum = sum * 2 % mod;
    while (last < pre[i]) sum = (sum - d[last] + mod) % mod, last++;
  }
  return sum;
}
signed main() {
  cin >> n >> k >> m;
  for (long long i = 1; i <= m; i++) cin >> e[i].l >> e[i].r >> e[i].x;
  for (long long i = 0; i < k; i++) ans = ans * solve(i) % mod;
  cout << ans << endl;
  return 0;
}
