# author: Manfred Scheucher
# date  : 04.01.2018
import sys
from itertools import permutations

def printGrid(Y):
	n = len(Y)
	for row in range(n):
		for col in range(n):
			print ("X" if Y[row]==col else "."),
		print ""

def test_involution(Y):
	for i in Y:
		if Y[Y[i]] != i: 
			return False
	return True

if len(sys.argv) < 2:
	print "usage: "+sys.argv[0]+" [n]"
	exit(0)
n = int(sys.argv[1])

N = range(n)
ct = 0
for Y in permutations(N):
	if test_involution(Y) or test_involution([n-1-y for y in Y]):
		ct += 1
		print (2*n)*"#","grid",ct
		printGrid(Y)
		print

print "total count:",ct