import java.io.*; import java.util.*; public class Main_yukicoder498 { 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(); } List> ans = new ArrayList<>(); List q = new ArrayList<>(); List> ql = new ArrayList<>(); q.add(enc(0, 0)); ql.add(new ArrayList<>()); for (int i = 0; i < k; i++) { for (int j = 0, size = q.size(); j < size; j++) { long e = q.get(j); List 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); List tmpl = new ArrayList<>(el); tmpl.add(l + 1); q.add(enc(nx, ny)); ql.add(tmpl); if (nx == gx && ny == gy) { ans.add(tmpl); } } } } long[] fact = new long[15 * 5 + 1]; long[] inv = new long[15 + 1]; fact[0] = 1; for (int i = 1; i <= 15 * 5; i++) { fact[i] = fact[i - 1] * i % MOD; } inv[0] = 1; for (int i = 1; i <= 15; i++) { int loop = MOD - 2; long tmp = i; inv[i] = 1; while (loop > 0) { if (loop % 2 == 1) { inv[i] = inv[i] * tmp % MOD; } tmp = tmp * tmp % MOD; loop /= 2; } } long ret = 0; for (List e : ans) { long tmp = 1; int sum = 0; for (int ee : e) { sum += ee; tmp *= inv[ee]; tmp %= MOD; } tmp *= fact[sum]; tmp %= MOD; ret += tmp; 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); } } }