#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  const int MOD = 998244353;
  int n, k, m;
  while (cin >> n >> k >> m) {
    vector<vector<tuple<int, int, int>>> events(n + 2);
    for (int i = 0; i < m; ++i) {
      int l, r, x;
      cin >> l >> r >> x;
      events[l].emplace_back(0, x, i);
      events[r + 1].emplace_back(l, x, i);
    }
    ll res = 1;
    for (int bit = 1; bit < (1 << k); bit <<= 1) {
      int cnt1 = 0;
      vector<char> ones(n + 2);
      for (int i = 1; i <= n; ++i) {
        for (auto [open, x, idx] : events[i]) {
          if (x & bit) {
            cnt1 += (open ? -1 : +1);
          }
        }
        if (cnt1) {
          ones[i] = true;
        }
      }
      int right_start = 0;
      vector<int> dp(n + 2);
      vector<int> pref(n + 3);
      dp[0] = 1;
      pref[1] = 1;
      auto getsum = [&](int l, int r) {
        return (pref[1 + r] - pref[l] + MOD) % MOD;
      };
      for (int i = 1; i <= n + 1; ++i) {
        pref[1 + i] = pref[i];
        for (auto [open, x, idx] : events[i]) {
          if (!(x & bit) && open) {
            right_start = max(right_start, open);
          }
        }
        if (ones[i]) continue;
        dp[i] = getsum(right_start, i - 1);
        pref[1 + i] = (pref[1 + i] + dp[i]) % MOD;
      }
      res = res * dp[n + 1] % MOD;
    }
    cout << res << "\n";
  }
}
