Image copyright AP Image caption Thousands of people turned up at Torkham in north-west Pakistan

Thousands of stranded Afghans and Pakistanis have been queuing to get home after Pakistan temporarily opened two main border crossings.

Officials at the Torkham point said 2,900 people crossed into Afghanistan and 550 entered Pakistan on Tuesday.

Figures from the other main crossing at Chaman were not immediately available.

Pakistan shut the crossings nearly three weeks ago after a wave of deadly attacks by militants it said were operating from Afghan soil.

The two countries have long accused each other of doing too little to tackle militants.

Afghanistan says some 25,000 Afghans are stranded in Pakistan because of the border closure.

The two crossings will be open for a second day but many believe it is unlikely all the people still stranded will be able to cross the border on Wednesday.

Image copyright EPA Image caption Many, like these people, have been trying to get home to Afghanistan for weeks

"We are trapped here because we have problems in our homeland," one man, Shah Wali, who is from the Afghan city of Kunduz, told BBC Urdu's Azizullah Khan.

Zabihullah said he had travelled to Pakistan for medical treatment.

Image caption Zabihullah has run out of money and just wants to get home

"Then the [border] gates closed on me. I was carrying some money but ended up spending all of it. Since then I have been living on other people's money and food. It's been so demeaning. I'm like a pauper now."

He had been queuing for four hours.

"The soldiers keep pushing us around from one queue to another. It's so tiring."

The BBC's M Ilyas Khan in Islamabad says the decision to temporarily open the border came amid rising concerns that continued closure could develop into a humanitarian crisis.