require 'set'
 
Move = [ [2],
         [2, 5], [0, 1, 3, 6], [2, 7],
         [5], [1, 4, 6, 9], [2, 5, 7, 10], [3, 6, 8, 11], [7],
         [5, 10], [6, 9, 11, 12], [7, 10],
         [10] ]
R = [0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4]
C = [2, 1, 2, 3, 0, 1, 2, 3, 4, 1, 2, 3, 2]
 
def min_heapify(x = 1)
  l = 2*x
  r = 2*x+1
  if l <= $n && $heap[l][0] < $heap[x][0]
    minimum = l
  else
    minimum = x
  end
  if r <= $n && $heap[r][0] < $heap[minimum][0]
    minimum = r
  end
  if minimum != x
    $heap[x], $heap[minimum] = $heap[minimum], $heap[x]
    min_heapify(minimum)
  end
end

def extract
  key = $heap[1]
  $heap[1] = $heap[$n]
  $n -= 1
  min_heapify
  key
end

def insert(key)
  $n += 1
  $heap[$n] = key
  i = $n
  while i > 1 && $heap[i/2][0] > $heap[i][0]
    $heap[i], $heap[i/2] = $heap[i/2], $heap[i]
    i /= 2
  end
end

def judge(brd, depth)
  ret = depth
  13.times do |i|
    if brd[i] > 0
      [R, C].each do |a|
        ret += (a[i] - a[brd[i]]).abs
      end
    end
  end
  ret
end
 
def solve(brd)
  $heap = []
  $n = 0
  insert [judge(brd, 0), brd, 0]
  set = Set.new([])
  set.add(brd)
  
  until $heap.empty?
    arr = extract
    x, b, d = arr
    return d if (1..11).all?{ |v| b[v] == v }
    next if x > 20
    13.times do |i|
      if b[i] == 0
        Move[i].each do |m|
          b[i], b[m] = b[m], b[i]
          nb = b.dup
          nx = judge(nb, d + 1)
          unless set.include?(nb)
            set.add(nb)
            insert [nx, nb, d + 1]
          end
          b[i], b[m] = b[m], b[i]
        end
      end
    end
  end
  false
end
 
while n = gets.to_i
  break if n == -1
  ans = solve([n, 4.times.map{ gets.split.map(&:to_i) } ].flatten)
  puts ans && ans <= 20 ? ans : 'NA'
end