N = 10**6 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 from collections import defaultdict gx, gy, k = map(int, input().split()) XYN = [] for i in range(k): x,y,n = map(int, input().split()) XYN.append((x, y, n)) dp = defaultdict(lambda: 0) dp[(0, 0, 0)] = 1 for i, (x, y, n) in enumerate(XYN): nx = defaultdict(lambda: 0) for a in range(0, n+1): for (cx, cy, s), v in dp.items(): if abs(cx-gx) > 10**4*(k-i) or abs(cy-gy) > 10**4*(k-i): continue ncx, ncy = cx+a*x, cy+a*y ns = s+a nx[(ncx,ncy,ns)] += v*cmb1(ns,a) nx[(ncx,ncy,ns)] %= mod dp = nx ans = 0 for (cx, cy, s), v in dp.items(): if cx == gx and cy == gy: ans += v ans %= mod print(ans)