import sys

def solution(L):
    N = len(L)
    for i in range(N):
        for j in range(i + 1, N):
            if L[j] - L[i] == j - i:
                return False
            if L[i] - L[j] == j - i:
                return False
    return True

def print_solution(L):
    N = len(L)
    for i in range(N):
        for _ in range(L[i]):
            print('* ', end = '')
        print('Q ', end = '')
        for _ in range(N - L[i] - 1):
            print('* ', end = '')
        print()
        
def permute_printR(pref, L):
    if not L:
        if solution(pref):
            print_solution(pref)
            print()
        return
    for i in range(len(L)):
        permute_printR(pref + [L[i]], L[:i] + L[i + 1:])

def permute_print(L):
    permute_printR([], L)
        
def enumerate(N):
    L = []
    for i in range(N):
        L += [i]
    permute_print(L)

def main():
    N = int(sys.argv[1])
    enumerate(N)

main()

# $ python queens.py 4
# * Q * * 
# * * * Q 
# Q * * * 
# * * Q * 
#
# * * Q * 
# Q * * * 
# * * * Q 
# * Q * * 
#
# $ python queens.py 8 | head -n20
# Q * * * * * * * 
# * * * * Q * * * 
# * * * * * * * Q 
# * * * * * Q * * 
# * * Q * * * * * 
# * * * * * * Q * 
# * Q * * * * * * 
# * * * Q * * * * 
#
# Q * * * * * * * 
# * * * * * Q * * 
# * * * * * * * Q 
# * * Q * * * * * 
# * * * * * * Q * 
# * * * Q * * * * 
# * Q * * * * * * 
# * * * * Q * * * 
#
# Q * * * * * * * 
# * * * * * * Q * 
# $ 
