You are given three integers n, k, m and m conditions (l_1, r_1, x_1), (l_2, r_2, x_2), ..., (l_m, r_m, x_m).

Calculate the number of distinct arrays a, consisting of n integers such that: 

  * 0 ≤ a_i < 2^k for each 1 ≤ i ≤ n; 
  * bitwise AND of numbers a[l_i] \& a[l_i + 1] \& ... \& a[r_i] = x_i for each 1 ≤ i ≤ m. 



Two arrays a and b are considered different if there exists such a position i that a_i ≠ b_i. 

The number can be pretty large so print it modulo 998244353.

Input

The first line contains three integers n, k and m (1 ≤ n ≤ 5 ⋅ 10^5, 1 ≤ k ≤ 30, 0 ≤ m ≤ 5 ⋅ 10^5) — the length of the array a, the value such that all numbers in a should be smaller than 2^k and the number of conditions, respectively.

Each of the next m lines contains the description of a condition l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 0 ≤ x_i < 2^k) — the borders of the condition segment and the required bitwise AND value on it.

Output

Print a single integer — the number of distinct arrays a that satisfy all the above conditions modulo 998244353.

Examples

Input


4 3 2
1 3 3
3 4 6


Output


3


Input


5 2 3
1 3 2
2 5 0
3 3 3


Output


33

Note

You can recall what is a bitwise AND operation [here](https://en.wikipedia.org/wiki/Bitwise_operation#AND).

In the first example, the answer is the following arrays: [3, 3, 7, 6], [3, 7, 7, 6] and [7, 3, 7, 6].
#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;
}
