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

public class domestic_md implements Runnable {
	private class Link implements Comparable<Link> {
		int a, b, length, id;
		
		public Link(String s, int id) {
			StringTokenizer st = new StringTokenizer(s);
			a = Integer.parseInt(st.nextToken()) - 1;
			b = Integer.parseInt(st.nextToken()) - 1;
			length = Integer.parseInt(st.nextToken());
			this.id = id;
		}

		public int compareTo(Link that) {
			return length - that.length;
		}
	}
	
	private class DSU {
		int size;
		int[] a;
		int[] r;
		
		public DSU(int size) {
			this.size = size;
			a = new int[size];
			r = new int[size];
			for (int i = 0; i < size; i++)
				a[i] = i;
		}
		
		public int get(int v) {
			if (a[v] == v)
				return v;
			return a[v] = get(a[v]);
		}
		
		public boolean union(int u, int v) {
			u = get(u);
			v = get(v);
			if (u == v)
				return false;
			if (r[u] == r[v])
				r[u]++;
			if (r[u] > r[v])
				a[v] = u;
			else
				a[u] = v;
			return true;
		}
		
		public boolean same(int u, int v) {
			return get(u) == get(v);
		}
	}
	
	private BufferedReader in;
	private PrintWriter out;

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private void solve() throws IOException {
		Locale.setDefault(Locale.US);
		in = new BufferedReader(new FileReader("domestic.in"));
		out = new PrintWriter("domestic.out");
		StringTokenizer st = new StringTokenizer(in.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		Link[] links = new Link[m];
		for (int i = 0; i < m; i++) {
			links[i] = new Link(in.readLine(), i);
		}
		st = new StringTokenizer(in.readLine());
		int pa = Integer.parseInt(st.nextToken());
		int qa = Integer.parseInt(st.nextToken());
		int pb = Integer.parseInt(st.nextToken());
		int qb = Integer.parseInt(st.nextToken());
		String cheap = "5";
		String expensive = "6";
		if (pa > pb) {
			int t = pa; pa = pb; pb = t;
			t = qa; qa = qb; qb = t;
			String s = cheap; cheap = expensive; expensive = s;
		}
		Arrays.sort(links);
		DSU dsu = new DSU(n);
		Link[] mst = new Link[n - 1];
		int mstSize = 0;
		int mstTotal = 0;
		for (Link link : links) {
			if (dsu.same(link.a, link.b))
				continue;
			mst[mstSize++] = link;
			mstTotal += link.length;
			dsu.union(link.a, link.b);
		}
		if (mstSize < n - 1) {
			out.println("Impossible");
			in.close();
			out.close();
			return;
		}
		boolean[] poss = new boolean[qa + 1];
		int[] how = new int[qa + 1];
		poss[0] = true;
		for (int i = 0; i < n - 1; i++) {
			int add = mst[i].length;
			for (int s = qa - add; s >= 0; s--) {
				if (poss[s] && !poss[s + add]) {
					poss[s + add] = true;
					how[s + add] = i;
				}
			}
		}
		int takea = qa;
		while (!poss[takea])
			takea--;
		if (mstTotal - takea > qb) {
			out.println("Impossible");
			in.close();
			out.close();
			return;
		}
		out.println(pa * takea + pb * (mstTotal - takea));
		String[] category = new String[n - 1];
		Arrays.fill(category, expensive);
		while (takea > 0) {
			category[how[takea]] = cheap;
			takea -= mst[how[takea]].length;
		}
		for (int i = 0; i < n - 1; i++) {
			out.println((mst[i].id + 1) + " " + category[i]);
		}
		in.close();
		out.close();
	}

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