from math import log def solve(): p = 10**9+7 F = [1]; FI = [0]*16 for i in xrange(75): F.append((i+1)*F[i]%p) FI[15] = pow(F[15],p-2,p) for i in xrange(15,0,-1): FI[i-1] = i*FI[i]%p Gx,Gy,K = map(int,raw_input().split()) G = (Gx,Gy); dp = {0:(0,0)} for i in xrange(K): x,y,N = map(int,raw_input().split()) mul = 1; shift = i*4 for j in xrange(int(log(N,2))): ndp = dict(); mx,my = x*mul,y*mul for k,h in dp.iteritems(): ndp[k] = h; ndp[k+(mul< 0: ndp = dict(); mx,my = x*N,y*N for k,h in dp.iteritems(): ndp[k] = h; ndp[k+(N<>=4 total += dup_n; deno=deno*FI[dup_n]%p ans = (ans + F[total]*deno)%p print ans solve()