H, W, K, P = map(int, input().split()) friends = [] grid = [[-1 for _ in range(W+1)] for _ in range(H+1)] for idx in range(K): x, y, name = input().split() x = int(x) y = int(y) friends.append((x, y, name)) grid[x][y] = idx mod = 10**9 + 7 max_count = 0 best_mask = 0 for mask in range(0, 1 << K): cnt = bin(mask).count('1') if cnt > P: continue dp = [[0] * (W + 1) for _ in range(H + 1)] dp[0][0] = 1 for s in range(0, H + W + 1): for i in range(0, H + 1): j = s - i if j < 0 or j > W: continue if i == 0 and j == 0: continue friend_idx = grid[i][j] blocked = False if friend_idx != -1: if not (mask & (1 << friend_idx)): blocked = True if blocked: dp[i][j] = 0 continue total = 0 if i > 0: total += dp[i-1][j] if j > 0: total += dp[i][j-1] dp[i][j] = total % mod current_count = dp[H][W] if current_count > max_count or (current_count == max_count and mask < best_mask and current_count != 0): max_count = current_count best_mask = mask if max_count == 0: print(0) else: print(max_count % mod) selected = [friends[idx][2] for idx in range(K) if (best_mask & (1 << idx))] for name in selected: print(name)