import java.io.*; import java.util.*; public class Main_yukicoder498_1 { private static Scanner sc; private static Printer pr; private static void solve() { final int MOD = 1_000_000_007; int gx = sc.nextInt(); int gy = sc.nextInt(); int k = sc.nextInt(); long[] x = new long[k]; long[] y = new long[k]; int[] n = new int[k]; for (int i = 0; i < k; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); n[i] = sc.nextInt(); } int si = 15 * 5; long[] fact = new long[si + 1]; fact[0] = 1; for (int i = 1; i <= si; i++) { fact[i] = fact[i - 1] * i % MOD; } long[] ifact = new long[si + 1]; int loop = MOD - 2; long xxx = fact[si]; ifact[si] = 1; while (loop > 0) { if (loop % 2 == 1) { ifact[si] = ifact[si] * xxx % MOD; } xxx = xxx * xxx % MOD; loop /= 2; } for (int i = si - 1; i >= 0; i--) { ifact[i] = ifact[i + 1] * (i + 1) % MOD; } long ret = 0; List q = new ArrayList<>(); List qs = new ArrayList<>(); List ql = new ArrayList<>(); q.add(enc(0, 0)); qs.add(0); ql.add(1L); for (int i = 0; i < k; i++) { for (int j = 0, size = q.size(); j < size; j++) { long e = q.get(j); int es = qs.get(j); long el = ql.get(j); long xx = e / OFFSET - OFFSET2; long yy = e % OFFSET - OFFSET2; for (int l = 0; l < n[i]; l++) { long nx = xx + x[i] * (l + 1); long ny = yy + y[i] * (l + 1); q.add(enc(nx, ny)); qs.add(es + l + 1); ql.add(el * ifact[l + 1] % MOD); if (nx == gx && ny == gy) { ret += el * ifact[l + 1] % MOD * fact[es + l + 1] % MOD; ret %= MOD; } } } } pr.println(ret); } static final int OFFSET = 1_000_000_000; static final int OFFSET2 = 100_000_000; private static long enc(long x, long y) { return (x + OFFSET2) * OFFSET + (y + OFFSET2); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }