#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[])
{
int N, M, C, S;
cin >> N >> M >> C >> S;
vector<int> F(N), A(M), B(M), W(M);
for (int i = 0; i < N; ++i) cin >> F[i];
for (int i = 0; i < M; ++i) cin >> A[i] >> B[i] >> W[i];
vector<int> total(N, 0);
for (int i = 0; i < M; ++i) total[B[i] - 1] += W[i];
vector<bool> used(N, false);
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;
cout << (pos + 1) << endl;
}
return 0;
}