import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.string; immutable long MOD = 10^^8 + 7; immutable long MAX = 2 * 10^^5 + 10; long[] F, G; void main() { auto s = readln.split.map!(to!int); auto H = s[0]; auto W = s[1]; auto K = s[2]; auto P = K.iota.map!(i => readln.split.map!(to!int).array ~ i).array; P.sort(); F = new long[](MAX+1); F[0] = 1; foreach (i; 1..MAX+1) F[i] = F[i-1] * i % MOD; auto all = new long[](1< mask & (1 << P[i][2])).map!(i => P[i]).array) ~ [H, W, -1]; long tmp = 1; foreach (i; 0..A.length.to!int-1) { if (A[i][1] > A[i+1][1]) { continue outer; } tmp *= comb(A[i+1][0] - A[i][0] + A[i+1][1] - A[i][1], A[i+1][0] - A[i][0]); tmp %= MOD; } all[mask] = tmp; } for (int mask = 0; mask < (1< writeln((a % MOD + MOD) % MOD)); } long comb(long n, long r) { if (n < r) return 0; return F[n] * powmod(F[n-r], MOD-2, MOD) % MOD * powmod(F[r], MOD-2, MOD) % MOD; } long powmod(long a, long x, long m) { long ret = 1; while (x) { if (x % 2) ret = ret * a % m; a = a * a % m; x /= 2; } return ret; }