#include <bits/stdc++.h>
using namespace std;
const int MOD = 119 << 23 | 1;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-6;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline unsigned long long isqrt(unsigned long long k) {
  unsigned long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() { return abs((int)mt()); }
inline int mrand(int k) { return abs((int)mt()) % k; }
void chemthan() {
  int n, k, m;
  cin >> n >> k >> m;
  vector<int> l(m), r(m), x(m);
  for (int i = (0); i < (m); ++i) cin >> l[i] >> r[i] >> x[i], l[i]--, r[i]--;
  vector<tuple<int, int, int>> vals;
  for (int i = (0); i < (m); ++i) {
    vals.push_back({l[i], -r[i], x[i]});
  }
  sort((vals).begin(), (vals).end());
  for (int i = (0); i < (m); ++i) {
    tie(l[i], r[i], x[i]) = vals[i];
    r[i] = -r[i];
  }
  int res = 1;
  for (int t = (0); t < (k); ++t) {
    vector<int> a(n);
    for (int i = (0); i < (m); ++i) {
      if ((((x[i]) >> (t)) & 1)) {
        a[l[i]]++;
        if (r[i] + 1 < n) {
          a[r[i] + 1]--;
        }
      }
    }
    for (int i = (1); i < (n); ++i) a[i] += a[i - 1];
    for (int i = (0); i < (n); ++i) a[i] = 0 < a[i];
    vector<pair<int, int>> vals;
    for (int i = (0); i < (m); ++i) {
      if (!(((x[i]) >> (t)) & 1)) {
        vals.push_back({l[i], -r[i]});
      }
    }
    int mn = INF;
    vector<pair<int, int>> nvals;
    for (int i = (int((vals).size())) - 1; i >= (0); --i) {
      int l, r;
      tie(l, r) = vals[i];
      r = -r;
      if (r < mn) {
        nvals.push_back({l, r});
      }
      chkmin(mn, r);
    }
    vals = nvals;
    vector<int> dc;
    for (int i = (0); i < (n); ++i) {
      if (!a[i]) {
        dc.push_back(i);
      }
    }
    vector<int> f(n, n);
    for (auto e : vals) {
      int l = e.first;
      int r = e.second;
      int u = lower_bound((dc).begin(), (dc).end(), l) - dc.begin();
      int v = upper_bound((dc).begin(), (dc).end(), r) - dc.begin() - 1;
      if (v < u) {
        cout << 0 << "\n";
        return;
      }
      chkmin(f[u], v);
    }
    vector<int> fen(n + 5);
    auto upd = [&](int p, int v) {
      p++;
      for (; p < int((fen).size()); p += p & -p) {
        addmod(fen[p], v);
      }
    };
    auto query = [&](int p) {
      p++;
      int res = 0;
      for (; 0 < p; p -= p & -p) {
        addmod(res, fen[p]);
      }
      return res;
    };
    int c = 1, d = 0;
    vector<int> g(int((dc).size()));
    for (int i = (0); i < (int((dc).size())); ++i) {
      if (f[i] < n) {
        addmod(g[f[i]], c);
        addmod(d, c);
        c = 0;
      }
      c = mult(c, 2);
      addmod(c, d);
      submod(d, g[i]);
    }
    res = mult(res, c);
  }
  cout << res << "\n";
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
