#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  int ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
inline int add(int x, int y) {
  return x + y >= 998244353 ? x + y - 998244353 : x + y;
}
inline int sub(int x, int y) { return x - y < 0 ? x - y + 998244353 : x - y; }
inline int mul(int x, int y) { return 1LL * x * y % 998244353; }
int n, k, m, ans;
int l[500005], r[500005], x[500005], f[500005], lim[500005], a[500005];
int solve(int u) {
  memset(f, 0, sizeof(f));
  memset(a, 0, sizeof(a));
  memset(lim, 0, sizeof(lim));
  for (int i = 1; i <= m; i++) {
    if (x[i] & (1 << u))
      a[l[i]]++, a[r[i] + 1]--;
    else
      lim[r[i]] = max(lim[r[i]], l[i]);
  }
  for (int i = 1; i <= n + 1; i++) a[i] += a[i - 1];
  f[0] = 1;
  int l = 0, sum = 1;
  for (int i = 1; i <= n + 1; i++) {
    while (l < lim[i - 1]) sum = sub(sum, f[l++]);
    if (a[i]) continue;
    f[i] = sum;
    sum = add(sum, f[i]);
  }
  return f[n + 1];
}
signed main() {
  cin >> n >> k >> m;
  for (int i = 1; i <= m; i++) l[i] = read(), r[i] = read(), x[i] = read();
  ans = 1;
  for (int i = 0; i < k; i++) ans = mul(ans, solve(i));
  cout << ans << endl;
  return 0;
}
