#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<vector<int>,int>P;
vector<int>v[13],s(13),t(13);
map<vector<int>,int>m;
void init(){

    v[0].push_back(2);

    v[1].push_back(2);
    v[1].push_back(5);

    v[2].push_back(0);
    v[2].push_back(1);
    v[2].push_back(3);
    v[2].push_back(6);

    v[3].push_back(2);
    v[3].push_back(7);

    v[4].push_back(5);

    v[5].push_back(1);
    v[5].push_back(4);
    v[5].push_back(6);
    v[5].push_back(9);

    v[6].push_back(2);
    v[6].push_back(5);
    v[6].push_back(7);
    v[6].push_back(10);

    v[7].push_back(3);
    v[7].push_back(6);
    v[7].push_back(8);
    v[7].push_back(11);

    v[8].push_back(7);

    v[9].push_back(5);
    v[9].push_back(10);

    v[10].push_back(6);
    v[10].push_back(9);
    v[10].push_back(11);
    v[10].push_back(12);

    v[11].push_back(7);
    v[11].push_back(10);

    v[12].push_back(10);
}
void BFS1(){
    s[0]=0;
    s[12]=0;
    r(i,11)s[i+1]=i+1;
    set<vector<int> >st;
    st.insert(s);
    m[s]=0;
    queue<P>q;
    q.push(P(s,0));
    while(1){
        vector<int>now=q.front().first;
        int cost=q.front().second;
        q.pop();
        if(cost==6)break;
        r(i,13)if(now[i]!=0){
            r(j,v[i].size()){
                swap(now[i],now[v[i][j]]);
                if(!st.count(now)){
                    st.insert(now);
                    m[now]=cost+1;
                    q.push(P(now,cost+1));
                }
                swap(now[i],now[v[i][j]]);
            }
        }
    }
}

void BFS2(){
    set<vector<int> >st;
    st.insert(t);
    queue<P>q;
    q.push(P(t,0));
    while(1){
        vector<int>now=q.front().first;
        int cost=q.front().second;
        if(m.count(now)){
            cout<<m[now]+cost<<endl;
            return ;
        }
        q.pop();
        if(cost==5)break;
        r(i,13)if(now[i]!=0){
            r(j,v[i].size()){
                swap(now[i],now[v[i][j]]);
                if(!st.count(now)){
                    st.insert(now);
                    q.push(P(now,cost+1));
                }
                swap(now[i],now[v[i][j]]);
            }
        }
    }
    cout<<"NA"<<endl;
}


int main(){
    init();
    BFS1();
    while(cin>>t[0],t[0]!=-1){
        r(i,12)cin>>t[i+1];
        BFS2();
    }
}
