#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

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

int main() {
	queue<string> que;
	map<string, int> d;
	
	que.push("abcdefghijkla");
	d["abcdefghijkla"] = 0;
	
	while (!que.empty()) {
		string now = que.front(); que.pop();
		int cost = d[now];
		
		if (cost > 10) break;
		
		REP(i, 13) if (now[i] == 'a') {
			REP(j, 4) {
				if (dd[i][j] == -1) break;
				
				swap(now[i], now[dd[i][j]]);
				if (d.find(now) == d.end()) {
					d[now] = cost + 1;
					que.push(now);
				}
				swap(now[i], now[dd[i][j]]);
			}
		}
	}
	while (!que.empty()) que.pop();
	
	int p[13];
	while (cin >> p[0], ~p[0]) {
		FOR(i, 1, 13) cin >> p[i];
		string st = "";
		REP(i, 13) st += p[i] + 'a';
		
		map<string, int> d2;
		que.push(st);
		d2[st] = 0;
		
		int ans = INF;
		
		while (!que.empty()) {
			string now = que.front(); que.pop();
			int cost = d2[now];
			
			if (cost > 10) break;
			if (d.find(now) != d.end()) chmin(ans, d[now] + d2[now]);
			
			REP(i, 13) if (now[i] == 'a') {
				REP(j, 4) {
					if (dd[i][j] == -1) break;
					
					swap(now[i], now[dd[i][j]]);
					if (d2.find(now) == d2.end()) {
						d2[now] = cost + 1;
						que.push(now);
					}
					swap(now[i], now[dd[i][j]]);
				}
			}
		}
		while (!que.empty()) que.pop();
		
		if (ans <= 20) cout << ans << endl;
		else puts("NA");
	}
	return 0;
}