{$q+,r+}
uses
    sysutils;

const
    max_m = 200000;
    max_n = 100000;
var
    i, j, n, m: longint;
    b, e, t: array [1..max_m] of longint;
    u: array [1..max_m] of boolean;
    c: array [0..1] of longint;
    p: array[1..max_n] of longint;

function find(i: longint): longint;
begin
    if (i <> p[i]) then begin
        p[i] := find(p[i]);
    end;
    find := p[i];
end;

procedure union(i, j: longint);
begin
    i := find(i);
    j := find(j);
    if random > 0.5 then begin
        p[i] := j;
    end else begin
        p[j] := i;
    end;
end;

begin
    reset(input, 'roads.in');
    rewrite(output, 'roads.out');

    read(n, m, c[0], c[1]);
    for i := 1 to m do begin
        read(b[i], e[i], t[i]);
        assert(e[i] <> b[i]);
    end;

    for i := 1 to n do begin
        p[i] := i;
    end;

    for j := 0 to 2 do begin
        for i := 1 to m do begin
            if (t[i] = j) and (c[j] > 0) and (find(b[i]) <> find(e[i])) then begin
                u[i] := true;
                union(b[i], e[i]);
                dec(c[j]);
            end;
        end;
    end;

    if (c[0] + c[1] > 0) then begin
        writeln('Impossible');
    end else begin
        for i := 1 to m do begin
            if u[i] then begin
                write(i, ' ');
            end;
        end;
    end;
end.
