NEW YORK - The hostages were taken out of their cell one by one.
In a private room, their captors asked each of them three intimate questions, a standard technique used to obtain proof that a prisoner is still alive in a kidnapping negotiation.
Mr James Foley returned to the cell shared with nearly two dozen other Western hostages and collapsed in tears of joy.
The questions were so personal ("Who cried at your brother's wedding?", "Who was the captain of your high school soccer team?") that he knew they were in touch with his family.
It was last December, more than a year since Mr Foley vanished on a road in northern Syria. His government, he believed, would negotiate his release.
What appeared to be a turning point was in fact the start of a downward spiral for Mr Foley, a 40-year-old journalist, ending in August when he was forced to his knees somewhere in the bald hills of Syria and beheaded on camera.
The story of what happened in the Islamic State in Iraq and Syria's (ISIS) underground network of prisons in Syria is one of excruciating suffering.
Mr Foley and his fellow hostages were routinely beaten and subjected to waterboarding.
Some, including Mr Foley, sought comfort in the faith of their captors, embracing Islam and taking Muslim names.
Their captivity coincided with the rise of the group that came to be known as ISIS out of the chaos of the Syrian civil war.
It did not exist on the day that Mr Foley was abducted, but it slowly grew to become the most powerful and feared rebel movement in the region.
By the second year of Mr Foley's imprisonment, the group had amassed close to two dozen hostages and devised a strategy to trade them for cash.
Their struggle for survival, which is being told now for the first time, was pieced together through interviews with five former hostages, locals who witnessed their treatment, relatives and colleagues of the captives, and advisers who made trips to the region to try to win their release. Details were confirmed by a former member of ISIS who was stationed in the prison where Mr Foley was held.
Officials in the United States say they did everything in their power to save Mr Foley and the others, including carrying out a failed rescue operation. They argue that the US policy of not paying ransoms saves Americans' lives in the long run by making them less attractive targets.
In Binesh, Syria, two years ago, Mr Foley and his travelling companion, British photojournalist John Cantlie, flagged a taxi for the 40km drive to Turkey. They never reached the border.
The gunmen who abducted them did not call themselves the ISIS because the group did not yet exist on Nov 22, 2012, the day the two men were grabbed.
But the danger of Islamic extremism was already palpable in Syria's rebel-held territories. Among the red flags was the growing number of foreign fighters flooding into Syria, dreaming of establishing a "caliphate".
Over the next 14 months, at least 23 foreigners, most of them freelance journalists and aid workers, were taken, including US freelance journalist Steven Sotloff, seized on Aug 4 last year.
The extremists found images of military personnel on Mr Foley's laptop, taken during assignments in Afghanistan and Iraq.
"In the archive of photographs he had personally taken, there were images glorifying the American crusaders," they wrote in an article.
The punishment for any perceived offence was torture.
"You could see the scars on his ankles," Mr Jejoen Bontinck, a 19-year-old Belgian who was released late last year, said of Mr Foley. "He told me how they had chained his feet to a bar and then hung the bar so that he was upside down from the ceiling."
Mr Foley converted to Islam soon after his capture, Mr Bontinck said. "Most people would say, 'Let's convert so that we can get better treatment'," Mr Bontinck said. "But in his case, I think it was sincere."
Former hostages said that a majority of the Western prisoners had converted during their captivity. But those recently released said that Mr Foley had been captivated by Islam. When the guards brought an English version of the Quran, Mr Foley spent hours engrossed in the text.
After months of holding them without making any demands, the militants suddenly devised a plan to ransom them. The prisoners realised that their kidnappers had identified which nations were most likely to pay, said a former hostage.
The European prisoners went from answering additional personal questions to filming videos to be sent to their families or governments. The videos became more and more charged, eventually including death threats and execution deadlines in an effort to force their nations to pay.
The jailers also began waterboarding a select few hostages, former hostages and witnesses said. The three American men and the three British hostages were singled out for the worst abuse.
"It's part of the DNA of this group to hate America," one said. "But they also realised that the United States and Britain were the least likely to pay."
Within this subset, the person who suffered the cruellest treatment, the former hostages said, was Mr Foley.
In addition to receiving prolonged beatings, he underwent mock executions and was repeatedly waterboarded.
When one of the prisoners was hauled out, the others were relieved if he came back bloodied. "It was when there was no blood," a former cellmate said, "that we knew he had suffered something even worse."
Mr Foley shared his meagre rations, offered another prisoner his only blanket, and kept the others entertained, proposing games and activities like Risk, a board game that involves moving imaginary armies across a map: a favourite pastime in the Foley family. The hostages also made a chess set out of discarded paper.
By April, nearly half of the captives had been freed. There had been no progress, however, on the ransom demands made for theUS and British hostages.
In a recent article in an official ISIS magazine, the militants described the US-led air strikes that began in August as the nail in those hostages' coffins.
In August, when the militants came for Mr Foley, they made him slip on a pair of plastic sandals. They drove him to a bare hill outside Raqqa and slit his throat.
Two weeks later, a similar video surfaced on YouTube showing Mr Sotloff's death.
Last month, the militants uploaded the execution of British hostage David Cawthorne Haines. This month, they killed Mr Alan Henning, another Briton.
Only three from the original group of 23 remain: two Americans, Mr Peter Kassig and a woman who has not been identified, as well as Briton John Cantlie. The militants say Mr Kassig is next.
Across Europe, those who had survived gasped at the footage: The flip-flops splayed next to Mr Foley's body were the same pair the prisoners had shared.
Those who survived had walked in the same shoes as those who did not.
NEW YORK TIMES