For 17 hours, Martin Mendez was trapped under the wreckage of a Mexico City building, praying to see his 3-year-old daughter again.

“I had to get out alive for her,” he said.

Mendez and three others were rescued Wednesday morning from the ruins of a six-story building in the city’s Roma neighborhood. The structure collapsed the day before when a powerful earthquake shook central Mexico, turning buildings into dust and killing more than 300 people.

The locksmith had been replacing broken locks at an accounting office when the rumbling started. He ran to an emergency stairwell, but the floors came down like dominoes, he said.

Within seconds, he became confined to a small space with a broken leg.

Some furniture seemed to have held back debris, preventing it from crashing down on him and the others in the office.

“We were there alive. That was the most important thing,” Mendez told CNN.

The four calmed each other as the hours passed. They talked about their families and prayed to the Virgin of Guadalupe.

Rescuers would yell, “Is anyone in there alive?” but they couldn’t hear the group’s frantic replies.

“They couldn’t hear us, but we heard them clearly, like if they were just across a window,” Mendez said.

Dust would fall on the four of them every time when the rescuers hit the debris with their mallets, causing the group to fear everything would collapse again.

‘We are trapped’

Diana Pacheco came back to get her cell phone before the earthquake brought down the building.

And her phone may have helped rescuers pinpoint the group’s location.

The 30-year-old mother said her phone didn’t have service, but she still sent a series of texts to her husband.

“We are trapped,” “we are in the fourth floor,” “near the emergency exit,” “we are four people,” the messages said.

Her husband somehow got the messages hours later.

“The messages went through, how? I have no idea, but he got them,” Pacheco said.

‘I hope they don’t stop searching’

Once they were found, the rescue from the wreckage also proved to be nerve-racking. As crews pulled the four out with ropes, they would get stuck in the debris. At points, it was hard to breathe, they recalled.

With a broken leg, Mendez said he felt an unbearable pain all along but he “had to hold on.”

“God pulled me out of there,” he said. “It’s thanks to God that I’m here.”

Pacheco said some of her colleagues at the accounting office could still be trapped in the building.