finish queen's problem algorithm