require 'set'

# ??????: ???????????¢?´¢

# ??£
NB = [
  [2],
  [5, 2],
  [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],
  [10, 7],
  [10]
]

Y = [0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4]
X = [2, 1, 2, 3, 0, 1, 2, 3, 4, 1, 2, 3, 2]

def solve(field)
  queue = []
  queue << [field, 0]
  used = Set.new
  dist = -1
  prev_dist = -1
  until queue.empty?
    f, dist = queue.shift
    return dist if f == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0]
    res = f.each_with_index.inject(0) {|accum, (v, i)|
      accum + (i != 0 ? (X[v] - X[i % 12]).abs + (Y[v] - Y[i % 12]).abs : 0)
    }
    next if ((res / 2) + dist) > 20
    f.each.with_index do |v, i|
      next unless v == 0
      NB[i].each do |t|
        f[i], f[t] = f[t], f[i]
        unless used.include? f
          nf = f.clone
          used.add(nf)
          queue << [nf, dist + 1]
        end
        f[i], f[t] = f[t], f[i]
      end
    end
    # p "N: #{prev_dist = dist}" if prev_dist < dist
  end
  return nil if queue.empty?
  dist
end

loop do
  v = gets.to_i
  break if v == -1
  field = (1..4).map { gets.split(" ").map(&:to_i) }
  res = solve(([[v]] + field).flatten)
  puts res.nil? ? "NA" : res
end