H, W, K, P = map(int, input().split()) friends = [] grid_map = {} for i in range(K): x, y, name = input().split() x = int(x) y = int(y) friends.append((x, y, name)) grid_map[(x, y)] = i # Maps coordinate to friend index MOD = 10**9 + 7 max_count = -1 best_mask = 0 for mask in range(0, 1 << K): selected = bin(mask).count('1') if selected > P: continue dp = [[0] * (W + 1) for _ in range(H + 1)] dp[0][0] = 1 # Starting point for x in range(H + 1): for y in range(W + 1): if x == 0 and y == 0: continue blocked = False if (x, y) in grid_map: idx = grid_map[(x, y)] if not (mask & (1 << idx)): blocked = True if blocked: dp[x][y] = 0 else: total = 0 if x > 0: total += dp[x-1][y] if y > 0: total += dp[x][y-1] dp[x][y] = total % MOD current_count = dp[H][W] if current_count > max_count: max_count = current_count best_mask = mask if max_count <= 0: print(0) else: print(max_count % MOD) selected_names = [friends[i][2] for i in range(K) if (best_mask & (1 << i))] for name in selected_names: print(name)