But chords kept popping into her head. The summer between junior and senior years, while working at Harvard Medical School’s lab, she ran experiments, set a timer, then raced over to the only dorm she knew that had a piano. There, until the experiment’s wait time was done, she wrote music. Back and forth each day she went, chemistry and chords pulling her this way and that, until she graduated and said to her parents, “give me a couple of years in New York and we’ll see how it goes.”

The two began working together, until Ms. Sarnak felt safe enough with Ms. Kaczmarek to show her a musical she had written that was close to her heart. The musical, “Afterwords,” found a working home at their respective apartments, both in Harlem. While working on it, they fell in love.

“We would go into separate rooms and she would work on a song and I would work on a scene and then we would have snacks and a drink and those sessions would go until 2 in the morning,” Ms. Kaczmarek said. “And when I didn’t want her to leave I said, ‘O.K., something’s going on here.”

They discovered they liked much of the same music, from Sara Bareilles and Brandi Carlile to “Ragtime” and “Rent.” They walked the city for hours, assuring each another they would descend at the next subway stop, only to skip it to continue the conversation.