#include <iostream>
#include <cstdlib>

using namespace std;

const int N= 6;
const int N2= N*N;

int sol= 0;
int tab[N][N];

const int m[8][2] = {
    { -1, -2 }, { -1,  2 }, {  1, -2 }, {  1,  2 },
    { -2, -1 }, { -2,  1 }, {  2, -1 }, {  2,  1 }
};

bool SePuede(int x, int y)
{
   return 0<=x && x<N && 0<=y && y<N && tab[x][y]==0;
}

void Poner(int k, int x, int y)
{
   tab[x][y]= k;
}

void intento(int n, int x, int y)
{
   Poner(n, x, y);
   if (n==N2)
     {
      for (int a=0; a<N; a++)
         {
          for (int b=0; b<N; b++) 
             {
              cout.width(3);
              cout << tab[a][b];
             } 
          cout << endl;
         }
      cout << "--- " << ++sol << " ---\n";
     }
   else
     {
      for (int k=0; k<8; k++)
         {
          int a= x + m[k][0];
          int b= y + m[k][1];
          if (SePuede(a,b))
             intento(n+1, a,b);
         }
     }
  Poner(0, x, y);
}

int main(void)
{
    for (int x=0; x<N; x++)
       for (int y=0; y<N; y++)
          Poner(0,x,y);
    intento(1,0,0);
    return EXIT_SUCCESS;
}

