One version is recorded in the Babylonian Talmud, Sukkah 53a.5-6 (NB: The Talmud was compiled in the 5th century while Samarrah was founded in the 9th century; the Talmudic version of the story involves King Solomon sending two men to a place called Luz to avoid death.)