#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1, mod = 998244353;
int n, k, m, valq[N];
int cnt[30][N], prv[30][N], dp[30][N];
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
int binpow(int a, int b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  int ret = binpow(a, b / 2);
  if (b % 2 == 0) return 1LL * ret * ret % mod;
  return 1LL * ret * ret % mod * a % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> m;
  for (int i = 1; i <= m; i++) {
    int l, r;
    cin >> l >> r >> valq[i];
    for (int j = 0; j < k; j++) {
      if (valq[i] & (1 << j)) {
        cnt[j][l]++, cnt[j][r + 1]--;
      } else {
        prv[j][r] = max(prv[j][r], l);
      }
    }
  }
  int ans = 1;
  for (int i = 0; i < k; i++) {
    dp[i][0] = 1;
    int sum = 0, pos = 0;
    for (int j = 1; j <= n; j++) {
      sum += cnt[i][j];
      if (sum > 0)
        dp[i][j] = dp[i][j - 1];
      else
        dp[i][j] =
            sub(2LL * dp[i][j - 1] % mod, (pos - 1 >= 0 ? dp[i][pos - 1] : 0));
      if (prv[i][j] != 0) pos = max(pos, prv[i][j]);
    }
    ans = 1LL * ans * sub(dp[i][n], (pos - 1 >= 0 ? dp[i][pos - 1] : 0)) % mod;
  }
  cout << ans;
}
