#include <iostream>
#include <vector>
using namespace std;

typedef vector <int> VI;
typedef vector <VI> VVI;

VVI goal;
VVI init;

int limit;

const int di[4] = { 0, 0, 1, -1 };
const int dj[4] = { 1, -1, 0, 0 };

const int T[12][2] = {
	{ 0, 0 },
	{ 1+1, 1+1 },
	{ 1+1, 2+1 },
	{ 1+1, 3+1 },
	{ 2+1, 0+1 },
	{ 2+1, 1+1 },
	{ 2+1, 2+1 },
	{ 2+1, 3+1 },
	{ 2+1, 4+1 },
	{ 3+1, 1+1 },
	{ 3+1, 2+1 },
	{ 3+1, 3+1 }
};

int getMD( VVI P )
{
	int sum = 0;
	int ti, tj;
	for ( int i = 0; i < 7; i++ )
	{
		for ( int j = 0; j < 7; j++ )
		{
			if ( P[j][i] <= 0 )
				continue;

			ti = T[P[j][i]][0];
			tj = T[P[j][i]][1];
			sum += ( max( ti, i ) - min( ti, i ) + max( tj, j ) - min( tj, j ) );
		}
	}
	return sum;
}

bool is_goal( VVI puzzle )
{
	bool ok = true;
	for ( int i = 0; ok && i < 7; i++ ) for ( int j = 0; ok && j < 7; j++ )
	{
		if ( puzzle[j][i] != goal[j][i] )
			ok = false;
	}
	return ok;
}

bool dfs( int depth, VVI now )
{
	if ( is_goal( now ) )
		return true;

	if ( depth + getMD( now ) > limit )
		return false;

	for ( int i = 0; i < 7; i++ )
	{
		for ( int j = 0; j < 7; j++ )
		{
			if ( now[j][i] != 0 )
				continue;

			for ( int k = 0; k < 4; k++ )
			{
				VVI v = now;
				int ni = i + di[k];
				int nj = j + dj[k];

				if ( v[nj][ni] <= 0 )
					continue;

				swap( v[j][i], v[nj][ni] );

				if ( dfs( depth+1, v ) )
					return true;

			}
		}
	}

}

int idfs( VVI src )
{
	for ( limit = 0; limit <= 20; limit++ )
	{
		if ( dfs( 0, src ) )
			return limit;
	}
	return -1;
}

int main( void )
{
	// S[ÌóÔðìé
	goal = VVI( 7, VI( 7, -1 ) );
	goal[3][1] = 0;
	goal[3][5] = 0;
	for ( int i = 0; i < 3; i++ )
	{
		goal[2+i][2] = 1+i;
		goal[2+i][4] = 9+i;
	}
	for ( int i = 0; i < 5; i++ )
	{
		goal[1+i][3] = 4+i;
	}

	while ( 1 )
	{
		// úóÔÌüÍ
		init = VVI( 7, VI( 7, -1 ) );
		cin >> init[3][1];
		if ( init[3][1] == -1 )
			break;
		for ( int i = 0; i < 3; i++ )
			cin >> init[2+i][2];
		for ( int i = 0; i < 5; i++ )
			cin >> init[1+i][3];
		for ( int i = 0; i < 3; i++ )
			cin >> init[2+i][4];
		cin >> init[3][5];

		int cost = idfs( init );

		if ( cost == -1 )
			cout << "NA" << endl;
		else
			cout << cost << endl;

	}

	return 0;
}