# coding: utf-8 import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time sys.setrecursionlimit(10 ** 7) INF = 10 ** 20 MOD = 10 ** 9 + 7 def II(): return int(input()) def ILI(): return list(map(int, input().split())) def IAI(LINE): return [ILI() for __ in range(LINE)] def IDI(): return {key: value for key, value in ILI()} def read(): H, W, K, P = ILI() ani = [] for __ in range(K): x, y, name = input().split() ani.append((int(x), int(y), str(name))) return (H, W, K, P, ani) def solve(H, W, K, P, ani): ans_num = -1 ans_ind = 0 dif_k = K - P for ani_ind in itertools.combinations(range(K), dif_k): board = [[0] * (W + 1) for __ in range(H + 1)] board_bool = [[False] * (W + 1) for __ in range(H + 1)] for ind in ani_ind: x, y, name = ani[ind] board_bool[x][y] = True for h in range(H + 1): if board_bool[h][0]: break board[h][0] = 1 for w in range(W + 1): if board_bool[0][w]: break board[0][w] = 1 for w in range(1, W + 1): for h in range(1, H + 1): if board_bool[h][w]: continue else: board[h][w] = board[h - 1][w] + board[h][w - 1] if ans_num < board[H][W]: ans_num = board[H][W] ans_ind = ani_ind if ans_num == 0: return 0 else: ans = [] ans.append(ans_num % MOD) for ind in range(K): if ind in ans_ind: continue x, y, name = ani[ind] ans.append(name) return ans def main(): params = read() ans = solve(*params) if isinstance(ans, int): print(ans) else: for a in ans: print(a) if __name__ == "__main__": main()