

#include <array>
#include <set>
#include <queue>
#include <iostream>
#include <string>
using namespace std;

struct state {
    array<int, 9> s;
    int hole;
    string previous_;
    bool operator<(const state& a) const {
        return s < a.s;
    }

    bool is_final() const {
        if (hole != 8) return false;
        for (int i = 0; i < 8; i++) {
            if (s[i] != i + 1) return false;
        }
        return true;
    }

    void down() {
        if (hole < 3) return;
        swap(s[hole], s[hole - 3]);
        hole -= 3;
        previous_ += 'd';
    }

    void up() {
        if (hole >= 6) return;
        swap(s[hole], s[hole + 3]);
        hole += 3;
        previous_ += 'u';
    }

    void right() {
        if (!(hole % 3)) return;
        swap(s[hole], s[hole - 1]);
        hole--;
        previous_ += 'r';
    }

    void left() {
        if (hole % 3 == 2) return;
        swap(s[hole], s[hole + 1]);
        hole++;
        previous_ += 'l';
    }
    friend ostream& operator<<(ostream& a,const state& s) {
        for (size_t i = 0; i < 9; i++)
        {
            a << s.s[i] << ' ';
        }
        a << s.previous_;
       
        return a;
    }
};

int main()
{
    state s = { {6, 8, 2, 1, 3, 5, 7, 0, 4}, 7 };
    queue<state> todo;
    set<state> visited;
    todo.push(s);
    while (!todo.empty()) {
        s = todo.front();
        todo.pop();
       
        //cout << s << endl;

        if (s.is_final()) {
            cout << s << endl;
            cout << "ok" << endl;
            return 0;
        }
        if (visited.count(s)) continue;
        visited.insert(s);
        state s2 = s;
        s2.up();
        if (!visited.count(s2)) {
            todo.push(s2);
        }
        s2 = s;
        s2.down();
        if (!visited.count(s2)) {
            todo.push(s2);
        }
        s2 = s;
        s2.left();
        if (!visited.count(s2)) {
            todo.push(s2);
        }
        s2 = s;
        s2.right();
        if (!visited.count(s2)) {
            todo.push(s2);
        }
    }
    cout << "smula" << endl;
    return 0;
}

