R = xrange def solve(): p = 10**9+7 Comb = [[0]*76 for i in R(76)] Comb[0][0] = 1 cx = [0]*5; cy = [0]*5; cN = [0]*5; use = [0]*5 Gx,Gy,K = map(int,raw_input().split()) for i in R(K): cx[i],cy[i],cN[i] = map(int,raw_input().split()) for i in R(K*15): for j in R(i+2): Comb[i+1][j] = (Comb[i][j] + (Comb[i][j-1] if j > 0 else 0)) % p ans = 0 x0 = y0 = 0 for i in R(cN[0]+1): use[0] = i x0 = cx[0]*i y0 = cy[0]*i for j in R(cN[1]+1): use[1] = j x1 = x0 + cx[1]*j y1 = y0 + cy[1]*j for k in R(cN[2]+1): use[2] = k x2 = x1 + cx[2]*k y2 = y1 + cy[2]*k for l in R(cN[3]+1): use[3] = l x3 = x2 + cx[3]*l y3 = y2 + cy[3]*l for m in R(cN[4]+1): use[4] = m x4 = x3 + cx[4]*m y4 = y3 + cy[4]*m if x4 != Gx or y4 != Gy: continue total = sum(use) cnt = 1 for n in xrange(5): cnt = cnt * Comb[total][use[n]] % p total -= use[n] ans = (ans + cnt) % p print ans solve()