def inv(x): return pow(x, MOD-2, MOD) Gx, Gy, K = map(int, input().split()) xyN = [tuple(map(int, input().split())) for _ in range(K)] xyN += [(0, 0, 0)]*(5-K) ans = 0 fact = [1] MOD = 10**9+7 for i in range(1, 100): fact.append(fact[-1]*i%MOD) for i0 in range(xyN[0][2]+1): for i1 in range(xyN[1][2]+1): for i2 in range(xyN[2][2]+1): for i3 in range(xyN[3][2]+1): for i4 in range(xyN[4][2]+1): x = i0*xyN[0][0]+i1*xyN[1][0]+i2*xyN[2][0]+i3*xyN[3][0]+i4*xyN[4][0] y = i0*xyN[0][1]+i1*xyN[1][1]+i2*xyN[2][1]+i3*xyN[3][1]+i4*xyN[4][1] if x==Gx and y==Gy: ans += fact[i0+i1+i2+i3+i4]*inv(fact[i0])*inv(fact[i1])*inv(fact[i2])*inv(fact[i3])*inv(fact[i4]) ans %= MOD print(ans)