$queen_poss = [nil] * 8

def valid?(new_i, new_j)

  if $queen_poss[new_i] != nil
    return false
  end

  # Check column
  $queen_poss.each{|j|
    if j == new_j
      return false
    end
  }

  i = new_i
  j = new_j
  while 0 <= i-1 && 0 <= j-1
    i -= 1
    j -= 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end

  i = new_i
  j = new_j
  while i+1 < 8 && j+1 < 8
    i += 1
    j += 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end

  i = new_i
  j = new_j
  while 0 <= i-1 && j+1 < 8
    i -= 1
    j += 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end


  i = new_i
  j = new_j
  while i+1 < 8 && 0 <= j-1
    i += 1
    j -= 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end


  return true
end

def print_queens()
  $queen_poss.each{|j|
    row = ['.'] * 8
    row[j] = 'Q'
    puts(row.join)
  }
end


$fixed_ijs = []

# Input values
_ = gets
while line = gets
  i, j = line.split(' ').map(&:to_i)
  $queen_poss[i] = j
  $fixed_ijs.push([i, j])
end


def solve(i)

  if i == 8
    print_queens()
    return true
  end

  (0...8).each{|j|
    if $fixed_ijs.include?([i,j])
      solve(i+1)
    end
    if valid?(i, j)
      $queen_poss[i] = j
      # p ['q:', $queen_poss]
      solve(i+1)
      $queen_poss[i] = nil
    end
  }

  return false
end


solve(0)
