Let me continue that story.
After Draupadi died, the Pandavas moved further. On the way, Sahdev died.
Bhim asked, "He who with great humility used to serve us all, alas, why is that son of Madri fallen down on the Earth?
Yudhisthir replied, "He never thought anybody his equal in wisdom. It is for that fault that this prince has fallen down."
Others went on. Knowing that Draupadi and Sahdev were not any more, Nakul fell down (died).
Bhim said, "This brother of ours was righteousness. He always obeyed us. He was unrivalled for beauty. This Nakul has fallen down"
Yudhisthir replied, "He was of righteous soul and highly intelligent. He, however, thought that there was nobody that equalled him in beauty of person. Indeed, he regarded himself as superior to all in that respect. It is for this that Nakul has fallen down."
Arjun fell down in grief. When Arjun was on the point of death, then Bhim said to Yudhisthir, "I do not recollect any lie uttered by this high-souled one. Not even in jest did he say anything false. What then is the reason for whose evil consequence this one has fallen down on the Earth?
Yudhisthir replied, "Proud of his heroism, Arjun had said that he would consume all our foes in a single day. However, he did not accomplish that. Hence has he fallen down. He disregarded all other archers. One desirous of prosperity should never indulge in such sentiments."
After some time, Bhim fell down. Before his death, Bhim said, "You liked me the most. I have fallen down. For what reason have I dropped down? Tell me if you know it."
Yudhisthir said, "You always boasted of your strength. You were a voracious eater. While eating, you never thought of the need of others. It is for that reason, O Bhim, that you have fallen down."
Yudhisthir proceeded further. He had only a dog as a companion. Lord Indra came there on an excellent car. He asked Yudhisthir to get in the car.
Yudhisthir said, "My brothers and Draupadi also must go to heaven. Without them, I do not want to go."
Indra said, "After casting off their bodies, they have reached their before you. You will see them in heaven. You will go to heaven with your body."
Yudhisthir said, "This dog is devotedly following me. He also must go with me."
Indra said, "There is no room in heaven for people with dogs. All merits of such people are taken away. Leave this dog."
Yudhisthir said, "Abandoning one who is devoted is sinful. I never give up a person that is terrified, nor one that is devoted to me, nor one that seeks my protection, saying that he is destitute, nor one that is afflicted, nor one that has come to me, nor one that is weak in protecting oneself, nor one that is solicitous of life. I shall not leave this dog just for my happiness."
Indra said, "You have renounced your brothers and Draupadi. Then, why this attachment with this dog?"
Yudhisthir said, "There is neither friendship nor enmity with those who are dead. When my brothers and Draupadi died, then there was no way I could revive them. That is why, I left them. I did not leave them so long they were alive."
Then the dog became Lord Yam (the lord of righteousness). He had taken the form of a dog to test Yudhisthir.