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 judge(brd)
  ret = 0
  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)
  q = [[judge(brd), brd, 0]]
  set = Set.new([])
  set.add(brd)
  until q.empty?
    arr = q.min{ |a, b| a <=> b }
    q.delete(arr)
    x, b, d = arr
    next if x + d > 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)
          return d + 1 if nx == 0
          unless set.include?(nb)
            set.add(nb)
            q << [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 : 'NA'
end