40,000 flee as quakes hit Japan