#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// #define DEBUG

vector<int> fixedqueen;

class Board
{
    int Boardsize;
    vector<int> pos;
    vector<bool> row;
    vector<bool> column;
    vector<bool> left;
    vector<bool> right;

public:
    Board(int n);
    Board(Board &n);
    vector<int> get_pos();
    vector<bool> get_row();
    vector<bool> get_column();
    vector<bool> get_left();
    vector<bool> get_right();
    void Boardproperty();
    void printboard();
    bool setqueenok(int y, int x);
    void setqueen(int y, int x);
    void removequeen(int y, int x);
    void dfs(int y, int n);
};

vector<int> Board::get_pos()
{
    return pos;
};
vector<bool> Board::get_row()
{
    return row;
};
vector<bool> Board::get_column()
{
    return column;
};
vector<bool> Board::get_left()
{
    return left;
};
vector<bool> Board::get_right()
{
    return right;
};

Board::Board(int n)
{
    Boardsize = n;
    pos.resize(n);
    row.resize(n);
    column.resize(n);
    left.resize(2 * n - 1);
    right.resize(2 * n - 1);
    fill(pos.begin(), pos.end(), -1);
    fill(row.begin(), row.end(), false);
    fill(column.begin(), column.end(), false);
    fill(left.begin(), left.end(), false);
    fill(right.begin(), right.end(), false);
};

Board::Board(Board &n)
{
    pos = n.get_pos();
    row = n.get_row();
    column = n.get_column();
    left = n.get_left();
    right = n.get_right();
};

void Board::Boardproperty()
{
    for (auto x : pos)
        cout << " " << x;
    cout << endl;
    // for (auto x : row)
    //     cout << " " << x;
    // cout << endl;
    // for (auto x : column)
    //     cout << " " << x;
    // cout << endl;
    // for (auto x : left)
    //     cout << " " << x;
    // cout << endl;
    // for (auto x : right)
    //     cout << " " << x;
    // cout << endl;
};

void Board::printboard()
{
    char board[Boardsize][Boardsize];
    for (int i = 0; i < Boardsize; i++)
        for (int j = 0; j < Boardsize; j++)
            board[i][j] = '.';
    for (int i = 0; i < Boardsize; i++)
        board[pos[i]][i] = 'Q';

    for (int i = 0; i < Boardsize; i++)
    {
        for (int j = 0; j < Boardsize; j++)
            cout << board[i][j];
        cout << endl;
    }
};

bool Board::setqueenok(int y, int x)
{
    return (!row[y] && !column[x] && !left[y - x + Boardsize - 1] && !right[x + y]);
};

void Board::setqueen(int y, int x)
{
    pos[x] = y;
    row[y] = true;
    column[x] = true;
    left[y - x + Boardsize - 1] = true;
    right[x + y] = true;
};

void Board::removequeen(int y, int x)
{
    pos[x] = -1;
    row[y] = false;
    column[x] = false;
    left[y - x + Boardsize - 1] = false;
    right[x + y] = false;
};

void Board::dfs(int y, int n)
{
    if (y == 0)
    {
        for (int x = 0; x < Boardsize; x++)
        {
            if (setqueenok(y, x))
            {
                setqueen(y, x);

                int counter = 0;
                for (int z = 0; z < Boardsize; z++)
                    if (pos[z] == fixedqueen[z])
                        counter++;
                if (counter == n)
                    printboard();
                removequeen(y, x);
            }
        }
    }

    else
    {
        for (int x = 0; x < Boardsize; x++)
        {
            if (setqueenok(y, x))
            {
                setqueen(y, x);
                dfs(y - 1, n);
                removequeen(y, x);
            }
        }
    }
    return;
};

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif
    int boardsize = 8;
    Board board(boardsize);
    fixedqueen.resize(boardsize);
    fill(fixedqueen.begin(), fixedqueen.end(), -1);

    int n, y, x;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> y >> x;
        fixedqueen[x] = y;
    }

    board.dfs(boardsize - 1, n);

    return 0;
}



Measured memory_bytes: 3136