#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
const int mod = 998244353;
int n, k, m, l[N], r[N], x[N];
int s[N], asd[N];
long long dp[N];
long long solve() {
  dp[0] = 1;
  int cur = 0, j = 0;
  long long sum = 1;
  for (int i = 1; i <= n; i++) {
    cur = cur + s[i];
    if (cur == 0) dp[i] = sum;
    while (j < asd[i]) {
      sum = (sum - dp[j] + mod) % mod;
      dp[j] = 0;
      j++;
    }
    sum = (sum + dp[i]) % mod;
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k >> m;
  for (int i = 1; i <= m; i++) cin >> l[i] >> r[i] >> x[i];
  long long res = 1;
  for (int bit = 0; bit < k; bit++) {
    for (int i = 1; i <= n; i++) {
      dp[i] = 0;
      s[i] = 0;
      asd[i] = 0;
    }
    for (int i = 1; i <= m; i++) {
      if (x[i] >> bit & 1) {
        s[l[i]]++;
        s[r[i] + 1]--;
      } else
        asd[r[i]] = max(asd[r[i]], l[i]);
    }
    res = (res * solve()) % mod;
  }
  cout << res;
}
