import java.util.*;
public class main
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int M = in.nextInt();
int C = in.nextInt();
int S = in.nextInt();
int[] F = new int[N];
int[] A = new int[M];
int[] B = new int[M];
int[] W = new int[M];
for (int i = 0; i < N; ++i)
{
F[i] = in.nextInt();
}
for (int i = 0; i < M; ++i)
{
A[i] = in.nextInt();
B[i] = in.nextInt();
W[i] = in.nextInt();
}
int[] total = new int[N];
for (int i = 0; i < M; ++i) total[B[i] - 1] += W[i];
boolean[] used = new boolean[N];
for (int i = 0; i < N; ++i)
{
int pos = -1;
for (int j = 0; j < N; ++j)
if (!used[j] && (pos == -1 || total[j] < total[pos]))
pos = j;
used[pos] = true;
System.out.println(pos + 1);
}
}
}