from operator import itemgetter from itertools import * from bisect import * from collections import * from heapq import * import sys sys.setrecursionlimit(10 ** 6) def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def SI(): return sys.stdin.readline()[:-1] def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] int1 = lambda x: int(x) - 1 def MI1(): return map(int1, sys.stdin.readline().split()) def LI1(): return list(map(int1, sys.stdin.readline().split())) p2D = lambda x: print(*x, sep="\n") dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] def main(): md=10**9+7 h,w,k,p=MI() friends=[SI().split() for _ in range(k)] ans=0 abit=(1<p:continue dp=[[0]*(w+2) for _ in range(h+2)] for fi in range(k): if bit>>fi&1: i,j,_=friends[fi] dp[int(i)+1][int(j)+1]=-1 dp[0][1]=1 for i in range(h+1): for j in range(w+1): if dp[i+1][j+1]==-1:dp[i+1][j+1]=0 else:dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j]) if dp[h+1][w+1]>ans: ans=dp[h+1][w+1] abit=bit print(ans%md) for fi in range(k): if abit>>fi&1==0:print(friends[fi][2]) main()