Next = [
  [nil, nil, 2, nil],
  [nil, 2, 5, nil],
  [0, 3, 6, 1],
  [nil, nil, 7, 2],
  [nil, 5, nil, nil],
  [1, 6, 9, 4],
  [2, 7, 10, 5],
  [3, 8, 11, 6],
  [nil, nil, nil, 7],
  [5, 10, nil, nil],
  [6, 11, 12, 9],
  [7, nil, nil, 10],
  [10, nil, nil, nil],
]

def copy(target)
  Marshal.load(Marshal.dump(target))
end

def bfs(original_puzzle, memo)
  q = [[original_puzzle, 0]]
  until q.empty?
    puzzle, depth = q.shift
    next if depth > 10
    next if memo[puzzle]
    memo[puzzle] = depth

    i1 = puzzle.index(0)
    i2 = puzzle[i1 + 1, puzzle.size].index(0) + i1 + 1
    [i1, i2].each do |i|
      Next[i].each do |j|
        next unless j
        _puzzle = copy(puzzle)
        _puzzle[i], _puzzle[j] = _puzzle[j], _puzzle[i]
        q << [_puzzle, depth + 1]
      end
    end
  end
end

@memo1 = Hash.new
bfs([*0..11, 0], @memo1)

until (puzzle = [gets.to_i]) == [-1]
  puzzle += 4.times.map{gets.split.map(&:to_i)}.flatten

  @memo2 = Hash.new
  bfs(puzzle, @memo2)

  answer = 21
  @memo1.keys.each do |k|
    next unless @memo2[k]
    answer = [answer, @memo1[k] + @memo2[k]].min
  end
  puts (answer > 20 ? "NA" : answer)
end