#include<iostream>
#include<string>
#include<set>
#include<utility>
#include<queue>
#include<algorithm>
using namespace std;

const int N=7;

int f(string first)
{
	const string last(
		"......."
		"...0..."
		"..123.."
		".45678."
		"..9AB.."
		"...0..."
		".......");
	set<string>s;
	queue<string>q;
	string p,next;
	int ans = 0,i,j,k,zeroPos[2],a[]={-1,1,N,-N};

	q.push(first);
	q.push("");
	while(!q.empty())
	{
		p = q.front(); q.pop();
		if(p.empty())
		{
			++ans;
			if(ans > 20)
				return -1;		//èª©©è·¬Ä¢Ü·
			q.push("");
		}
		else if(p==last) break;
		else
		{
			if(!s.insert(p).second)
				continue;	//à¤»Ì`ÉÈÁ½±Æª éÈç½àµÈ¢
			//0ÌêðT·
			zeroPos[0]=p.find('0');
			zeroPos[1]=p.find('0',zeroPos[0]+1);
			//0Ìê©çAãº¶Eª.Å³¯êÎð·µÄo^
			for(i=0;i<2;++i)
			{
				for(j=0;j<4;++j)
				{
					if(p[ zeroPos[i]+a[j] ]!='.')
					{
						next=p;
						swap(next[zeroPos[i]], next[ zeroPos[i]+a[j] ]);
						q.push(next);
					}
				}
			}
		}
	}
	return ans;
}

int main()
{
	const char a[]="0123456789AB";
	//(5+2)^2ÌvfðAÔºà©ËÄmÛ
	string s(49,'.');
	int i,x;
	while(cin>>x,x>=0)
	{
		s[10]=a[x];
		for(i=0;i<3;++i) cin>>x,s[16+i]=a[x];
		for(i=0;i<5;++i) cin>>x,s[22+i]=a[x];
		for(i=0;i<3;++i) cin>>x,s[30+i]=a[x];
		cin>>x,s[38]=a[x];

		x=f(s);
		if(x>=0) cout<<x<<endl;
		else cout<<"NA\n";
	}
	return 0;
}