#define FOR(i,n) for(int i=0; i<n; ++i)
#define GET(type,name) type name; std::cin >> name;

#include <iostream>
#include <vector>
#include <utility>
#include <utility>
#include <algorithm>
#include <numeric>


inline std::pair<int, int> min_max_in_the_same_line(const std::vector<std::vector<int>>& a){
      int n = a.size();
      std::vector<int> left(n);
      std::vector<int> up(n);
      std::vector<int> upleft(2*n-1); // (7,0) --> 0, (0,0) --> 7, (0,7) --> 14
      std::vector<int> upright(2*n-1); // (7,0) --> 7, (0,0) --> 0, (0,7) --> 14
      FOR(i,n){
        FOR(j,n){
          left[i] += a[i][j];
          up[j] += a[i][j];
          upleft[n - 1 - i + j] += a[i][j];
          upright[i+j] +=  a[i][j];
        }
      }
      int M = std::max(
        std::max(*std::max_element(left.begin(), left.end()), *std::max_element(upleft.begin(), upleft.end())),
        std::max(*std::max_element(up.begin(), up.end()), *std::max_element(upright.begin(), upright.end()))
      );
      int m = std::min(
        std::min(*std::min_element(left.begin(), left.end()), *std::min_element(upleft.begin(), upleft.end())),
        std::min(*std::min_element(up.begin(), up.end()), *std::min_element(upright.begin(), upright.end()))
      );
  //    std::cout << m << ", " <<  M <<std::endl;
      return std::make_pair(m, M);
    };
  inline bool is_valid_board(const std::vector<std::vector<int>>& a){
    return min_max_in_the_same_line(a).second <= 1;
  }

  inline bool is_completed_board(const std::vector<std::vector<int>>& a){
    int s=0;
    auto n = a.size();
    FOR(i,n){
      FOR(j,n){
        if(a[i][j]==1) s+=1;
      }
    }
    return is_valid_board(a) and s==n;
  }


  std::vector<std::vector<int>> rec_8queen_solve(std::vector<std::vector<int>> a){
//    std::cout << 'x' << std::endl;
    int n = a.size();
//    FOR(p, n){
//      FOR(q, n){
//        std::cout << a[p][q];
//      }
//      std::cout<<std::endl;
//    }


    if(is_completed_board(a)){
//      std::cout << 'a' << std::endl;
      return a;
    }

    if(not is_valid_board(a)){
//      std::cout << 'b' << std::endl;
      return a;
    }

//    std::cout << 'c' << std::endl;

    FOR(i,n) {
      FOR(j, n) {
        std::vector<std::vector<int>> a_next = a;
        a_next[i][j] += 1;
        if(is_valid_board(a_next)){

//          std::cout << 'C' << n << std::endl;

          auto b = rec_8queen_solve(a_next);
//          std::cout << 'B' << std::endl;

          if(is_completed_board(b)){
//            std::cout << 'A' << std::endl;

            return b;
          }
        }
      }
    }

//    std::cout << 'd' << std::endl;


    return a;
  };

  int main(){
    int n = 8;
    GET(int, k)
    std::vector<std::vector<int>> a (n, std::vector<int>(n));
//    std::vector<int> left(8);
//    std::vector<int> up(8);
//    std::vector<int> upleft(15); // (7,0) --> 0, (0,0) --> 7, (0,7) --> 14

    FOR(i, k){
      GET(int, r);
      GET(int, c);
      a[r][c] = 1;
//      left[r] += 1;
//      up[c] += 1;
//      upleft[7-r+c] += 1;
    }

    auto solved_board = rec_8queen_solve(a);
//    std::cout<<"z"<<std::endl;
    FOR(i, n){
      FOR(j, n){
        std::cout << (solved_board[i][j]==1 ? 'Q' : '.');
      }
      std::cout<<std::endl;
    }
  };

Measured memory_bytes: 3168