N = 100 mod = 10**9+7 fac = [1]*(N+1) finv = [1]*(N+1) for i in range(N): fac[i+1] = fac[i] * (i+1) % mod finv[-1] = pow(fac[-1], mod-2, mod) for i in reversed(range(N)): finv[i] = finv[i+1] * (i+1) % mod def cmb1(n, r): if r <0 or r > n: return 0 r = min(r, n-r) return fac[n] * finv[r] * finv[n-r] % mod import sys import io, os sys.setrecursionlimit(10**9) input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import defaultdict gx, gy, k = map(int, input().split()) X, Y, N = [], [], [] for i in range(k): x,y,n = map(int, input().split()) X.append(x) Y.append(y) N.append(n) ans = [0] def dfs(A): if len(A) == k: cx, cy = 0, 0 s = 0 for i, a in enumerate(A): cx += a*X[i] cy += a*Y[i] s += a if cx == gx and cy == gy: temp = fac[s] for a in A: temp *= finv[a] temp %= mod ans[0] += temp ans[0] %= mod return j = len(A) for a in range(N[j]+1): A.append(a) dfs(A) A.pop() dfs([]) print(ans[0]%mod)