#include <iostream>
#include <array>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;

using state = array<array<int, 3>,3>;


bool is_solved(const state& s){
  for(size_t i = 0; i<3; i++){
    for(size_t j = 0; j<3; j++){
      if (!(s[i][j] == (i*3+j+1) % 9)){
        return false;
      } 
    }
  }
  return true;
}

pair<int, int> hole_position(const state& s) {
  for(size_t i = 0; i<3; i++){
    for(size_t j = 0; j<3; j++){
      if (s[i][j] == 0){
        return {i, j};
      } 
    }
  }
  throw "Hole not found.";
}
// optimalnejsi: istream& load_input(istream&, state&)
state load_input() {
  state s;
  for(size_t i = 0; i<3; i++){
    for(size_t j = 0; j<3; j++){
      std::cin >> s[i][j];
    }
  }
  return s;
}

void print_state(const state& s){
  for(size_t i=0;i<3;++i){
    for(size_t j=0;j<3;++j){
      std::cout<<s[i][j]<<" ";
    }
    std::cout<<std::endl;
  }
  std::cout<<std::endl;
}

template <typename F>
void generate_states(const state &cur, F submit) {
  auto [i, j] = hole_position(cur);
  if (i > 0) {
    state new_state = cur;
    swap(new_state[i-1][j], new_state[i][j]);
    submit(new_state);
  }
  if (i < 2) {
    state new_state = cur;
    swap(new_state[i+1][j], new_state[i][j]);
    submit(new_state);
  }
  if (j > 0) {
    state new_state = cur;
    swap(new_state[i][j-1], new_state[i][j]);
    submit(new_state);
  }
  if (j < 2) {
    state new_state = cur;
    swap(new_state[i][j+1], new_state[i][j]);
    submit(new_state);
  }
}

int main() {
  set<state> visited;
  queue<state> q;
  map<state, state> origins;

  state s = load_input();
  q.push(s);
  visited.insert(s);


  while(!q.empty()){
    state cur = q.front();
    if(is_solved(cur)) {
      break;
    }
    q.pop();

    generate_states(cur, [&](const state& s){
      if(!visited.count(s)){
        q.push(s);
        visited.insert(s);
        origins[s] = cur;
      }
    });
  }

  if(!q.empty()) {
    cout << "Vitezstvi!" << endl;
    
    stack<state> reverse;
    for(auto i = q.front(); i != s; i=origins[i] ) {
      //print_state(i);
      reverse.push(i);
    }
    while(!reverse.empty()) {
      print_state(reverse.top());
      reverse.pop();
    }

  }
  else {
    cout << "Prohra" << endl;
  }
}
