#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
vector<string>strv;
int pos[9];
//放第k行的皇后
void queen(int k) {
if (k == 9) {//结束
string s = "";
for (int i = 1; i <= 8; i++) {
s += pos[i] + '0';
}
strv.push_back(s);
return;
}
if (k == 1) {
for (int i = 1; i <= 8; i++) {
pos[k] = i;
queen(k + 1);
}
}
else {
for(int i = 1; i <= 8; i++) {//列
pos[k] = i;
int j = 1;
for (; j < k; j++) {
if (i == pos[j] || abs(k - j) == abs(pos[j] - i))break;
}
if (j == k)queen(k + 1);
}
}
}
int main() {
queen(1);
int n;
while (cin >> n){
cout << strv[n - 1] << endl;
}
return 0;
}