from collections import defaultdict MOD = 10**9 + 7 MAX = 76 fac = [1] * MAX for i in range(1, MAX): fac[i] = fac[i - 1] * i % MOD Gx, Gy, K = map(int, input().split()) cand = defaultdict(list) cand[(0, 0)] = [[]] for _ in range(K): nx, ny, n = map(int, input().split()) new_cand = defaultdict(list) for (x, y), lst in cand.items(): for crystal in lst: new_cand[(x, y)].append(crystal + [0]) for i in range(1, n + 1): new_cand[(x + i * nx, y + i * ny)].append(crystal + [i]) cand = new_cand res = cand[(Gx, Gy)] ans = 0 for crystal in res: tmp = fac[sum(crystal)] for x in crystal: tmp *= pow(fac[x], -1, MOD) tmp %= MOD ans += tmp ans %= MOD print(ans)