import java.util.Arrays; import java.util.Scanner; public class Main { public static final long MOD = 1000000007; public static long mod_pow(long a, long e, long m){ if(e == 0){ return 1; }else if(e % 2 == 0){ long ret = mod_pow(a, e / 2, m); return (ret * ret) % m; }else{ return (mod_pow(a, e - 1, m) * a) % m; } } public static long mod_inv(long a, long p){ return mod_pow(a, p - 2, p); } public static long dfs(int deep, int limit, int[] using, int[] xs, int[] ys, int[] ns, int gx, int gy, long x, long y){ if(deep >= limit){ if(gx == x && gy == y){ final int use_sum = Arrays.stream(using).sum(); //if(use_sum == 0){ return 0; } long upper = 1; for(int i = 1; i <= use_sum; i++){ upper *= i; upper %= MOD; } long lower = 1; for(int part = 0; part < limit; part++){ for(int i = 1; i <= using[part]; i++){ lower *= i; lower %= MOD; } } return (upper * mod_inv(lower, MOD)) % MOD; }else{ return 0; } }else{ long ret = 0; for(int i = 0; i <= ns[deep]; i++){ using[deep] = i; ret += dfs(deep + 1, limit, using, xs, ys, ns, gx, gy, x + xs[deep] * i, y + ys[deep] * i); ret %= MOD; } return ret; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int gx = sc.nextInt(); final int gy = sc.nextInt(); final int K = sc.nextInt(); int[] xs = new int[K]; int[] ys = new int[K]; int[] ns = new int[K]; for(int i = 0; i < K; i++){ xs[i] = sc.nextInt(); ys[i] = sc.nextInt(); ns[i] = sc.nextInt(); } System.out.println(dfs(0, K, new int[K], xs, ys, ns, gx, gy, 0, 0)); } }