#include<bits/stdc++.h> using std::vector; #define int long long typedef vector<int> vi; typedeflonglong ll; constint Mod=998244353; template<typename Tp=int>inline Tp read(){Tp x(0);intop(0);char ch=getchar();while(ch<'0'||ch>'9')op|=(ch==45),ch=getchar();while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();return op?-x:x;}
signedmain(){ int n=read(),K=read(),m=read(); vi L(m+1),R(m+1),X(m+1); for(int i=1;i<=m;++i)L[i]=read(),R[i]=read()+1,X[i]=read(); auto solve=[&](vi a) -> int { vi lef(n+2),one(n+2); for(int i=1;i<=m;++i) if(a[i])one[L[i]]++,one[R[i]]--; else lef[R[i]]=std::max(lef[R[i]],L[i]); for(int i=2;i<=n+1;++i)one[i]+=one[i-1],lef[i]=std::max(lef[i],lef[i-1]); vi f(n+2); f[0]=1; for(int i=1,cur=0,sum=1;i<=n+1;++i){ while(cur<lef[i])sum-=f[cur++],sum<0?sum+=Mod:1; if(!one[i])f[i]=sum; sum+=f[i],sum>=Mod?sum-=Mod:1; } return f[n+1]; }; int ans=1; for(int i=0;i<K;++i){ vi a(m+1); for(int j=1;j<=m;++j)a[j]=(X[j]>>i)&1; int x=solve(a); (ans=1ll*ans*x)%=Mod; } printf("%lld\n",ans); return0; }