# include using namespace std; typedef long long ll; # define int long long # define lc u << 1 # define rc u << 1 | 1 # define fi first # define se second const int N = 10, M = 100005, mod = 1e9 + 7; int X, Y, K; int x[N], y[N], c[N]; int mul[M], inv[M]; int quick_pow (int a, int b = mod - 2) { int ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod, b >>= 1; } return ans; } void init () { mul[0] = 1; for (int i = 1; i < M; i ++ ) mul[i] = mul[i - 1] * i % mod; inv[M - 1] = quick_pow (mul[M - 1]); for (int i = M - 2; i >= 0; i -- ) inv[i] = inv[i + 1] * (i + 1) % mod; } int chs[N]; int ans; void dfs (int dep) { if (dep > K) { int nowx = 0, nowy = 0; for (int i = 1; i <= K; i ++ ) nowx += x[i] * chs[i], nowy += y[i] * chs[i]; if (nowx == X && nowy == Y) { int cnt = 0; for (int i = 1; i <= K; i ++ ) cnt = (cnt + chs[i]) % mod; int fangan = mul[cnt]; for (int i = 1; i <= K; i ++ ) fangan = fangan * inv[chs[i]] % mod; ans = (ans + fangan) % mod; } return; } for (int i = 0; i <= c[dep]; i ++ ) { chs[dep] = i; dfs (dep + 1); } } signed main () { // freopen ("move.in", "r", stdin); freopen ("move.out", "w", stdout); init (); scanf ("%lld%lld%lld", &X, &Y, &K); for (int i = 1; i <= K; i ++ ) scanf ("%lld%lld%lld", &x[i], &y[i], &c[i]); dfs (1); printf ("%lld\n", ans); return 0; }