// 八数码问题有解的充要条件是 逆序对的数量一定是偶数
//估价函数:所有点当前位置和真实位置的曼哈都距离差之和. (因为每一步增加/减少曼哈顿距离1, 估价函数接近真实值)
//如果是0, 就是朴素BFS?
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<unordered_map>
using namespace std;
#define x first
#define y second
typedef pair<int , string> PIS;
priority_queue<PIS, vector<PIS>, greater<PIS>> heap;
unordered_map<string, int> dist;
unordered_map<string, pair<char, string>> pre;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
char op[5] = "urdl";
int f(string state)
{
int res;
for (int i = 0; i < 9; i ++ )
{
if (state[i] != 'x')
{
int t = state[i] - '1';
res += abs(t / 3 - i / 3) + abs(t % 3 - i % 3);
}
}
//cout << res << endl;
return res;
}
string bfs(string start)
{
string end = "12345678x";
heap.push({f(start), start});
dist[start] = 0;
while (heap.size())
{
PIS t = heap.top();
heap.pop();
string state = t.y;
if (state == end) break;
int x, y;
for (int i = 0; i < 9; i ++ )
{
if (state[i] == 'x')
{
x = i / 3, y = i % 3;
break;
}
}
string source = state;
for (int i = 0; i < 4; i ++ )
{
int nx = x + dx[i], ny = y + dy[i];
if (nx < 0 || nx >= 3 || ny < 0 || ny >= 3) continue;
state = source;
swap(state[x * 3 + y], state[nx * 3 + ny]);
if (!dist.count(state) || dist[state] > dist[source] + 1)
{
dist[state] = dist[source] + 1;
heap.push({dist[state] + f(state), state});
pre[state] = {op[i], source};
//cout << state << endl;
}
}
}
string res;
while (end != start)
{
res += pre[end].x;
end = pre[end].y;
}
reverse(res.begin(), res.end());
//cout << res << endl;
return res;
}
int main()
{
string state, seq;
for (int i = 0; i < 9; i ++ )
{
char c;cin >> c;
state += c;
if (c != 'x') seq += c;
}
int rev;
for (int i = 0; i < 8; i ++ )
for (int j = i; j < 8; j ++ )
{
if (seq[i] > seq[j]) rev ++;
}
if (rev & 1) cout << "unsolvable" << endl;
else cout << bfs(state) << endl;
return 0;
}