K9 Mark 1 was left on Gallifrey by Leela,
The Doctor used Professor Marius' schematics to build K9-2 which was damaged in E-Space where he remained to prtect Romana. She later repaired this adn returned to her own time adn space with K9-2.
K9-3 was made by Sarah Smith for The Doctor but later broke down after Sarah was returned to ehr own time. She was unable to repair him as the circuits hadn;t yet been invented. The remains were passed down through her family before ending up in the future in the hands of professor Marius who used them as the basis for a robotic companion named K9-Mark1
Which makes K9 a self defeating paradox rendering the space time continuum null and void!!!
Incidentalyl - you can;t put a tardis inside another one as the TARDIS interior is not a physical craft but a wormhole destination and putting one wormhole inside another leads to a break down of the event horizon!

