gx, gy, K = map(int, input().split()) X, Y, N = [0] * K, [0] * K, [0] * K for i in range(K): X[i], Y[i], N[i] = map(int, input().split()) mod = 10 ** 9 + 7 n = 100 fact = [1] * (n + 1) invfact = [1] * (n + 1) for i in range(1, n): fact[i + 1] = ((i+1) * fact[i]) % mod invfact[n] = pow(fact[n], mod - 2, mod) for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % mod def comb(n, r): if n < 0 or r < 0 or n - r < 0: return 0 return fact[n] * invfact[r] * invfact[n - r] % mod ans = 0 if K == 1: for i0 in range(N[0] + 1): x = X[0] * i0 y = Y[0] * i0 if x == gx and y == gy: ans += 1 elif K == 2: for i0 in range(N[0] + 1): for i1 in range(N[1] + 1): x = X[0] * i0 + X[1] * i1 y = Y[0] * i0 + Y[1] * i1 if x == gx and y == gy: ans += comb(i0 + i1, i0) ans %= mod elif K == 3: for i0 in range(N[0] + 1): for i1 in range(N[1] + 1): for i2 in range(N[2] + 1): x = X[0] * i0 + X[1] * i1 + X[2] * i2 y = Y[0] * i0 + Y[1] * i1 + Y[2] * i2 if x == gx and y == gy: ans += comb(i0 + i1 + i2, i0) * comb(i1 + i2, i1) ans %= mod elif K == 4: for i0 in range(N[0] + 1): for i1 in range(N[1] + 1): for i2 in range(N[2] + 1): for i3 in range(N[3] + 1): x = X[0] * i0 + X[1] * i1 + X[2] * i2 + X[3] * i3 y = Y[0] * i0 + Y[1] * i1 + Y[2] * i2 + Y[3] * i3 if x == gx and y == gy: ans += comb(i0 + i1 + i2 + i3, i0) * comb(i1 + i2 + i3, i1) * comb(i2 + i3, i2) ans %= mod else: for i0 in range(N[0] + 1): for i1 in range(N[1] + 1): for i2 in range(N[2] + 1): for i3 in range(N[3] + 1): for i4 in range(N[4] + 1): x = X[0] * i0 + X[1] * i1 + X[2] * i2 + X[3] * i3 + X[4] * i4 y = Y[0] * i0 + Y[1] * i1 + Y[2] * i2 + Y[3] * i3 + Y[4] * i4 if x == gx and y == gy: ans += comb(i0 + i1 + i2 + i3 + i4, i0) * comb(i1 + i2 + i3 + i4, i1) * comb(i2 + i3 + i4, i2) * comb(i3 + i4, i3) ans %= mod print(ans)