#include <bits/stdc++.h>
using namespace std;
int a[20],b[20],c[20],d[20];
int num = 0;
void ans() {
cout << "NO." << " " << ++num << endl;
for (int i = 1; i <= 8; i++) {
for (int j = 1; j <= 8; j++) {
if (a[j] == i) {
cout << "1" << " ";
}
else{
cout << "0" << " ";
}
}
cout << endl;
}
}
int dfs(int x) {
for (int i = 1; i <= 8; i++) {
if (b[i] && c[x + i - 1] && d[x - i + 8]) {
a[x] = i;
b[i] = 0;
c[x + i - 1] = 0;
d[x - i + 8] = 0;
if (x == 8)
ans();
else
dfs(x + 1);
b[i] = 1;
c[x + i - 1] = 1;
d[x - i + 8] = 1;
}
}
}
int main() {
memset(b, 1, sizeof(b));
memset(c, 1, sizeof(c));
memset(d, 1, sizeof(d));
dfs(1);
return 0;
}