#include using namespace std; #define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++) #define ALL(x) x.begin(),x.end() template bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; } template bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; } typedef long long ll; int gx,gy,N,K; ll dp [1 << 15]; const ll MOD = 1e9 + 7; int main() { scanf("%d%d%d",&gx,&gy,&K); vector X(K),Y(K),C(K),A; FOR(i,0,K){ scanf("%d%d%d",&X [i],&Y [i],&C [i]); N += C [i]; FOR(j,0,C [i]) A.push_back(i); } dp [0] = 1; FOR(mask,0,1 << N){ deque used(K); FOR(i,0,N) if((mask >> i & 1) == 0){ if(used [A [i]]) continue; (dp [mask | (1 << i)] += dp [mask]) %= MOD; used [A [i]] = true; } } ll ans = 0; FOR(mask,0,1 << N){ int x = 0,y = 0; FOR(i,0,N) if(mask >> i & 1){ x += X [A [i]]; y += Y [A [i]]; } if(x == gx && y == gy) (ans += dp [mask]) %= MOD; } printf("%lld\n",ans); return 0; }