// Задача "Шахматная головоломка"
// XVIII командный чемпионат школьников Санкт-Петербурга по программированию
// Автор задачи: Виталий Аксенов
// Автор чекера: Владимир Ульянцев, ulyantsev@rain.ifmo.ru

uses
    testlib, Math, SysUtils;
type
    int = longint;

function is_rock_beat_position(rx, ry, x, y : int) : boolean;
begin
    result := (rx = x) or (ry = y);
end;

function is_bishop_beat_position(bx, by, x, y : int) : boolean;
begin
    result := (bx - x = by - y) or (bx + by = x + y);
end;

var
    kx, ky, rx, ry, bx, by : int;
    s1, s2 : string;
begin
    s1 := inf.readstring;
    kx := ord(s1[2]) - ord('0');
    ky := ord(s1[1]) - ord('a') + 1;
    
    s1 := ouf.readstring;
    s2 := ouf.readstring;

    if (length(s1) <> 2) or (length(s2) <> 2) then begin
        quit(_wa, 'Something strange in output file');
    end;

    rx := ord(s1[2]) - ord('0');
    ry := ord(s1[1]) - ord('a') + 1;
    bx := ord(s2[2]) - ord('0');
    by := ord(s2[1]) - ord('a') + 1;

    if (rx < 1) or (8 < rx) or (ry < 1) or (8 < ry) or 
       (bx < 1) or (8 < bx) or (by < 1) or (8 < by) then begin
        quit(_wa, 'Something is out of the board');
    end;

    if (rx = kx) and (ry = ky) then begin
        quit(_wa, 'Rook and knight are on the same position');
    end;

    if (bx = kx) and (by = ky) then begin
        quit(_wa, 'Bishop and knight are on the same position');
    end;

    if (rx = bx) and (ry = by) then begin
        quit(_wa, 'Rook and bishop are on the same position');
    end;


    if not is_bishop_beat_position(bx, by, kx, ky) then begin
        quit(_wa, 'Bishop does not beat knight');
    end;

    if not is_rock_beat_position(rx, ry, kx, ky) then begin
        quit(_wa, 'Rook does not beat knight');
    end;


    if is_bishop_beat_position(bx, by, rx, ry) then begin
        quit(_wa, 'Bishop beats rook');
    end;

    if is_rock_beat_position(rx, ry, bx, by) then begin
        quit(_wa, 'Rook beats bishop');
    end;

    quit(_ok, 'OK');
end.
