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;
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();
  }
}
