import java.io.*;
import java.util.*;

public class roads_ft_nlogn implements Runnable {

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	private void myAssert(boolean e, String mes) {
		if (!e) {
			throw new Error("Assertion failure!!! " + mes);
		}
	}

	String nextToken() throws IOException {
		while (!st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	class Edge {
		int u;
		int v;
		int w;
		int id;
		public Edge(int u, int v, int w, int id) {
			this.u = u;
			this.v = v;
			this.w = w;
			this.id = id;
		}

	}

	class DisjointSetSystem {
		int n;
		int[] p;
		int[] r;
		
		public DisjointSetSystem(int n) {
			this.n = n;
			p = new int[n];
			r = new int[n];
			for (int i = 0; i < n; i++) {
				p[i] = i;
				r[i] = 1;
			}
		}

		public int get(int x) {
			int res = x;
			if (p[x] != x) {
				res = get(p[x]);
			}
//			p[x] = res;
			return res;
		}

		public void join(int x, int y) {
			x = get(x);
			y = get(y);
			if (x != y) {
				if (r[x] > r[y]) {
					p[y] = x;
					r[x] += r[y];
				} else {
					p[x] = y;
					r[y] += r[x];
				}
			}
		}
	}

	private void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		int a = nextInt();
		int b = nextInt();

		ArrayList<Edge> ones = new ArrayList<Edge>();
		ArrayList<Edge> zeroes = new ArrayList<Edge>();
		ArrayList<Edge> list = new ArrayList<Edge>();
		
		for (int i = 0; i < m; i++) {
			int u = nextInt() - 1;
			int v = nextInt() - 1;
			int w = nextInt();
			Edge e = new Edge(u, v, w, i + 1);
			if (w == 0) {
				zeroes.add(e);
			} else {
				ones.add(e);
			}
		}		

		for (Edge e : zeroes) {
			list.add(e);
		}

		for (Edge e : ones) {
			list.add(e);
		}

		ArrayList<Edge> mst = new ArrayList<Edge>();
        
		DisjointSetSystem dssMST = new DisjointSetSystem(n);
		int mstWeight = 0;
		for (Edge e : list) {
			int u = e.u;
			int v = e.v;
			if (dssMST.get(u) != dssMST.get(v)) {
				dssMST.join(u, v);
                mstWeight += e.w;
                mst.add(e);
			}						
		}

		if (mstWeight > b) {
			out.println("Impossible");
			return;
		}

        DisjointSetSystem dssAnswer = new DisjointSetSystem(n);
        ArrayList<Edge> answer = new ArrayList<Edge>();

        for (Edge e : mst) {
			int u = e.u;
			int v = e.v;
        	if (e.w == 1) {
				dssAnswer.join(u, v);
				answer.add(e);
        	}
        }

	    int ansWeight = mstWeight;
		
		for (Edge e : ones) {
			if (ansWeight == b) {
				break;
			}
			int u = e.u;
			int v = e.v;
			if (dssAnswer.get(u) != dssAnswer.get(v)) {
				dssAnswer.join(u, v);
				ansWeight++;	
				answer.add(e);
			}   
		}

		for (Edge e : zeroes) {
			int u = e.u;
			int v = e.v;
			if (dssAnswer.get(u) != dssAnswer.get(v)) {
				dssAnswer.join(u, v);
				answer.add(e);
			}   
		}

        if (ansWeight != b || answer.size() != n - 1) {
        	out.println("Impossible");
        	return;
        }

        StringBuilder sb = new StringBuilder();

        for (Edge e : answer) {
        	sb.append(e.id + " ");
        }

        out.println(sb.toString().trim());

	}

	public void run() {
		try {
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}
	}
	
	private roads_ft_nlogn(String name) {
		try {
			in = new BufferedReader(new FileReader(name + ".in"));
			st = new StringTokenizer(in.readLine());
			out = new PrintWriter(new FileWriter(name + ".out"));	
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(239);
		}
	}

	public static void main(String[] args) {
		(new Thread(new roads_ft_nlogn("roads"))).start();
	}
}
