#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
const int INF = 0x3f3f3f3f;
const long long mod = 998244353;
int n, k, m;
int x[maxn], l[maxn], r[maxn];
long long dp[maxn];
int a[maxn], b[maxn];
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= m; ++i) scanf("%d%d%d", &l[i], &r[i], &x[i]);
  long long ans = 1;
  dp[0] = 1;
  for (int t = 0; t < k; t++) {
    for (int i = 1; i <= n + 1; i++) a[i] = 0, b[i] = 0;
    for (int i = 1; i <= m; i++) {
      if (x[i] >> t & 1)
        a[l[i]]++, a[r[i] + 1]--;
      else
        b[r[i] + 1] = max(b[r[i] + 1], l[i]);
    }
    for (int i = 1; i <= n + 1; i++) {
      a[i] += a[i - 1];
      b[i] = max(b[i], b[i - 1]);
    }
    for (int i = 1; i <= n + 1; i++) {
      if (!a[i]) {
        dp[i] = dp[i - 1];
        if (b[i]) dp[i] = (dp[i] - dp[b[i] - 1] + mod) % mod;
      } else
        dp[i] = 0;
      dp[i] = (dp[i - 1] + dp[i]) % mod;
    }
    ans = ans * (dp[n + 1] - dp[n] + mod) % mod;
  }
  cout << ans << endl;
}
