#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;

string stuph[6][6];

void resetstuph(){
     for (int i = 0; i<6; i++)
         for (int j = 0; j<6; j++)
             stuph[i][j] = '.';
}

bool findturns(int num) {
     if (num == 1 || num == 2 || num == 4 || num == 6 || num == 9 || num == 12 || num == 16) return true;
     return false;
}

int main() {
    ifstream in;
    in.open ("DATA4.txt");
    ofstream out;
    out.open ("OUT4.txt");
    int num, cols, rows, x, y, dir;
    for (int j = 0; j<5; j++) {
        resetstuph();
        in >> num;
        rows = 0;
        cols = 0;
        if (num<=1) {
           out << "0" << endl;
           if (num == 1) out << 1 << endl;
           continue;
        } else if (num<=3) {
           cols = 2;
           rows = 2;
           x = 0;
           y = 0;
        } else if (num<=5) {
           cols = 2;
           rows = 3;
           x = 0;
           y = 1;
        } else if (num<=8) {
           cols = 3;
           rows = 3;
           x = 1;
           y = 1;
        } else if (num<=11) {
           cols = 3;
           rows = 4;
           x = 1;
           y = 1;
        } else if (num<=15) {
           cols = 4;
           rows = 4;
           x = 1;
           y = 1;
        } else if (num<=19) {
           cols = 4;
           rows = 5;
           x = 1;
           y = 2;
        } else if (num<=20) {
           cols = 5;
           rows = 5;
           x = 2;
           y = 2;
        }
        dir = 0;
        for (int curr = 0; curr<=num; curr++) {
            stringstream outstr;
            outstr << curr;
            stuph[x][y]=outstr.str();
            if (findturns(curr)) dir++;
            if (dir > 3) dir = 0;
            if (dir ==0) y++;
            else if (dir ==1) x++;
            else if (dir ==2) y--;
            else if (dir ==3) x--;
        }
        //out << endl << endl << num << ": " << rows << ", " << cols << endl;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++)
                out << stuph[j][i];
            out << endl;
        }
    }
    in.close();
    out.close();
}

