Solving 8-puzzle and 8-queens