#include <bits/stdc++.h>

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;

vector< vector<int> > to = {
  {2},
  {2, 5},
  {0, 1, 3, 6},
  {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}
};

vector<int> ans = {0,1,2,3,4,5,6,7,8,9,10,11,0};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  map<vector<int>, int> D;  
  queue< vector<int> > que;
  que.push(ans);
  D[ans] = 0;
  while(!que.empty()) {
    auto v = que.front(); que.pop();
    if(D[v] >= 10) break;
    rep(i, v.size()) {
      if(v[i]) continue;
      rep(j, to[i].size()) {
	int c = D[v];
	swap(v[i], v[to[i][j]]);
	if(!D.count(v)) {
	  que.push(v);
	  D[v] = c + 1;
	}
	swap(v[i], v[to[i][j]]);
      }
    }
  }
  
  int p;
  while(cin >> p, ~p) {
    vector<int> pzl; pzl.push_back(p);
    rep(i, 12) cin >> p, pzl.push_back(p);
    if(D.count(pzl)) {
      cout << D[pzl] << endl;
      continue;
    }
    map<vector<int>, int> d;
    queue< vector<int> > que;
    que.push(pzl);
    d[pzl] = 0;
    bool flag = false;
    while(!que.empty() && !flag) {
      auto v = que.front(); que.pop();
      if(d[v] >= 10) break;      
      rep(i, v.size()) {
	if(v[i]) continue;
	rep(j, to[i].size()) {
	  int c = d[v];
	  swap(v[i], v[to[i][j]]);
	  if(D.count(v)) {
	    cout << D[v] + c + 1 << endl;
	    flag = true;
	    break;
	  } else if(!d.count(v)) {
	    que.push(v);
	    d[v] = c + 1;
	  }
	  swap(v[i], v[to[i][j]]);
	}
	if(flag) break;
      }
    }
    if(!flag) cout << "NA" << endl;
  }
  return 0;
}