#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;

int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int gx[]={0,1,2,3,0,1,2,3,4,1,2,3},gy[]={0,1,1,1,2,2,2,2,2,3,3,3};

struct S{
	int p[5][5];
	int zx[2],zy[2];
	int md;
	S(){}
	S(int a[5][5])
	{
		md=0;
		zx[0]=-1;
		rep(i,5)rep(j,5)
		{
			p[i][j]=a[i][j];
			if(a[i][j]==0)
			{
				if(zx[0]==-1)zy[0]=i,zx[0]=j;
				else zy[1]=i,zx[1]=j;
			}
			if(abs(i-2)+abs(j-2)<=2&&p[i][j])
			md+=abs(gy[p[i][j]]-i)+abs(gx[p[i][j]]-j);
		}
	}
	bool swp(int z,int d)
	{
		int y=zy[z],x=zx[z],nx=x+dx[d],ny=y+dy[d];
		if(abs(nx-2)+abs(ny-2)>2||p[y][x]==p[ny][nx])return 0;
		
		md+=abs(gy[p[ny][nx]]-y)+abs(gx[p[ny][nx]]-x);
		md-=abs(gy[p[ny][nx]]-ny)+abs(gx[p[ny][nx]]-nx);
		swap(p[y][x],p[ny][nx]);
		zy[z]+=dy[d]; zx[z]+=dx[d];
		return 1;
	}
};
S pz; int lim;
bool dfs(int c)
{
	if(pz.md==0)return 1;
	rep(i,2)rep(d,4)
	{
		if(!pz.swp(i,d))continue;
		if(pz.md+c+1<=lim&&dfs(c+1))return 1;
		pz.swp(i,d+2&3);
	}
	return 0;
}
int main()
{
	int t;
	while(scanf("%d",&t),~t)
	{
		int p[5][5];
		rep(i,5)rep(j,5)p[i][j]=-1;
		p[0][2]=t;
		rep(i,3)scanf("%d",p[1]+i+1);
		rep(i,5)scanf("%d",p[2]+i);
		rep(i,3)scanf("%d",p[3]+i+1);
		scanf("%d",p[4]+2);
		
		for(lim=0;lim<=20;lim++)
		{
			pz=S(p);
			if(!dfs(0))continue;
			printf("%d\n",lim); goto END;
		}
		puts("NA"); END:;
	}
	return 0;
}