BLANK = 0
O = 1
X = -1
H = 8
W = 8

def put!(field, y, x, color)
  field[y][x] = color
  dy = [-1, -1, -1, 0, 1, 1, 1, 0]
  dx = [-1, 0, 1, 1, 1, 0, -1, -1]
  8.times do |i|
    ny = y + dy[i]
    nx = x + dx[i]
    count = 0
    while field[ny][nx] == -color do
      count += 1
      ny += dy[i]
      nx += dx[i]
    end
    next if field[ny][nx] != color || count == 0
    ny = y + dy[i]
    nx = x + dx[i]
    while field[ny][nx] == -color do
      field[ny][nx] = color
      ny += dy[i]
      nx += dx[i]
    end
  end
  1
end

def put?(field, y, x, color)
  return 0 if field[y][x] != BLANK
  sum = 0
  dy = [-1, -1, -1, 0, 1, 1, 1, 0]
  dx = [-1, 0, 1, 1, 1, 0, -1, -1]
  8.times do |i|
    ny = y + dy[i]
    nx = x + dx[i]
    count = 0
    while field[ny][nx] == -color do
      count += 1
      ny += dy[i]
      nx += dx[i]
    end
    next if field[ny][nx] != color || count == 0
    sum += count
  end
  sum
end

def mami(field)
  max = y = x = 0
  for i in 1..H do
    for j in 1..W do
      count = put?(field, i, j, O)
      next if max >= count
      max = count
      y = i
      x = j
    end
  end
  max > 0 ? put!(field, y, x, O) : 0
end

def witch(field)
  max = y = x = 0
  H.downto(1) do |i|
    W.downto(1) do |j|
      count = put?(field, i, j, X)
      next if max >= count
      max = count
      y = i
      x = j
    end
  end
  max > 0 ? put!(field, y, x, X) : 0
end

field = Array.new(H+2) {Array.new(W+2, BLANK)}
for i in 1..H do
  field[i][1, W] = gets.chomp.chars.map{|c| c == "o" ? O : (c == "x" ? X : BLANK)}
end

turn = O
pass = 0
while true do
  case turn
    when O
      mami(field) > 0 ? pass = 0 : pass += 1
    when X
      witch(field) > 0 ? pass = 0 : pass += 1
  end
  break if pass == 2
  turn *= -1
end

for i in 1..H do
  field[i][1,W].map{|c| putc c == 0 ? "." : (c == 1 ? "o" : "x")}
  puts
end