#include <cstdio>

const int Mod = 1000000007;
const int MN = 20, MM = 20;

inline void Add(int &x, int y) { x -= Mod - y; x += x >> 31 & Mod; }

int N, M, K, t[MM][MN];
int f[2][1 << MN];

int main() {
	scanf("%d%d%d", &N, &M, &K), --N;
	for (int i = 0; i < M; ++i)
		for (int j = 0; j < N; ++j)
			t[i][j] = -1;
	for (int i = 1; i <= K; ++i) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		t[--a][--b] = c;
	}
	int o = 0;
	f[o][0] = 1;
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < N; ++j) {
			o ^= 1;
			for (int S = 0; S < 1 << N; ++S) f[o][S] = 0;
			for (int S = 0; S < 1 << N; ++S) if (f[o ^ 1][S]) {
				int v = f[o ^ 1][S];
				if (t[i][j] != 1) {
					if (~S >> j & 1) Add(f[o][S], v);
				}
				if (t[i][j] != 0) {
					if (S >> j & 1) Add(f[o][S], v);
					else {
						int T = S >> j;
						if (T) T &= T - 1;
						T = (T + 1) << j | (S & ((1 << j) - 1));
						Add(f[o][T], v);
					}
				}
			}
		}
	}
	int Ans = 0;
	for (int S = 0; S < 1 << N; ++S) Add(Ans, f[o][S]);
	printf("%d\n", Ans);
	return 0;
}