main = interact $ unlines . map tic_tac_toe . lines
tic_tac_toe board
 | judge 'o' = "o" 
 | judge 'x' = "x"
 | otherwise = "d"
  where 
   win = ["111000000","000111000","000000111","100100100","010010010","001001001","100010001","001010100"]
   judge c = or $ map ((==3) . length . filter (== (c,'1')) . zip board) win