I don't know man. Use your imagination. Madara obviously did it when Nagato was a kid without him knowing it, just as he put the curse seal in Obito without him knowing it and just as Obito brainwashed Yagura without him knowing it. He probably did it when Nagato was too young to remember.