Program zadatak_2;
uses strutils;

type pacijent = record
    grupa : string;
    broj, O, A, B, AB : longint;
    end;

var n, o, a, b, ab, u, i : longint;
    p, s : string;
    k : array[1..10000] of pacijent;
begin
    readln(n);
    readln(s);

    u := pos(' ', s);
    val(leftstr(s, (u - 1)), o);
    delete(s, 1, u);
    u := pos(' ', s);
    val(leftstr(s, (u - 1)), a);
    delete(s, 1, u);
    u := pos(' ', s);
    val(leftstr(s, (u - 1)), b);
    delete(s, 1, u);
    val(s, ab);

    for i := 1 to n do
    begin
        readln(p);
        if p[2] = 'B' then
        begin
            k[i].grupa := 'AB';
            val(rightstr(p, length(p) - 3), k[i].broj);
        end
        else begin
            k[i].grupa := p[1];
            val(rightstr(p, length(p) - 2), k[i].broj);
        end;
    end;

    for i := 1 to n do
        if k[i].grupa = 'O' then begin
            k[i].O := k[i].broj;
            o := o - k[i].broj;
        end;
    for i := 1 to n do begin
        if k[i].grupa = 'A' then begin
            if a >= k[i].broj then begin
                k[i].A := k[i].broj;
                a := a - k[i].broj;
            end
            else begin
                k[i].A := a;
                k[i].O := k[i].broj - a;
                o := o + a - k[i].broj;
                a := 0;
            end;
        end;
        if k[i].grupa = 'B' then begin
            if b >= k[i].broj then begin
                k[i].B := k[i].broj;
                b := b - k[i].broj;
            end
            else begin
                k[i].B := b;
                k[i].O := k[i].broj - b;
                o := o + b - k[i].broj;
                b := 0;
            end;
        end;
    end;
    for i := 1 to n do begin
        if k[i].grupa = 'AB' then begin
            if ab >= k[i].broj then begin
                k[i].AB := k[i].broj;
                ab := ab - k[i].broj;
            end
            else begin
                if (a + ab) >= k[i].broj then begin
                    k[i].AB := ab;
                    k[i].A := k[i].broj - ab;
                    a := a + ab - k[i].broj;
                    ab := 0;
                end
                else begin
                    if (a + b + ab) >= k[i].broj then begin
                        k[i].AB := ab;
                        k[i].A := a;
                        k[i].B := k[i].broj - a - ab;
                        b := b + a + ab - k[i].broj;
                        ab := 0;
                        a := 0;
                    end
                    else begin
                        k[i].AB := ab;
                        k[i].A := a;
                        k[i].B := b;
                        k[i].O := k[i].broj - a - b - ab;
                        o := o + a + b + ab - k[i].broj;
                        ab := 0;
                        a := 0;
                        b := 0;
                    end;
                end;
            end;
        end;
    end;

    if o < 0 then
        writeln('nemoguce')
    else begin
        writeln('moguce');
        for i := 1 to n do
            writeln(k[i].O, ' ', k[i].A, ' ', k[i].B, ' ', k[i].AB);
    end;
end.