#include <bits/stdc++.h>
using namespace std;
mt19937 mr(time(0));
struct LL {
  static const long long int m = 998244353;
  long long int val;
  LL(long long int v) { val = reduce(v); };
  LL(int v) { val = reduce((long long int)v); };
  LL() { val = 0; };
  ~LL(){};
  LL(const LL& l) { val = l.val; };
  LL& operator=(int l) {
    val = l;
    return *this;
  }
  LL& operator=(long long int l) {
    val = l;
    return *this;
  }
  LL& operator=(LL l) {
    val = l.val;
    return *this;
  }
  static long long int reduce(long long int x, long long int md = m) {
    x %= md;
    while (x >= md) x -= md;
    while (x < 0) x += md;
    return x;
  }
  bool operator<(const LL& b) { return val < b.val; }
  bool operator<=(const LL& b) { return val <= b.val; }
  bool operator==(const LL& b) { return val == b.val; }
  bool operator>=(const LL& b) { return val >= b.val; }
  bool operator>(const LL& b) { return val > b.val; }
  LL operator+(const LL& b) { return LL(val + b.val); }
  LL operator+(const long long int& b) { return (*this + LL(b)); }
  LL& operator+=(const LL& b) { return (*this = *this + b); }
  LL& operator+=(const long long int& b) { return (*this = *this + b); }
  LL operator-(const LL& b) { return LL(val - b.val); }
  LL operator-(const long long int& b) { return (*this - LL(b)); }
  LL& operator-=(const LL& b) { return (*this = *this - b); }
  LL& operator-=(const long long int& b) { return (*this = *this - b); }
  LL operator*(const LL& b) { return LL(val * b.val); }
  LL operator*(const long long int& b) { return (*this * LL(b)); }
  LL& operator*=(const LL& b) { return (*this = *this * b); }
  LL& operator*=(const long long int& b) { return (*this = *this * b); }
  static LL exp(const LL& x, const long long int& y) {
    long long int z = y;
    z = reduce(z, m - 1);
    LL ret = 1;
    LL w = x;
    while (z) {
      if (z & 1) ret *= w;
      z >>= 1;
      w *= w;
    }
    return ret;
  }
  LL& operator^=(long long int y) { return (*this = LL(val ^ y)); }
  LL operator/(const LL& b) { return ((*this) * exp(b, -1)); }
  LL operator/(const long long int& b) { return (*this / LL(b)); }
  LL operator/=(const LL& b) { return ((*this) *= exp(b, -1)); }
  LL& operator/=(const long long int& b) { return (*this = *this / LL(b)); }
};
ostream& operator<<(ostream& os, const LL& obj) { return os << obj.val; }
int T, N, M, K, Q, X, Y;
int rd() {
  int x;
  cin >> x;
  return x;
}
void fl() { cout.flush(); }
LL ret = 1;
LL DP[5 * 100010];
LL S[5 * 100010];
int P[5 * 100010];
vector<pair<pair<int, int>, int>> ps;
void panic() {
  cout << 0 << endl;
  exit(0);
}
int segtree[4 * 5 * 100010];
int range(int a, int b) {
  a += 5 * 100010;
  b += 5 * 100010;
  int ans = 0;
  while (a <= b) {
    if (a % 2 == 1) ans += segtree[a++];
    if (b % 2 == 0) ans += segtree[b--];
    a /= 2;
    b /= 2;
  }
  return ans;
}
void update(int k, int x) {
  k += 5 * 100010;
  segtree[k] += x;
  for (k /= 2; k >= 1; k /= 2) segtree[k] = segtree[2 * k] + segtree[2 * k + 1];
}
LL pfx(int l, int r) { return S[r] - S[l] + DP[l]; }
LL solve() {
  S[0] = 1;
  DP[0] = 1;
  int pr = 0;
  for (int i = 1; i <= N + 1; i++) {
    if (range(0, i) > 0)
      DP[i] = 0;
    else
      DP[i] = pfx(pr, i - 1);
    S[i] = S[i - 1] + DP[i];
    pr = max(pr, P[i]);
  }
  return DP[N + 1];
}
void read() {
  N = rd();
  K = rd();
  M = rd();
  for (int i = 0; i < M; i++) {
    int l = rd();
    int r = rd();
    int x = rd();
    ps.push_back(make_pair(make_pair(l, r), x));
  }
  for (int ii = 0, j = 1; ii < K; ii++, j <<= 1) {
    for (int i = 0; i < 4 * 5 * 100010; i++) {
      segtree[i] = 0;
    }
    for (int i = 1; i <= N + 1; i++) P[i] = 0;
    for (int i = 0; i < M; i++) {
      int l = ps[i].first.first;
      int r = ps[i].first.second;
      int x = ps[i].second;
      if (x & j) {
        update(l, 1);
        update(r + 1, -1);
      } else
        P[r] = max(P[r], l);
    }
    P[N + 1] = N + 1;
    ret *= solve();
  }
  cout << ret << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  bool trials = 0;
  if (trials)
    T = rd();
  else
    T = 1;
  while (T--) {
    read();
  }
}
