#include <bits/stdc++.h>
using namespace std;
bool __hack = std::ios::sync_with_stdio(false);
auto __hack1 = cin.tie(nullptr);
template <class T>
inline bool get_bit(T mask, int bit) {
  assert(0 <= bit && bit < numeric_limits<T>::digits);
  return mask & ((T)(1) << bit);
}
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N>
struct bytetype {};
template <uint64_t N>
struct minimal_uint : bytetype<bytecount(N)> {};
}  // namespace template_util
template <class T>
T next(istream& in) {
  T ret;
  in >> ret;
  return ret;
}
const int MOD = 998244353;
int64_t solveOneBit(int n, const vector<pair<pair<int, int>, int>>& queries,
                    int bit) {
  vector<int> sum(n + 1, 0);
  vector<int> ri(n + 1, -1);
  for (auto& p : queries) {
    if (get_bit(p.second, bit)) {
      ++sum[p.first.first];
      --sum[p.first.second];
    } else {
      ri[p.first.second] = max(ri[p.first.second], p.first.first);
    }
  }
  for (int i = 0; i < (n); ++i) {
    sum[i + 1] += sum[i];
  }
  vector<int64_t> dp0(n + 1, 0);
  dp0[0] = 1;
  int64_t s = 1;
  int ptr = 0;
  for (int i = 1; i <= n; ++i) {
    if (sum[i - 1] == 0) {
      dp0[i] = s;
    }
    if (ri[i] != -1) {
      while (ri[i] >= ptr) {
        s -= dp0[ptr];
        dp0[ptr] = 0;
        if (s < 0) {
          s += MOD;
        }
        ++ptr;
      }
    }
    s += dp0[i];
    s %= MOD;
  }
  return s;
}
void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto countBits = next<int>(in);
  auto m = next<int>(in);
  vector<pair<pair<int, int>, int>> queries(m);
  for (int i = 0; i < (m); ++i) {
    auto le = next<int>(in) - 1;
    auto ri = next<int>(in);
    auto x = next<int>(in);
    queries[i] = {{le, ri}, x};
  }
  int64_t res = 1;
  for (int bit = 0; bit < (countBits); ++bit) {
    res = res * solveOneBit(n, queries, bit);
    res = res % MOD;
  }
  out << res << "\n";
}
int main() {
  solve(cin, cout);
  return 0;
}
