#include<iostream> using namespace std; const int N = 10; char a[N][N]; bool b[N], c[N], d[N]; int n; void dfs(int u) { if (u == n) { for (int i = 0; i < n; i++)puts(a[i]); puts(""); return; } for (int i = 0; i < n; i++) { if (!b[i] && !c[u - i] && !d[i - u + n]) { a[u][i] = 'Q'; b[i] = c[u - i] = d[i - u + n] = true; dfs(u + 1); b[i] = c[u - i] = d[i - u + n] = false; a[u][i] = '*'; } } } int main() { cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = '*'; } } dfs(0); return 0; }