using System;
using System.Linq;
using System.Collections.Generic;
class EightQueen
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var rc = Enumerable.Range(0, n)
			.Select(_ => Console.ReadLine());
		
		var board = new Board(rc);
        board.InitAttackedArea();
        
        var resultBoard = Board.Explore(board) ?? board;
        
        resultBoard.Nodes.ForEach(row => Console.WriteLine(string.Join("", row.Select(x => x.QueenExists ? "Q" : ".").ToArray())));
	}
}

public class Board
{
    public Node[][] Nodes{ get; set; }
 	const int Size = 8;
   
	public Board(IEnumerable<string> rc)
	{
		var queens = rc.Select(x => x.Split())
			.Select(x => new { Row = int.Parse(x[0]), Column = int.Parse(x[1]) })
			.ToArray();
		
		Nodes = Enumerable.Range(0, Size)
			.Select(row => Enumerable
				.Range(0, Size)
				.Select(column => new Node{ QueenExists = queens.Any(x => x.Row == row && x.Column == column) })
                .ToArray())
            .ToArray();
	}
    
    public void InitAttackedArea()
    {
        Nodes.ForEach((x, row) => x.ForEach((node, column) =>
        {
            ApplyAttackedArea(row, column, true);
        }));
    }
    
    public void ApplyAttackedArea(int row, int column, bool isChecked = false)
    {
        var node = Nodes[row][column];
        if (!node.QueenExists)
            return; 
        
        // row
        Nodes[row].ForEach(x =>             
        {
            x.IsAttackedArea = true;
            x.Checked = isChecked;
        });
        
        // column
        Nodes.ForEach(rows => 
        {
            rows[column].IsAttackedArea = true;
            rows[column].Checked = isChecked;
        });
        
        // from left top to right bottom
        for (int r = row - Size, c = column - Size; r < Size && c < Size; r++, c++)
        {
            if (r >= Size || c >= Size || r < 0 || c < 0)
                continue;
            
            Nodes[r][c].IsAttackedArea = true;
            Nodes[r][c].Checked = isChecked;
        }
        
        // from right top to left bottom
        for (int r = row - Size, c = column + Size; r < Size && c >= 0; r++, c--)
        {
            if (r >= Size || c >= Size || r < 0 || c < 0)
                continue;
            
            Nodes[r][c].IsAttackedArea = true;
            Nodes[r][c].Checked = isChecked;
        }
    }
    
    public Board(Board board)
    {
        Nodes = board.Nodes.Select(x => x.Select(y => new Node{ IsAttackedArea = y.IsAttackedArea, QueenExists = y.QueenExists }).ToArray()).ToArray();
    }
    
    public Board Clone()
    {  
        return new Board(this);
    }
   
    public static Board Explore(Board board)
    {
        return Enumerable.Range(0, Size)
            .Where(row => board.Nodes[row].All(x => !x.QueenExists))
            .Select(row => Enumerable.Range(0, Size).Select(column => Explore(board, row, column)).FirstOrDefault(x => x != null))
            .FirstOrDefault();
    }
    
    public static Board Explore(Board board, int r, int c)
    {
        if (r >= Size)
            return board;
            
        if (board.Nodes[r][c].IsAttackedArea)
            return null;
            
        board.Nodes[r][c].Checked = true;
        
        var b = board.Clone();
        b.Nodes[r][c].QueenExists = true;
        
        b.ApplyAttackedArea(r, c);
        
        var nextRow = Enumerable.Range(r + 1, Size - (r + 1))
            .Where(x => b.Nodes[x].All(node => !node.QueenExists))
            .DefaultIfEmpty(Size)
            .Min();
        
        if (nextRow >= Size)
            return b;
        
        return Enumerable.Range(0, Size)
            .Where(x => !b.Nodes[nextRow][x].IsAttackedArea)
            .Select(x => Explore(b, nextRow, x))
            .FirstOrDefault(x => x != null);
    }
}

public class Node
{
    public bool Checked { get; set; }
    public bool QueenExists { get; set; }
    public bool IsAttackedArea { get; set; }
}

public static class MyExtensions
{
	public static void ForEach<T>(this IEnumerable<T> e, Action<T> action)
	{
		foreach (var element in e) action(element);
	}
	
	public static void ForEach<T>(this IEnumerable<T> e, Action<T, int> action)
	{
		var i = 0;
		foreach (var element in e) action(element, i++);
	}
}

Measured memory_bytes: 20392