from collections import deque def inv(x): return pow(x, MOD-2, MOD) def dfs(d, q): if d==K: x, y = 0, 0 res = fact[sum(q)] for (xi, yi, _), qi in zip(xyN, q): x += xi*qi y += yi*qi res *= inv(fact[qi]) if x==Gx and y==Gy: return res else: return 0 res = 0 for i in range(xyN[d][2]+1): q.append(i) res += dfs(d+1, q) res %= MOD q.pop() return res Gx, Gy, K = map(int, input().split()) xyN = [tuple(map(int, input().split())) for _ in range(K)] MOD = 10**9+7 fact = [1] for i in range(1, 100): fact.append(fact[-1]*i%MOD) print(dfs(0, deque([])))