from sys import stdin

N = 8

FREE = -1

NOT_FREE = 1

row = [FREE] * N

col = [FREE] * N

dpos = [FREE] * (2 * N - 1)

dneg = [FREE] * (2 * N - 1)

X = [[False] * N for _ in range(N)]

n = int(stdin.readline())

for _ in range(0, n):

    r, c = list(map(int, stdin.readline().split()))

    X[r][c] = True

def printBoard():

    for i in range(0, N):

        for j in range(0, N):

            if X[i][j] != 0 and row[i] != j: return

    for i in range(0, N):

        print(("." * row[i] + "Q" + "." * (8 - row[i] - 1)))

def recursive(i):

    if i == N:

        printBoard()

        return

    for j in range(0, N):

        if (NOT_FREE == col[j] or

            NOT_FREE == dpos[i + j] or

            NOT_FREE == dneg[i - j + N - 1]): continue

        row[i] = j

        col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE

        recursive(i + 1)

        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE

recursive(0)
from sys import stdin

from itertools import permutations as per

def check(queen):

    for r1, c1 in queen:

        if not all((r1 == r2 and c1 == c2) or (r1 + c1 != r2 + c2 and r1 - c1 != r2 - c2) for r2, c2 in queen):

            return False

    return True

k = int(stdin.readline())

R, C = [[i for i in range(8)] for _ in range(2)]

q = []

for _ in range(k):

    r, c = list(map(int, stdin.readline().split()))

    q.append((r, c))

    R.remove(r)

    C.remove(c)

for l in per(C):

    q_tmp = q[:] + [(r, c) for r, c in zip(R, l)]

    if check(q_tmp):

        for i, j in sorted(q_tmp):

            print(("." * j + "Q" + "." * (8 - j - 1)))

        break
from sys import stdin

N = 8
FREE = -1
NOT_FREE = 1
row = [FREE] * N
col = [FREE] * N
dpos = [FREE] * (2 * N - 1)
dneg = [FREE] * (2 * N - 1)
X = [[False] * N for _ in range(N)]
n = int(stdin.readline())
for _ in range(0, n):
    r, c = list(map(int, stdin.readline().split()))
    X[r][c] = True


def printBoard():
    for i in range(0, N):
        for j in range(0, N):
            if X[i][j] != 0 and row[i] != j:
                return
    for i in range(0, N):
        print(("." * row[i] + "Q" + "." * (8 - row[i] - 1)))


def recursive(i):
    if i == N:
        printBoard()
        return
    for j in range(0, N):
        if (
            NOT_FREE == col[j]
            or NOT_FREE == dpos[i + j]
            or NOT_FREE == dneg[i - j + N - 1]
        ):
            continue
        row[i] = j
        col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE
        recursive(i + 1)
        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE


recursive(0)

from sys import stdin
from itertools import permutations as per


def check(queen):
    for r1, c1 in queen:
        if not all(
            (r1 == r2 and c1 == c2) or (r1 + c1 != r2 + c2 and r1 - c1 != r2 - c2)
            for r2, c2 in queen
        ):
            return False
    return True


k = int(stdin.readline())
R, C = [[i for i in range(8)] for _ in range(2)]
q = []
for _ in range(k):
    r, c = list(map(int, stdin.readline().split()))
    q.append((r, c))
    R.remove(r)
    C.remove(c)
for l in per(C):
    q_tmp = q[:] + [(r, c) for r, c in zip(R, l)]
    if check(q_tmp):
        for i, j in sorted(q_tmp):
            print(("." * j + "Q" + "." * (8 - j - 1)))
        break

- -N = 8 -FREE = -1 -NOT_FREE = 1 -row = [FREE] * N -col = [FREE] * N -dpos = [FREE] * (2 * N - 1) -dneg = [FREE] * (2 * N - 1) -X = [[False] * N for _ in range(N)] -n = int(stdin.readline()) -for _ in range(0, n): -    r, c = list(map(int, stdin.readline().split())) -    X[r][c] = True +from itertools import permutations as per -def printBoard(): -    for i in range(0, N): -        for j in range(0, N): -            if X[i][j] != 0 and row[i] != j: -                return -    for i in range(0, N): -        print(("." * row[i] + "Q" + "." * (8 - row[i] - 1))) +def check(queen): +    for r1, c1 in queen: +        if not all( +            (r1 == r2 and c1 == c2) or (r1 + c1 != r2 + c2 and r1 - c1 != r2 - c2) +            for r2, c2 in queen +        ): +            return False +    return True -def recursive(i): -    if i == N: -        printBoard() -        return -    for j in range(0, N): -        if ( -            NOT_FREE == col[j] -            or NOT_FREE == dpos[i + j] -            or NOT_FREE == dneg[i - j + N - 1] -        ): -            continue -        row[i] = j -        col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE -        recursive(i + 1) -        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE - - -recursive(0) +k = int(stdin.readline()) +R, C = [[i for i in range(8)] for _ in range(2)] +q = [] +for _ in range(k): +    r, c = list(map(int, stdin.readline().split())) +    q.append((r, c)) +    R.remove(r) +    C.remove(c) +for l in per(C): +    q_tmp = q[:] + [(r, c) for r, c in zip(R, l)] +    if check(q_tmp): +        for i, j in sorted(q_tmp): +            print(("." * j + "Q" + "." * (8 - j - 1))) +        break