import itertools import math def read_data(): Gx, Gy, K = map(int, input().split()) xs = [] ys = [] Ns = [] for k in range(K): x, y, N = map(int, input().split()) xs.append(x) ys.append(y) Ns.append(N) return Gx, Gy, K, xs, ys, Ns def solve(Gx, Gy, K, xs, ys, Ns): mod = 10**9 + 7 counts = 0 patterns = [range(n + 1) for n in Ns] for ns in itertools.product(*patterns): X = sum(n * x for n, x in zip(ns, xs)) Y = sum(n * y for n, y in zip(ns, ys)) if X == Gx and Y == Gy: counts += count_patterns(ns, mod) counts %= mod return counts def count_patterns(ns, mod): num = math.factorial(sum(ns)) for n in ns: num //= math.factorial(n) return num % mod Gx, Gy, K, xs, ys, Ns = read_data() print(solve(Gx, Gy, K, xs, ys, Ns))