Solve puzzles using BFS tempelate