SEVNICA, Slovenia — On days when Melanija Knavs could not play outside or grew tired of knitting her navy blue sweaters, she and her friends would exchange notes along the lines of yarn they strung between their apartment block balconies.

In clear handwriting, Melanija mused about the boys of her dreams.

She could not have seen what was coming. Melanija Knavs is now Melania Trump, and she is one election away from being the first foreign-born first lady since Louisa Adams. She addressed millions of Americans on Monday night in a televised speech at the Republican National Convention in Cleveland.

But interviews with her former classmates, friends of her family and others who knew them during her youth in Slovenia suggest that her transformation owes less to chance than to the Knavs family’s determination to seize openings and avoid getting stuck.