#!/usr/bin/env python3.8 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools MOD = 10**9 + 7 # %% H, W, K, P = map(int, readline().split()) X = [] Y = [] N = [] for _ in range(K): x, y, n = readline().decode().split() x = int(x) y = int(y) X.append(x) Y.append(y) N.append(n) # %% def solve(subset): dp = [[0] * (W + 2) for _ in range(H + 2)] dp[0][0] = 1 forbit = [[0] * (W + 1) for _ in range(H + 1)] for i in subset: x = X[i] y = Y[i] forbit[x][y] = 1 for h in range(H + 1): for w in range(W + 1): if forbit[h][w]: dp[h][w] = 0 continue dp[h + 1][w] += dp[h][w] dp[h][w + 1] += dp[h][w] return dp[H][W] # %% best_subset = 0 best_path = 0 for s in itertools.combinations(range(K), K - P): x = solve(s) if best_path < x: best_path = x best_subset = s # %% if best_path == 0: print(0) else: print(best_path % MOD) for i in range(K): if i in best_subset: continue print(N[i])