#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long n, k, m, ones[500010], ml[500010], sum[500010];
pair<pair<long long, long long>, long long> q[500010];
long long add(long long a, long long b) {
  a += b;
  if (a >= ((long long)998244353)) a -= ((long long)998244353);
  if (a < 0) a += ((long long)998244353);
  return a;
}
long long cal(long long k) {
  memset(ones, 0, sizeof(ones));
  memset(sum, 0, sizeof(sum));
  memset(ml, -1, sizeof(ml));
  for (long long i = 0; i < m; i++) {
    if (q[i].second & (1 << k)) {
      ones[q[i].first.first]++;
      ones[q[i].first.second + 1]--;
    } else {
      ml[q[i].first.second] = max(q[i].first.first, ml[q[i].first.second]);
    }
  }
  long long j = -1;
  for (long long i = 0; i < n; i++) {
    long long s = 0;
    if (!ones[i]) {
      s = sum[i];
      if (j == -1)
        s = add(s, 1);
      else
        s = add(s, -sum[j]);
    }
    sum[i + 1] = add(sum[i], s);
    ones[i + 1] += ones[i];
    j = max(j, ml[i]);
  }
  return add(sum[n], j == -1 ? 1 : -sum[j]);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> m;
  for (long long i = 0; i < m; i++) {
    cin >> q[i].first.first >> q[i].first.second >> q[i].second;
    q[i].first.first--, q[i].first.second--;
  }
  long long ans = 1;
  for (long long i = 0; i < k; i++)
    ans = (ans * cal(i)) % ((long long)998244353);
  cout << ans << '\n';
  return 0;
}
