#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;

typedef vector<int> VI;

int size[13] = {1, 2, 4, 2, 1, 4, 4, 4, 1, 2, 4, 2, 1};
int move[13][4] = {
  {2},
  {2, 5},
  {0, 1, 6, 3},
  {2, 7},
  {5},
  {1, 4, 6, 9},
  {2, 5, 7, 10},
  {3, 6, 8, 11},
  {7},
  {5, 10},
  {6, 9, 11, 12},
  {7, 10},
  {10}
};

VI v;
map<VI, int> mp;
map<VI, int> mp2;

void make(){
  VI goal;
  for(int i = 0 ; i < 13 ; i++){
    if(i == 0 || i == 12) goal.push_back(0);
    else goal.push_back(i);    
  }
  
  queue<VI> que;
  que.push(goal);
  mp2[goal] = 0;
  
  while(!que.empty()){
    VI q = que.front(); que.pop();    
    if(mp2[q] > 13) continue;
    for(int i = 0 ; i < 13 ; i++){
      if(q[i] != 0) continue;
      for(int j = 0 ; j < size[i] ; j++){
	VI t = q;
	swap(t[i], t[ move[i][j] ]);
	if(mp2.find(t) != mp2.end()) continue;	
	mp2[t] = mp2[q] + 1;	
	que.push(t);
      }
    }
  }
}
    


int bfs(){
  queue<VI> que;
  que.push(v);
  mp[v] = 0;  
  while(!que.empty()){
    VI q = que.front(); que.pop();    
    if(mp2.find(q) != mp2.end()){
      return mp2[q] + mp[q];
    }
    
    if(mp[q] > 8) continue;
    for(int i = 0 ; i < 13 ; i++){
      if(q[i] != 0) continue;      
      for(int j = 0 ; j < size[i] ; j++){
	VI t = q;
	swap(t[i], t[ move[i][j] ]);
	if(mp.find(t) != mp.end()) continue;
	mp[t] = mp[q] + 1;
	que.push(t);
      }
    }
  }
  return -1;
}

void init(){
  v.clear();
  mp.clear();  
}

int main(){
  make();
  int n;
  while(cin >> n){
    if(n == -1) break;
    
    init();
    
    v.push_back(n);
    for(int i = 0 ; i < 12 ; i++){ cin >> n; v.push_back(n); }
    
    int ans = bfs();
    if(ans == -1 || ans > 20) cout << "NA" << endl;
    else cout << ans << endl;
  }
  

  return 0;
}