#include<iostream>
using namespace std;
#include<queue>
#define size 10
int board[size][size];//棋盘
class point
{
public:
int x;
int y;
};
point start,end;
queue<point> q;//辅助队列
int cur_level,next_level,level;
int dir[8][2]={ {-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1} };
int bfs()
{
point temp=start,temp2;
while( !q.empty() )
q.pop();
q.push(temp);
cur_level=1;//当前处理的那层有多少个节点
next_level=0;//下一层有多少个节点
level=0;//当前处理的是第几层
for(int i1=1;i1<=8;i1++)
for(int i2=1;i2<=8;i2++)
board[i1][i2]=0;
board[start.x][start.y]=1;
while(1)
{
while(cur_level>0)
{
cur_level--;
temp=q.front();
for(int i=0;i<8;i++)
{
temp2.x=temp.x+dir[i][0];
temp2.y=temp.y+dir[i][1];
if(temp2.x == end.x && temp2.y==end.y)
{
return level+1;
}
else
{
if( temp2.x>=1 && temp2.x<=8 && temp2.y>=1 && temp2.y<=8 && board[temp2.x][temp2.y]==0 )
{
q.push(temp2);
board[temp2.x][temp2.y]=1;
next_level++;
}
}
}
q.pop();
}
cur_level=next_level;
next_level=0;
level++;
}
}
int main()
{
char ch1,ch2,ch3,ch4;
while(cin>>ch1>>ch2>>ch3>>ch4)
{
start.y=ch1-'a'+1;
start.x=ch2-'0';
end.y=ch3-'a'+1;
end.x=ch4-'0';
cout<<"To get from "<<ch1<<ch2<<" to "<<ch3<<ch4<<" takes ";
if(start.x==end.x && start.y==end.y)
{ cout<<0;}
else cout<<bfs();
cout<<" knight moves."<<endl;
}
return 0;
}