import java.util.*;

public class Antti {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int m = input.nextInt();
		if (m < n) {
			System.out.println("impossible");
			return;
		}
		int b = input.nextInt()+1;
		int r = input.nextInt();
		int[][] start = new int[n][n];
		int[][] first = new int[n][n];
		int[][] total = new int[n][n];
		int[][] pref = new int[n][n];
		int[] pos = new int[n];
		while (r-- > 0) {
			int s = input.nextInt()+1;
			int k = input.nextInt()-1;
			int t = input.nextInt()-1;
			for (int i = 0; i < n; i++) {
				if (start[k][i] != 0) {
					total[k][i] += s-start[k][i];
					start[k][i] = 0;
				}
			}
			if (t == -1 || t >= n) continue;
			start[k][t] = s;
			if (first[k][t] == 0) {
				first[k][t] = s;
				pref[t][pos[t]++] = k;
			}
		}
		for (int k = 0; k < n; k++) {
			for (int t = 0; t < n; t++) {
				if (first[k][t] == 0) {
					pref[t][pos[t]++] = k;
				}
				if (start[k][t] != 0) {
					total[k][t] += b-start[k][t];
				}
			}
		}
		int[] toy = new int[n];
		for (int i = 0; i < n; i++) {
			toy[i] = -1;
			pos[i] = 0;
		}
		for (int i = 0; i < n; i++) {
			int x = i;
			while (x != -1) {
				int p = pref[x][pos[x]];
				if (toy[p] == -1 || total[p][x] > total[p][toy[p]]) {
					int old = toy[p];
					toy[p] = x;
					x = old;
				} else {
					pos[x]++;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.print((toy[i]+1)+" ");
		}
		System.out.println();
	}
}
