South Africa's Grade 5 pupils rank last out of 59 countries in maths and science, with scores declining in both subjects.