table = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8],
         [0, 4, 8], [2, 4, 6]]
check = ->(field, type) {table = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8],
         [0, 4, 8], [2, 4, 6]]
check = ->(field, type) {
  table.each do |pat|
    return true if pat.map {|i| field[i] == type}.all?
  end
  false
}
game = ->(field, left) {
  if check.(field, "o")
      "o"
  elsif check.(field, "x")
      "x"
  else
    nxt = (left.size % 2).zero? ? "x" : "o"
    left.each do |pos|
      table[pos] = nxt
      a = game.(table, left.reject {|i| i == pos})
      return a if a
      table[pos] = "s"
    end
    false
  end
}
         
$<.readlines.map(&:chomp).map(&:chars).each do |field|
  left = field.map {|i| i == "s" ? i : nil}.compact
  result = game.(field, left)
  puts result ? result : "d"
end
  table.each do |pat|
    return true if pat.map {|i| field[i] == type}.all?
  end
  false
}
game = ->(field, left) {
  if check.(field, "o")
      "o"
  elsif check.(field, "x")
      "x"
  else
    nxt = (left.size % 2).zero? ? "x" : "o"
    try = proc {|f|
      left.each do |pos|
        field[pos] = nxt
        a = f.()
        return a if a
        field[pos] = "s"
      end
    }
    try.(->{ check.(field, left.reject {|i| i == pos}) })
    try.(->{ game .(field, left.reject {|i| i == pos}) })
    false
  end
}
         
$<.readlines.map(&:chomp).map(&:chars).each do |field|
  left = field.map {|i| i == "s" ? i : nil}.compact
  result = game.(field, left)
  puts result ? result : "d"
end
