import sys
import numpy
N, M, C, S = input().split()
N, M, C, S = int(N), int(M), int(C), int(S)
F = numpy.zeros((N,), dtype=int)
A = numpy.zeros((M,), dtype=int)
B = numpy.zeros((M,), dtype=int)
W = numpy.zeros((M,), dtype=int)
for i in range(N):
F[i] = int(input())
for i in range(M):
a, b, w = input().split()
A[i], B[i], W[i] = int(a), int(b), int(w)
total = numpy.zeros((N,), dtype=int)
for i in range(M):
total[B[i] - 1] = total[B[i] - 1] + W[i]
order = numpy.empty([N], dtype='int,int')
for i in range(N):
order[i] = total[i], i
order.sort()
for i in range(N):
print(order[i][1] + 1)