from operator import itemgetter from itertools import * from bisect import * from collections import * from heapq import * import sys sys.setrecursionlimit(10 ** 6) def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def SI(): return sys.stdin.readline()[:-1] def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] int1 = lambda x: int(x) - 1 def MI1(): return map(int1, sys.stdin.readline().split()) def LI1(): return list(map(int1, sys.stdin.readline().split())) p2D = lambda x: print(*x, sep="\n") dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] md=10**9+7 n_max = 200005 fac = [1] for i in range(1, n_max + 1): fac.append(fac[-1] * i % md) ifac = [1] * (n_max + 1) ifac[n_max] = pow(fac[n_max], md - 2, md) for i in range(n_max - 1, 1, -1): ifac[i] = ifac[i + 1] * (i + 1) % md memo={} def main(): def dfs(i=0,x=0,y=0,log=[]): if i==k: if x!=gx or y!=gy:return 0 res=fac[sum(log)] for c in log:res=res*ifac[c]%md return res t=(i,x,y) if t in memo:return memo[t] res=0 dx,dy,c=xyc[i] for j in range(c+1): res=(res+dfs(i+1,x+dx*j,y+dy*j,log+[j]))%md memo[t]=res return res gx,gy,k=MI() xyc=LLI(k) print(dfs()) main()