#include <bits/stdc++.h>
using namespace std;
const int MD = 998244353;
const int M = 5e5 + 100;
int n, m, k;
int l[M], r[M], x[M], p2[M];
bool check(vector<int> &v) {
  for (int i = 0; i < m; i++) {
    int a = -1;
    for (int j = l[i]; j <= r[i]; j++) a &= v[j];
    if (a != x[i]) return false;
  }
  return true;
}
int acc;
void gen(vector<int> &t) {
  if (t.size() == n) {
    if (check(t)) {
      for (auto &x : t) cerr << x << " ";
      cerr << "\n";
      acc++;
    }
    return;
  }
  for (int x = 0; x < 1 << k; x++) {
    t.push_back(x);
    gen(t);
    t.pop_back();
  }
}
void solve() {
  acc = 0;
  vector<int> t;
  gen(t);
  cerr << "ans: " << acc << "\n";
}
int main() {
  p2[0] = 1;
  for (int i = 1; i < M; i++) p2[i] = p2[i - 1] * 2ll % MD;
  while (scanf("%d %d %d", &n, &k, &m) == 3) {
    for (int i = 0; i < m; i++) scanf("%d %d %d", &l[i], &r[i], &x[i]);
    for (int i = 0; i < m; i++) l[i]--, r[i]--;
    vector<int> ids(m, 0);
    for (int i = 0; i < m; i++) ids[i] = i;
    sort(ids.begin(), ids.end(), [](int i, int j) -> bool {
      return r[i] == r[j] ? l[i] < l[j] : r[i] < r[j];
    });
    int res = 1;
    for (int ib = 0; ib < k; ib++) {
      vector<int> ids0, ids1;
      for (auto &id : ids)
        if (x[id] >> ib & 1)
          ids1.push_back(id);
        else
          ids0.push_back(id);
      vector<int> dp(n + 1, 1), s(n + 1, 0), sdp(n + 1, 0);
      int i1 = (int)ids1.size() - 1, left = n;
      for (int i = n - 1; i >= 0; i--) {
        while (i1 >= 0 && r[ids1[i1]] == i) left = min(left, l[ids1[i1--]]);
        if (i >= left) s[i] = 1;
      }
      for (int i = 1; i <= n; i++) s[i] += s[i - 1];
      int i0 = 0, le = -1, ri = -1;
      for (int i = 0; i <= n; i++) {
        if (s[i] - (i ? s[i - 1] : 0) == 1)
          dp[i] = 0;
        else if (i0 == 0)
          dp[i] = p2[i - (i ? s[i - 1] : 0)];
        else
          dp[i] = 1ll * (sdp[ri] - (le ? sdp[le - 1] : 0) + MD) % MD *
                  p2[i - ri - 1 - s[i - 1] + s[ri]] % MD;
        while (i0 < ids0.size() && r[ids0[i0]] == i) {
          int id = ids0[i0];
          if (s[r[id]] - (l[id] ? s[l[id] - 1] : 0) == r[id] - l[id] + 1)
            res = 0;
          le = max(le, l[id]), ri = max(ri, r[id]);
          i0++;
        }
        sdp[i] = ((i ? sdp[i - 1] : 0) + dp[i]) % MD;
      }
      int tres = dp[n];
      res = 1ll * res * tres % MD;
    }
    printf("%d\n", res);
  }
  return 0;
}
