#include <bits/stdc++.h>
using namespace std;
bool is_finish = false;
bool solve_queen(vector<vector<char>> &board)
{
    vector<vector<char>> tmp = board;
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            tmp = board;
            if (tmp[i][j] == '0')
            {
                tmp[i][j] = 'Q';
                int count_q = 0;
                for (int ii = 0; ii < 8; ii++)
                {
                    for (int jj = 0; jj < 8; jj++)
                    {
                        if (tmp[ii][jj] == 'Q')
                        {
                            count_q++;
                        }
                    }
                }
                if (count_q == 8)
                {
                    for (int ii = 0; ii < 8; ii++)
                    {
                        for (int jj = 0; jj < 8; jj++)
                        {
                            if (tmp[ii][jj] == 'Q')
                            {
                                cout << 'Q';
                            }
                            else
                            {
                                cout << '.';
                            }
                        }
                        cout << endl;
                    }
                    is_finish = true;
                    return false;
                }
                for (int r = 0; r < 8; r++)
                {
                    if (r == i)
                    {
                        continue;
                    }
                    tmp[r][j] = '1';
                }
                for (int c = 0; c < 8; c++)
                {
                    if (c == j)
                    {
                        continue;
                    }
                    tmp[i][c] = '1';
                }
                int v[4][2] = {{-1, -1}, {1, 1}, {1, -1}, {-1, 1}};
                for (int s = 1; s < 8; s++)
                {
                    for (int t = 0; t < 4; t++)
                    {
                        int r1 = i + s * v[t][0];
                        int c1 = j + s * v[t][1];
                        if (r1 >= 0 && r1 <= 7 && c1 >= 0 && c1 <= 7)
                        {
                            tmp[r1][c1] = '1';
                        }
                    }
                }
                if (is_finish)
                {
                    return false;
                }
                else
                {
                    solve_queen(tmp);
                }
            }
        }
    }
}

int main()
{
    int k;
    cin >> k;
    int r[k], c[k];
    vector<vector<char>> board(8, vector<char>(8, '0'));
    for (int i = 0; i < k; i++)
    {
        cin >> r[i] >> c[i];
        board[r[i]][c[i]] = 'Q';
        for (int ri = 0; ri < 8; ri++)
        {
            if (ri == r[i])
            {
                continue;
            }
            board[ri][c[i]] = '1';
        }
        for (int ci = 0; ci < 8; ci++)
        {
            if (ci == c[i])
            {
                continue;
            }
            board[r[i]][ci] = '1';
        }
        int v[4][2] = {{-1, -1}, {1, 1}, {1, -1}, {-1, 1}};
        for (int s = 1; s < 8; s++)
        {
            for (int t = 0; t < 4; t++)
            {
                int r1 = r[i] + s * v[t][0];
                int c1 = c[i] + s * v[t][1];
                if (r1 >= 0 && r1 <= 7 && c1 >= 0 && c1 <= 7)
                {
                    board[r1][c1] = '1';
                }
            }
        }
    }
    int count_q = 0;
    for (int ii = 0; ii < 8; ii++)
    {
        for (int jj = 0; jj < 8; jj++)
        {
            if (board[ii][jj] == 'Q')
            {
                count_q++;
            }
        }
    }
    if (count_q == 8)
    {
        for (int ii = 0; ii < 8; ii++)
        {
            for (int jj = 0; jj < 8; jj++)
            {
                if (board[ii][jj] == 'Q')
                {
                    cout << 'Q';
                }
                else
                {
                    cout << '.';
                }
            }
            cout << endl;
        }
        is_finish = true;
        return false;
    }
    solve_queen(board);
}


Measured memory_bytes: 3152