Some fairy tales go back thousands of years, study says