h,w,K,P=map(int,input().split()) f=[] o=[[-1]*(w+1) for i in range(h+1)] for i in range(K): x,y,n=input().split() f+=[n] x=int(x) y=int(y) o[x][y]=i M=10**9+7 v=[[0]*(w+1) for i in range(h+1)] q=[[[0]*(1<>j)&1: q[h][w][i]+=q[h][w][i^(1<a: a=q[h][w][i] p=i print(a) for i in range(K): if (p>>i)&1: print(f[i]) else: print(0)