// Greedy knapsnack algorithm
import java.util.*;
import java.io.*;

public class domestic_gk_greedy2 {
    static Scanner in;
    static PrintWriter out;

    int[] p;

    int find(int i) {
        if (p[i] != i) {
            p[i] = find(p[i]);
        }
        return p[i];
    }

    static class Edge implements Comparable<Edge> {
        private final int i, a, b, l;

        Edge(int i, int a, int b, int l) {
            this.i = i;
            this.a = a;
            this.b = b;
            this.l = l;
        }

        public int compareTo(Edge that) {
            return this.l - that.l;
        }
    }

    void run() {
        int n = in.nextInt();
        int m = in.nextInt();

        Edge[] edges = new Edge[m];
        for (int i = 0; i < m; i++) {
            edges[i] = new Edge(
                i + 1,
                in.nextInt() - 1, 
                in.nextInt() - 1, 
                in.nextInt()
            );
        }
        Arrays.sort(edges);

        int p5 = in.nextInt();
        int q5 = in.nextInt();
        int p6 = in.nextInt();
        int q6 = in.nextInt();
        int i5 = 5;
        int i6 = 6;

        if (p5 > p6) {
            int t = 0;
            t = p5; p5 = p6; p6 = t;
            t = q5; q5 = q6; q6 = t;
            t = i5; i5 = i6; i6 = t;
        }

        p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = i;
        }

        List<Edge> cedges = new ArrayList<Edge>();
        for (Edge e: edges) {
            if (find(e.a) != find(e.b)) {
                p[find(e.a)] = find(e.b);
                cedges.add(e);
            }
        }

        if (cedges.size() != n - 1) {
            out.println("Impossible\n");
            return;
        }

        boolean[] f = new boolean[q5 + 1];
        Edge[] p = new Edge[q5 + 1];
        f[0] = true;
        for (Edge e : cedges) {
            int l = e.l;
            for (int i = q5; i >= l; i--) {
                if (!f[i] & f[i - l]) {
                    f[i] = true;
                    p[i] = e;
                    break;
                }
            }
        }

        Set<Edge> edges5 = new HashSet<Edge>();
        Set<Edge> edges6 = new HashSet<Edge>(cedges);

        int j = q5;
        while (!f[j]) j--;

        while (j > 0) {
            edges5.add(p[j]);
            edges6.remove(p[j]);
            j -= p[j].l;
        }

        int l5 = 0;
        for (Edge e : edges5) l5 += e.l;
        int l6 = 0;
        for (Edge e : edges6) l6 += e.l;

        if (l5 <= q5 && l6 <= q6) {
            out.format("%d\n", p5 * l5 + p6 * l6);
            for (Edge e : edges5) {
                out.format("%d %d\n", e.i, i5);
            }
            for (Edge e : edges6) {
                out.format("%d %d\n", e.i, i6);
            }
        } else {
            out.println("Impossible\n");
        }
    }

    public static void main(String[] args) throws IOException {
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);
        new domestic_gk_greedy2().run();
        out.close();
    }
}
