#include <iostream>
#include <set>
#include <queue>
#include <map>

using namespace std;

class State{
public:
   string s;
   int cost;
};

int input;
set<string> visited;
map<string, int> memo;
int distx[] = {};
int disty[] = {};

void swap(string &str, int a, int b){
   char tmp = str[a];
   str[a] = str[b];
   str[b] = tmp;
}

void pre_bfs(){
   State u, v;
   u.s = "ABCDEFGHIJKLA";
   u.cost = 0;
   memo[u.s] = u.cost;
   queue<State>Q;
   Q.push(u);
   while(!Q.empty()){
      u = Q.front(); Q.pop();
      if(u.cost >= 10) continue;
      for(int i=0;i<13;i++){
         if(u.s[i] == 'A'){
            v.cost = u.cost + 1;
            switch(i){
               case 0:
                  v.s = u.s;
                  swap(v.s, 0, 2);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  break;
               case 1:
                  v.s = u.s;
                  swap(v.s, i, 2);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, 5);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  break;
               case 3:
                  v.s = u.s;
                  swap(v.s, i, 2);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, 7);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  break;
               case 4:
                  v.s = u.s;
                  swap(v.s, i, 5);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  break;
               case 8:
                  v.s = u.s;
                  swap(v.s, i, 7);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  break;
               case 9:
                  v.s = u.s;
                  swap(v.s, i, 5);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, 10);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }

                  break;
               case 11:
                  v.s = u.s;
                  swap(v.s, i, 7);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, 10);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  break;
               case 12:
                  v.s = u.s;
                  swap(v.s, i, 10);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  break;
               default:
                  int ue = 4;
                  int sita = 4;
                  if(i == 2) ue = 2;
                  if(i == 10) sita = 2;
                  v.s = u.s;
                  swap(v.s, i, i-ue);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, i+sita);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, i+1);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, i-1);
                  if(memo.find(v.s) == memo.end()){
                     memo[v.s] = v.cost;
                     Q.push(v);
                  }
                  break;
            }
         }
      }
   }
}

int bfs(string str){
   State u, v;
   u.s = str;
   u.cost = 0;
   queue<State> Q;
   Q.push(u);
   while(!Q.empty()){
      u = Q.front(); Q.pop();
      if(memo.find(u.s) != memo.end()){
         return u.cost + memo[u.s];
      }
      if(u.cost >= 10) continue;
      for(int i=0;i<13;i++){
         if(u.s[i] == 'A'){
            v.cost = u.cost + 1;
            switch(i){
               case 0:
                  v.s = u.s;
                  swap(v.s, 0, 2);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  break;
               case 1:
                  v.s = u.s;
                  swap(v.s, i, 2);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, 5);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  break;
               case 3:
                  v.s = u.s;
                  swap(v.s, i, 2);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, 7);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  break;
               case 4:
                  v.s = u.s;
                  swap(v.s, i, 5);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  break;
               case 8:
                  v.s = u.s;
                  swap(v.s, i, 7);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  break;
               case 9:
                  v.s = u.s;
                  swap(v.s, i, 5);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, 10);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }

                  break;
               case 11:
                  v.s = u.s;
                  swap(v.s, i, 7);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, 10);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  break;
               case 12:
                  v.s = u.s;
                  swap(v.s, i, 10);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  break;
               default:
                  int ue = 4;
                  int sita = 4;
                  if(i == 2) ue = 2;
                  if(i == 10) sita = 2;
                  v.s = u.s;
                  swap(v.s, i, i-ue);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, i+sita);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, i+1);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  v.s = u.s;
                  swap(v.s, i, i-1);
                  if(visited.find(v.s) == visited.end()){
                     visited.insert(v.s);
                     Q.push(v);
                  }
                  break;
            }
         }
      }
   }
   return -1;
}

main(){
   pre_bfs();
   while(cin >> input){
      if(input == -1) break;
      string str = "";
      str += ((char)input + 'A');
      for(int i=1;i<13;i++){
         cin >> input;
         str += ((char)input + 'A');
      }
      int ans = bfs(str);
      if(ans == -1) cout << "NA" << endl;
      else{
         cout << ans << endl;
      }
   }
   return 0;

}