In Talmud Bava Kama, Chazal teach:
כל המבקש רחמים על חבירו והוא צריך לאותו דבר הוא נענה תחילה –
“Anyone wanting mercy for his friend, and he needs the same thing – he is answered first”.
The Talmud offers one source for this teaching. Avraham Avinu davened for King of Plishtim Avimelech, his wife and his maidservants etc that they should be healed and able to bear children. As a result of Avraham praying for others to restore their ability to have children, Sarah and Avraham were blessed in conceiving and bearing a son Yitzchok; even before the others were cured.