The three U.S. citizens were detained on July 31 for entering Iran illegally , after they apparently strayed across the border while on a hike in northern Iraq .