logo AlgoBeat OnlineJudge
登录 注册

#216954. [ICPC 2017 Qingdao R] Chenchen, Tangtang and ZengZeng

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Chenchen, Tangtang and ZengZeng are starting a game of tic-tac-toe, played on a board.

Initially, all squares on the board are empty and they takes turns writing the first letter of their name into any of the empty squares (because Chenchen, Tangtang and ZengZeng are elites, their names have different first letters, 'C', 'T' and 'Z' respectively). The game ends when anyone of them places 3 of his letters consecutively in a row, column or diagonally. That people is declared the winner.

Write a program that, given the state of the board, determines if the game is over and who won if it is.

输入格式

The input contains several test cases up to 1000. Each case contains three lines describing the board. Each line contains 3 characters. The characters will be uppercase letters of or '.' (if the square is empty). The data will be such that there is at most one winner.

输出格式

For each case, if the game is over, output the first letter of the winner's name. If not, output "ongoing" even if the board if full.

样例

样例输入 1

4
CTZ
TCZ
CTZ
ZCT
CZC
TTZ
.C.
C.T
Z..
CTZ
.C.
CTZ

样例输出 1

Z
Z
ongoing
ongoing