Above ground, the families of the missing gold miners accepted the inevitable and mourned their dead.

Joseph Burule Robi’s wife and four children held a funeral for him. A brother of Msafiri Gerard, the father of seven kids, inherited his sibling’s shoes. In this desperate corner of northern Tanzania, resources are scarce. A good pair of shoes can’t be left unused, not when there are so many feet unshod.

Forty days had passed since six men had descended into an unstable mining shaft in search of 11 missing colleagues. Forty days since the shaft collapsed, burying the exit and presumably the miners along with it. It was unimaginable that they could have survived so long. Not without food, and water. Not without anyone noticing.

Unimaginable, yet possible. On the 41st day, after an interminable incarceration during which they subsisted on roots, frogs, bugs and water that dripped from the mine’s dirty ceiling, the miners were finally able to catch the attention of another group working in a shaft nearby.

Five of the men who were trapped were pulled to freedom Sunday, Tanzania’s Ministry of Energy and Mines announced on Tuesday. A sixth died of hunger during the six-week ordeal.

Speaking to the Tanzanian newspaper the Citizen, survivor Chacha Wambura said that 20 miners were in the mine when it collapsed on Oct. 5. Fourteen escaped, but six remained inside, unhurt but unable to get out.

The men futilely sought a way out, scouring the mining shaft’s tunnels and passages until their headlights and cell phones ran out of battery. Then they sought refuge in a cave used to store mining tools.

Some 300 feet above them, local rescue teams tried to use heavy machinery to get to the missing men, but that effort also failed. On October 11, six days after the collapse, then Deputy Minister for Energy and Minerals Charles Kitwanga announced that the trapped men were presumed dead.

“I have spoken to experts about this calamity, and they have informed me that it is virtually impossible to rescue the victims,” he said, according to the Citizen.

Families began to arrange funerals, according to the BBC. One man’s wife moved back to her family in a different town.

At seven days, the stranded miners had also given up.

“We tried, without success, to tunnel our way out,” Wambura told the Citizen. “Weak and tired, we waited for the inevitable.”

Just when they’d given up, they stumbled across hope — in the form of a weak stream of light and a trickle of dirty water.

“We discovered a place where the sun’s rays shone through a crack,” Wambura said. “We also found water seeping through. This gave us a new lease of life.”

Wambura and his colleagues survived by eating cockroaches, frogs and the bark of poles used to hold up the tunnel ceiling. Increasingly weak from hunger, they decided to stay together rather than separate in search of an exit. Their best hope was for someone to hear them.

On Sunday, someone finally did — a fellow miner who, like everyone else, had resigned themselves to the fact that their colleagues were long gone.

“He asked us who we were and we mentioned our names and told him what had happened to us,” Wambura said. “He told us to stay put, and after some time we heard people digging and they eventually broke through to where we were trapped.”

When Tobias Uruothi, the brother of one of the buried men, got a call saying his sibling was still alive, he assumed it was a scam and hung up, he told the BBC.

The five survivors are now in the hospital, where they are still “very weak,” Ministry of Energy and Mines spokeswoman Badra Masoud told Agence France-Presse.

In 2010 33 miners in Chile endured a record 69-day entrapment, but in that case, officials were aware that the miners were alive and were able to send down food and notes of encouragement. After the first week, the miners in Tanzania had no one looking for them and no one to depend on but themselves.

According to the BBC, the trapped men in Tanzania are “artisanal” gold miners — a technical term (and some might say euphemism) for informal subsistence miners who work in small gold mines without health and safety regulations. Miners, including children, toil underground in hopes of finding some gold they can sell to dealers.

Collapse of artisanal mines are frequent, AFP reported, since miners have only the most basic tools and little training in the construction of safe shafts.