AFTER Aida Hadzialic’s parents fled war-torn Bosnia for Sweden in the early 1990s, they put their five-year-old daughter in a school full of native Swedes and made sure she studied hard to get ahead. It worked. Today Ms Hadzialic, 27, is Sweden’s minister for upper secondary education. Like her counterparts across Europe, she faces a new challenge: ensuring that a fresh wave of refugee children can integrate as successfully as she did.

Even before this year’s surge, western Europe had lots of immigrant students. According to the Organisation for Economic Cooperation and Development (OECD), the proportion of 15-year-old schoolchildren in Spain who are foreign-born rose from 3% to 8% from 2003 to 2012 (though in Germany it fell by about the same amount). The new wave of migrants from Syria, Afghanistan, Iraq and elsewhere has redoubled the strains on school systems.

In the countries accepting the most refugees—Sweden and Germany—lack of space is not a problem. Before the migrant surge, both countries faced declining numbers of pupils because of low birth rates. In Sweden the number of children in ninth grade fell from 120,000 in 2005 to 96,000 in 2015. “We have places for a hundred more pupils,” says Henrik Ljungqvist, the headmaster of Ronna School in Sodertalje, a city near Stockholm. (His school admits two to four new refugee pupils a week.) In Germany, without the new migrants, the number of students was projected to decline by 10% over the next decade, says Ludger Woessmann of the University of Munich.

The biggest problem for education systems is that refugee children tend to be concentrated together. Many attend schools near refugee centres or in immigrant neighbourhoods. In Norway, Denmark and Sweden about 70% go to schools where at least half of the pupils are immigrants. This means they are partially segregated and less likely to learn the local language.

Moreover, immigrants tend to find housing in poor areas with lower education standards. Schools where more than a quarter of students are immigrants usually perform worse than those with no immigrants (see chart), although the gap shrinks when economic status is accounted for. At Mr Ljungqvist’s school, where about 350 of the 750 students were born abroad, many of the brightest pupils have left.

Swedish schools faced problems well before the latest migrants began arriving. From 2002 to 2012 Sweden’s rank in the OECD’s Programme for International Student Assessment (PISA) fell more than any other country’s, to 28th out of 34 countries in mathematics and 27th in reading and science. Pupils in Sweden are more likely to arrive late to school than in any other rich-world country. The government has responded to declining scores by increasing teachers’ pay, but it still does little or no inspecting of schools. The OECD’s Andreas Schleicher says the system lacks a culture of accountability.

Germany’s PISA rankings remain high, but its school system is “almost the worst you could pick” for migrants, says Maurice Crul, an expert on immigrant youth at Erasmus University in Rotterdam. Unlike France or Sweden, where most children start preschool before age three, German children tend to start school at four or five. Many schools have only half-day classes.

Moreover, the German system streams pupils at 10 into either vocational or academic systems—and immigrant children are 44 percentage points more likely than natives to be sent to vocational courses. Unlike other vocational systems such as that in the Netherlands, Germany’s makes it hard to move from a vocational track to an academic one. Lack of native language skills can steer bright immigrant children away from a university education. The system’s inflexibility also makes it harder to integrate older immigrant children. Germany has one of the world’s biggest gaps in reading proficiency between those who arrive aged between six and 11 and those who arrive aged 12 or over.

The German system has its strengths. In less than a decade, Germany has improved the mathematics grades of second-generation migrant children by the equivalent of over a year of schooling. In some German states school days are being extended, and the government has made a big investment in preschool education. In Sweden, meanwhile, older refugees are being trained as teaching assistants to speed integration. Ronna School and others scrapped separate “introductory lessons” for refugees after realising they led to immigrants being segregated and bullied.

But far more could be done. Pupils could be distributed throughout the school system more effectively. In Aarhus, a city in Denmark, the proportion of pupils from migrant backgrounds cannot exceed 20% in each school; a similar distribution in Germany and Sweden could help fight ghettoisation. And refugee children should be getting more preschool. According to the OECD, 15-year-old immigrant children are 20% less likely to have attended pre-primary education than the native-born, but those who have score 49 points higher in reading than those who have not.

Most important, European governments need to treat refugee children as an opportunity rather than a problem. Driven by a desperate desire for a better life, they and their parents tend to be hard-working and ambitious. Europeans worried about migrants studying beside their children should take comfort: the most important predictor of pupils’ school results is their parents’ level of education, and about half of the refugees reaching Europe from Syria have university degrees, according to UNHCR, the UN refugee agency (though other surveys put this number far lower). “Sometimes I joke that Syrian children may help reverse [our decline in] PISA results in maths,” quips Ms Hadzialic. If they are integrated properly, she may be right.

Editor's note: This piece was updated on January 6th to include additional information on the proportion of refugees with university degrees.