#include<iostream>
#include<unordered_map>
#include<queue>
using namespace std;
typedef pair<string, char> PSC;
unordered_map<string, char> mp,remp;
int a, b, c, d;
queue<PSC> que,reque;
string s = "";
string temp;
string rs; char rc;
#define str first;
#define cr second;
//每次选取两个队列里面元素最少的,逐次执行弹出操作,直到队列里面的元素完全弹出
//在入队之前判断元素是否为自己已经记录的,已记录则不入队
//判断是否为对方记录的,如果是对方记录的则break
void found(string ts)
{
char rcchar = remp[ts];
char cchar = mp[ts];
string rsstr = "";
string sstr = "";
string rts = ts;
int p, rp;
for (int i = 0; i < 9; i++)
{
if (ts[i] == 'x')
{
p = i,rp = i;
}
}
while (rcchar != 'e')
{
if (rcchar == 'u')rsstr = rsstr + 'd';
if (rcchar == 'd')rsstr = rsstr + 'u';
if (rcchar == 'l')rsstr = rsstr + 'r';
if (rcchar == 'r')rsstr = rsstr + 'l';
if (rcchar == 'u')
{
swap(rts[rp], rts[rp + 3]);
rp = rp + 3;
rcchar = remp[rts];
}
else if (rcchar == 'd')
{
swap(rts[rp], rts[rp - 3]);
rp = rp - 3;
rcchar = remp[rts];
}
else if (rcchar == 'l')
{
swap(rts[rp], rts[rp + 1]);
rp = rp +1;
rcchar = remp[rts];
}
else if (rcchar == 'r')
{
swap(rts[rp], rts[rp - 1]);
rp = rp -1;
rcchar = remp[rts];
}
}
while (cchar != 's')
{
sstr = cchar+sstr;
if (cchar == 'u')
{
swap(ts[p], ts[p + 3]);
p = p + 3;
cchar = mp[ts];
}
else if (cchar == 'd')
{
swap(ts[p], ts[p - 3]);
p = p - 3;
cchar = mp[ts];
}
else if (cchar == 'l')
{
swap(ts[p], ts[p + 1]);
p = p + 1;
cchar = mp[ts];
}
else if (cchar == 'r')
{
swap(ts[p], ts[p - 1]);
p = p - 1;
cchar = mp[ts];
}
}
cout << sstr + rsstr << endl;
}
void dfs_d()
{
a = que.size();
b = reque.size();
if (a + b > 1000)
{
cout << "unsolvable" << endl;
return;
}
if (a >= b)
{
while (b--)
{
rs = reque.front().str;
rc = reque.front().cr;
reque.pop();
temp = rs;
for (int i = 0; i < 9; i++)
{
if (rs[i] == 'x')
{
if (i >= 3)
{
swap(rs[i], rs[i - 3]);
if (!remp[rs])
{
remp[rs] = 'u';
reque.push({ rs,'u' });
if (mp[rs])
{
cout << 1 << endl;
found(rs);
return;
}
}
}
rs = temp;
if (i >= 1&&i!=3&&i!=6)
{
swap(rs[i], rs[i - 1]);
if (!remp[rs])
{
remp[rs] = 'l';
reque.push({ rs,'l' });
if (mp[rs])
{
found(rs);
return;
}
}
}
rs = temp;
if (i <= 7&&i!=2&&i!=5)
{
swap(rs[i], rs[i +1]);
if (!remp[rs])
{
remp[rs] = 'r';
reque.push({ rs,'r' });
if (mp[rs])
{
found(rs);
return;
}
}
}
rs = temp;
if (i <= 5)
{
swap(rs[i], rs[i + 3]);
if (!remp[rs])
{
remp[rs] = 'd';
reque.push({ rs,'d' });
if (mp[rs])
{
found(rs);
return;
}
}
}
break;
}
}
}
}
else
{
while (a--)
{
rs = que.front().str;
rc = que.front().cr;
temp = rs;
que.pop();
for (int i = 0; i < 9; i++)
{
if (rs[i] == 'x')
{
if (i >= 3)
{
swap(rs[i], rs[i - 3]);
if (!mp[rs])
{
mp[rs] = 'u';
que.push({ rs,'u' });
if (remp[rs])
{
found(rs);
return;
}
}
}
rs = temp;
if (i >= 1&&i!=3&&i!=6)
{
swap(rs[i], rs[i - 1]);
if (!mp[rs])
{
mp[rs] = 'l';
que.push({ rs,'l' });
if (remp[rs])
{
found(rs);
return;
}
}
}
rs = temp;
if (i <= 7&&i!=5&&i!=2)
{
swap(rs[i], rs[i + 1]);
if (!mp[rs])
{
mp[rs] = 'r';
que.push({ rs,'r' });
if (remp[rs])
{
found(rs);
return;
}
}
}
rs = temp;
if (i <= 5)
{
swap(rs[i], rs[i + 3]);
if (!mp[rs])
{
mp[rs] = 'd';
que.push({ rs,'d' });
if (remp[rs])
{
found(rs);
return;
}
}
}
break;
}
}
}
}
dfs_d();
}
int main()
{
for (int i = 0; i < 9; i++)
{
char s2; cin >> s2;
s += s2;
}
remp["12345678x"] = 'e';
mp[s] = 's';
reque.push({ "12345678x",'e' });
que.push({ s,'s' });
dfs_d();
return 0;
}