#include using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; ll f[80], fi[80]; int gx, gy, K; vector x, y, n; ll modpow(ll x, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } void init(int lim) { f[0] = 1; for (int i = 1; i <= lim; i++) f[i] = f[i - 1] * i % MOD; fi[lim] = modpow(f[lim], MOD - 2); for (int i = lim; i > 0; i--) fi[i - 1] = fi[i] * i % MOD; } bool judge(vector& used) { int sx = 0, sy = 0; for (int i = 0; i < K; i++) { sx += x[i] * used[i]; sy += y[i] * used[i]; } return (sx == gx && sy == gy); } ll solve(vector& used) { ll res = f[accumulate(used.begin(), used.end(), 0)]; for (int x : used) { (res *= fi[x]) %= MOD; } return res; } ll dfs(int cnt, vector used) { if (cnt == K) { if (!judge(used)) return 0; else return solve(used); } ll res = 0; for (int i = 0; i <= n[cnt]; i++) { used[cnt] = i; (res += dfs(cnt + 1, used)) %= MOD; used[cnt] = 0; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> gx >> gy >> K; x.resize(K); y.resize(K); n.resize(K); for (int i = 0; i < K; i++) cin >> x[i] >> y[i] >> n[i]; init(accumulate(n.begin(), n.end(), 0)); vector used(K, 0); cout << dfs(0, used) << endl; return 0; }