#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools MOD = 10 ** 9 + 7 # %% Gx, Gy, K = map(int, readline().split()) m = map(int, read().split()) XYN = list(zip(m, m, m)) # %% fact = [1] * 1000 for n in range(1, 1000): fact[n] = n * fact[n - 1] # %% X, Y, N = zip(*XYN) rngs = [range(n + 1) for n in N] it = itertools.product(*rngs) answer = 0 for p in it: x = sum(dx * cnt for dx, cnt in zip(X, p)) y = sum(dy * cnt for dy, cnt in zip(Y, p)) if x != Gx or y != Gy: continue x = fact[sum(p)] for cnt in p: x //= fact[cnt] answer += x # %% print(answer % MOD)