from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals


import random
import sys
import copy


class Reversi:
    M = 8
    DIRS = [(0, 1), (1, 0), (-1, 0), (0, -1),
            (1, 1), (-1, -1), (1, -1), (-1, 1)]

    def __init__(self):
        self.board = self.initial_board()
        self.fields = set()
        self.move_list = []
        self.history = []
        for i in range(self.M):
            for j in range(self.M):
                if self.board[i][j] is None:
                    self.fields.add((j, i))

    def initial_board(self):
        B = [[None] * self.M for _ in range(self.M)]
        B[3][3] = 1
        B[4][4] = 1
        B[3][4] = 0
        B[4][3] = 0
        return B

    def draw(self):
        for i in range(self.M):
            res = []
            for j in range(self.M):
                b = self.board[i][j]
                if b is None:
                    res.append('.')
                elif b == 1:
                    res.append('#')
                else:
                    res.append('o')
            print(''.join(res))
        print('')

    def moves(self, player, fields, board):
        res = []
        for (x, y) in fields:
            if any(self.can_beat(x, y, direction, player, board)
                   for direction in self.DIRS):
                res.append((x, y))
        return res

    def can_beat(self, x, y, d, player, board):
        dx, dy = d
        x += dx
        y += dy
        cnt = 0
        while self.get(x, y, board) == 1 - player:
            x += dx
            y += dy
            cnt += 1
        return cnt > 0 and self.get(x, y, board) == player

    def get(self, x, y, board):
        if 0 <= x < self.M and 0 <= y < self.M:
            return board[y][x]
        return None

    def do_move(self, move, player):
        assert player == len(self.move_list) % 2
        self.history.append([x[:] for x in self.board])
        self.move_list.append(move)

        if move is None:
            return
        x, y = move
        x0, y0 = move
        self.board[y][x] = player
        self.fields -= set([move])
        for dx, dy in self.DIRS:
            x, y = x0, y0
            to_beat = []
            x += dx
            y += dy
            while self.get(x, y, self.board) == 1 - player:
                to_beat.append((x, y))
                x += dx
                y += dy
            if self.get(x, y, self.board) == player:
                for (nx, ny) in to_beat:
                    self.board[ny][nx] = player

    def result(self):
        res = 0
        for y in range(self.M):
            for x in range(self.M):
                b = self.board[y][x]
                if b == 0:
                    res -= 1
                elif b == 1:
                    res += 1
        return res

    def terminal(self):
        if not self.fields:
            return True
        if len(self.move_list) < 2:
            return False
        return self.move_list[-1] is None and self.move_list[-2] is None


class Player(object):
    WEIGHTS = [[4, -3, 2, 2, 2, 2, -3, 4],
               [-3, -4, -1, -1, -1, -1, -4, -3],
               [2, -1, 1, 0, 0, 1, -1, 2],
               [2, -1, 0, 1, 1, 0, -1, 2],
               [2, -1, 0, 1, 1, 0, -1, 2],
               [2, -1, 1, 0, 0, 1, -1, 2],
               [-3, -4, -1, -1, -1, -1, -4, -3],
               [4, -3, 2, 2, 2, 2, -3, 4]]

    def __init__(self):
        self.reset()

    def heuristic(self, board):
        sum_points = 0

        for i in range(8):
            for j in range(8):
                if board[i][j] == self.my_player:
                    sum_points += self.WEIGHTS[i][j]
                elif board[i][i] == (1 - self.my_player)%2:
                    sum_points -= self.WEIGHTS[i][j]
        return sum_points

    def is_terminal(self, board, fields):
        stopper = True
        for row in board:
            for field in row:
                if field is None:
                    stopper = False
                    break
        if stopper:
            return True
        if not self.game.moves(self.my_player, fields, board):
            s_player = (self.my_player + 1)%2
            if not self.game.moves(s_player, fields, board):
                return True
        return False

    def alphabeta(self, board, depth, a, b, maximizingPlayer):
        fields = self.board_to_fields(board)
        if depth == 0 or self.is_terminal(board, fields):
            return self.heuristic(board)

        if maximizingPlayer:
            value = float('-inf')
            for child in self.game.moves(self.my_player, fields, board):
                child_state = self.move_to_board(board, child, self.my_player)
                value = max(value, self.alphabeta(child_state, depth-1, a, b, False))
                a = max(a, value)
                if a >= b:
                    break
            return value
        else:
            value = float('inf')
            player = (self.my_player + 1) % 2
            for child in self.game.moves(player, fields, board):
                child_state = self.move_to_board(board, child, player)
                value = min(value, self.alphabeta(child_state, depth-1, a, b, True))
                b = max(b, value)
                if a >= b:
                    break
            return value
    
    def move_to_board(self, board, move, player):
        board_copy = copy.deepcopy(board)
        board_copy[move[0]][move[1]] = player
        return board_copy

    def board_to_fields(self, board):
        fields = set()
        for i in range(8):
            for j in range(8):
                if board[i][j] is None:
                    fields.add((j, i))
        return fields

    def reset(self):
        self.game = Reversi()
        self.my_player = 1
        self.say('RDY')

    def say(self, what):
        sys.stdout.write(what)
        sys.stdout.write('\n')
        sys.stdout.flush()

    def hear(self):
        line = sys.stdin.readline().split()
        return line[0], line[1:]

    def loop(self):
        while True:
            cmd, args = self.hear()
            if cmd == 'HEDID':
                unused_move_timeout, unused_game_timeout = args[:2]
                move = tuple((int(m) for m in args[2:]))
                if move == (-1, -1):
                    move = None
                self.game.do_move(move, 1 - self.my_player)
            elif cmd == 'ONEMORE':
                self.reset()
                continue
            elif cmd == 'BYE':
                break
            else:
                assert cmd == 'UGO'
                assert not self.game.move_list
                self.my_player = 0

            moves = self.game.moves(self.my_player, self.game.fields, self.game.board)

            if moves:
                move = None
                value = float('-inf')
                for m in moves:
                    state = self.move_to_board(self.game.board, m, self.my_player)
                    v = self.alphabeta(state, 3, float('-inf'), float('inf'), True)
                    if v > value:
                        value = v
                        move = m
                
                self.game.do_move(move, self.my_player)
            else:
                self.game.do_move(None, self.my_player)
                move = (-1, -1)
            self.say('IDO %d %d' % move)


if __name__ == '__main__':
    player = Player()
    player.loop()