BFS
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
class Node{
int x;
int y;
String s;
String s1;
public Node(int x, int y, String s,String s1) {
super();
this.x = x;
this.y = y;
this.s = s;
this.s1 = s1;
}
}
public class Main {
private static int[] dx = new int[] {-1,1,0,0};
private static int[] dy = new int[] {0,0,-1,1};;
private static String dstr = "udlr";
private static String end = "12345678x";
public static void main(String[] args) {
Queue<Node> queue = new LinkedList<Node>();
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
String[] string = str.split(" ");
String str1 = "";
for(String s1 :string) {
str1 += s1;
}
Set<String> set = new HashSet<String>();
set.add(str1);
int pos = str1.indexOf("x");
queue.add(new Node(pos / 3, pos % 3, "",str1));
int flag = 0;
Node res = null;
while(!queue.isEmpty()) {
int size = queue.size();
for(int i = 0;i < size;i++) {
Node node = queue.peek();
if(node.s1.equals(end)) {
flag = 1;
res = node;
break;
}
StringBuffer s2 = new StringBuffer(node.s1);
int oldPos = s2.indexOf("x");
queue.poll();
for(int j = 0;j < 4;j++) {
int x1 = node.x + dx[j];
int y1 = node.y + dy[j];
int newPos = x1 * 3 + y1 % 3;
if(x1 >= 0 && x1 < 3 && y1 >= 0 && y1 < 3) {
char ch = s2.charAt(newPos);
s2.setCharAt(newPos, 'x');
s2.setCharAt(oldPos, ch);
if(!set.contains(s2.toString())) {
queue.add(new Node(x1, y1, node.s + dstr.charAt(j),s2.toString()));
set.add(s2.toString());
}
s2.setCharAt(oldPos, 'x');
s2.setCharAt(newPos, ch);
}
}
}
if(flag == 1) break;
}
if(res != null) {
System.out.println(res.s);
}else {
System.out.println("unsolvable");
}
}
}