using System;
public class main
{
public static void Main()
{
string[] line = Console.ReadLine().Split(' ');
int N = Int32.Parse(line[0]);
int M = Int32.Parse(line[1]);
int C = Int32.Parse(line[2]);
int S = Int32.Parse(line[3]);
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)
{
line = Console.ReadLine().Split(' ');
F[i] = Int32.Parse(line[0]);
}
for (int i = 0; i < M; ++i)
{
line = Console.ReadLine().Split(' ');
A[i] = Int32.Parse(line[0]);
B[i] = Int32.Parse(line[1]);
W[i] = Int32.Parse(line[2]);
}
int[] total = new int[N];
for (int i = 0; i < M; ++i) total[B[i] - 1] += W[i];
bool[] used = new bool[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;
Console.WriteLine(pos + 1);
}
}
}