#include<bits/stdc++.h>
using namespace std;
typedef pair<int, pair<string, string>> PISS; //当前距离+曼哈顿距离 操作 序列
string a;
int dir[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
char op[4] = {'u', 'd', 'l', 'r'};
int dis(string s){
int res = 0;
for(int i=0; i<9; i++){
if(s[i]!='x'){
int t = s[i]-'1';
res += abs(i/3-t/3) + abs(i%3-t%3);
}
}
return res;
}
string astra(){
string g = "12345678x";
unordered_map<string, int> vis;
priority_queue<PISS, vector<PISS>, greater<PISS>> q;
q.push({dis(a), {"", a}});
vis[a] = dis(a);
while(q.size()){
PISS t = q.top();
q.pop();
string s = t.second.second, ns = s, preop = t.second.first;
if(s==g) return t.second.first;
int x, y;
for(int i=0; i<9; i++){
if(s[i]=='x'){
x = i/3, y = i%3;
break;
}
}
for(int i=0; i<4; i++){
int xx = x+dir[i][0], yy = y+dir[i][1];
if(xx<0 || xx>=3 || yy<0 || yy>=3) continue;
ns = s;
swap(ns[x*3+y], ns[xx*3+yy]);
//如果新的情况没有出现过或者出现过但是距离更短,就用入队
if(!vis.count(ns) || vis[ns]>vis[s]+1){
vis[ns] = vis[s]+1;
q.push({vis[ns]+dis(ns), {(preop+op[i]), ns}});
}
}
}
return "";
}
int main(){
string t;
char c;
for(int i=0; i<9; i++){
cin>> c;
a += c;
if(c!='x') t += c;
}
int k = 0;
for(int i=0; i<9; i++){
for(int j=i+1; j<9; j++){
if(t[i]>t[j]) k++;
}
}
if(k%2) puts("unsolvable");
else cout<< astra()<< endl;
return 0;
}