SIZE=1000; MOD=10**9+7 #998244353 #ここを変更する inv = [0]*SIZE # inv[j] = j^{-1} mod MOD fac = [0]*SIZE # fac[j] = j! mod MOD finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2,SIZE): fac[i] = fac[i-1]*i%MOD finv[-1] = pow(fac[-1],MOD-2,MOD) for i in range(SIZE-1,0,-1): finv[i-1] = finv[i]*i%MOD inv[i] = finv[i]*fac[i-1]%MOD def choose(n,r): # nCk mod MOD の計算 if 0 <= r <= n: return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD else: return 0 gx,gy,k = map(int,input().split()) xyn = [list(map(int,input().split())) for _ in range(k)] v = [0]*k ans = 0 def dfs(i,gx,gy): global ans if i == k: if gx==gy==0: r = fac[sum(v)] for vi in v: r *= finv[vi] r %= MOD ans += r return x,y,n = xyn[i] for j in range(n+1): v[i] = j dfs(i+1,gx-j*x,gy-j*y) dfs(0,gx,gy) print(ans)