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]

while n = gets.to_i
  break if n == -1
  brd = [n, 4.times.map{ gets.split.map(&:to_i) } ].flatten
  q = [[brd, 0]]
  ans = -1
  set = SortedSet.new([])
  set.add(brd)
  until q.empty?
    b, d = q.shift
    if (1..11).all?{ |v| b[v] == v }
      ans = d
      break
    end
    x = d
    13.times do |i|
      if b[i] > 0
        [R, C].each do |a|
          x += (a[i] - a[b[i]]).abs
        end
      end
    end
    unless x > 20
      13.times do |i|
        if b[i] == 0
          Move[i].each do |m|
            b[i], b[m] = b[m], b[i]
            unless set.include?(b)
              set.add(nb = b.dup)
              q << [nb, d + 1]
            end
            b[i], b[m] = b[m], b[i]
          end
        end
      end
    end
  end
  puts ans == -1 ? 'NA' : ans
end