uses
    testlib, sysutils;

const
    max_steps = 1000000;

type
    pInStream = ^InStream;

procedure rotate(var x, y: longint; cx, cy: longint);
var
    t: longint;
begin
    x := x - cx;
    y := y - cy;
    t := x; x := -y; y := t;
    x := x + cx;
    y := y + cy;
end;

function emulate(x, y, tx, ty: longint; s: pInStream): longint;
var
    step: string;
    steps: longint;
begin
    steps := 0;
    while (not s.seekeof) and (steps <= max_steps) do begin
        inc(steps);
        step := s.readWord(blanks, blanks);
        if step = '+A' then begin
            rotate(x, y, 0, 0);
            rotate(x, y, 0, 0);
            rotate(x, y, 0, 0);
        end else if step = '-A' then begin
            rotate(x, y, 0, 0);
        end else if step = '+B' then begin
            rotate(x, y, 1, 0);
            rotate(x, y, 1, 0);
            rotate(x, y, 1, 0);
        end else if step = '-B' then begin
            rotate(x, y, 1, 0);
        end else begin
            quit(_pe, format('+A, -A, +B or -B expected, "%s" found', [step]));
        end;
    end;
    if (steps > max_steps) then begin
        quit(_wa, 'Too many steps');
    end;
    emulate := sqr(x - tx) + sqr(y - ty);
end;

var
    x, y, tx, ty: longint;
    jd, pd: longint;
begin
    x := inf.readLongint();
    y := inf.readLongint();
    tx := inf.readLongint();
    ty := inf.readLongint();

    jd := emulate(x, y, tx, ty, @ans);
    pd := emulate(x, y, tx, ty, @ouf);

    if (jd = pd) then begin
        //quit(_ok, format('%d', [jd]));
        quit(_ok, format('%d (%d, %d)', [jd, tx - x, ty - y]));
    end;
    if (jd < pd) then begin
        quit(_wa, format('%d instead of %d', [pd, jd]));
    end;
    quit(_fail, format('%d instead of %d', [pd, jd]));
end.