Cash-strapped councils across Wales are spending tens of millions of pounds on agency supply staff in schools.