#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef int in;
typedef long long ll;
typedef vector<in> VI;
typedef vector<VI> VVI;
const in mdl=1000000007;
in p2(in a){
  return 1<<a;
}
vector<ll> wys;
in n;
void goup(){
  in pn=p2(n);
  in pi;
  in tmsk;
  forn(i,n){
    pi=p2(i);
    in pl=p2(n-1-i);
    in pr=p2(i);
    forn(msk,pn){
      if(msk&pi)
	continue;
      tmsk=msk&(~(pi-1));
      tmsk&=~(tmsk-1);
      wys[(msk|pi)^tmsk]+=wys[msk];
    }
  }
}

VI condmembers;
VI condvalue;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in m,k;
  cin>>n>>m>>k;
  --n;
  wys.resize(p2(n));
  wys[0]=1;
  condmembers.resize(m);
  condvalue.resize(m);
  in a,b,c;
  forn(z,k){
    cin>>a>>b>>c;
    --a;
    --b;
    condmembers[a]|=p2(b);
    condvalue[a]|=c*p2(b);
  }
  forn(z,m){
    goup();
    forn(msk,p2(n)){
      if((msk&condmembers[z])!=condvalue[z])
	wys[msk]=0;
      wys[msk]%=mdl;
    }
  }
  ll sm=0;
  forn(i,p2(n))
    sm+=wys[i];
  sm%=mdl;
  if(sm<0)
    sm+=mdl;
  cout<<sm<<endl;
  return 0;
}
