Classmates, friends and families of the victims of a mass shooting at a Brazil school have begun saying their goodbyes.

Thousands attended a wake in the devastated Sao Paulo suburb as authorities worked to understand what drove two former students to attack with a gun, crossbows and axes.

Before 17-year-old Guilherme Taucci Monteiro and 25-year-old Henrique de Castro launched an assault at the public school on Wednesday morning, police said they shot and killed a man who owned a used car dealership nearby.

What came next, partially caught on surveillance camera footage shot at the school’s entrance and widely distributed in Brazil, was horrifying.

Upon entering, Monteiro is seen shooting several people as they try to run away. Moments later, de Castro enters, first striking wounded people on the ground with a small axe and then swinging it wildly while scores of students run past him.

Relatives and friends of the victims of a school shooting in Brazil attend a large wake
Relatives and friends of the victims of a school shooting in Brazil attend a large wake (Andre Penner/AP)

De Castro then arms his bow and walks further into the school.

“I couldn’t sleep. I have two children in school and they are about the age of the victims,” said Wanda Augusta, a 46-year-old woman attending the wake.

In total, seven were killed at the school, including five students, a teacher and a school administrator. Nine others were wounded in the attack. Of those, seven are still in hospital, three in intensive care.

The large wake in a volleyball arena was for four of the students and the two school employees. Services for the other victims were held in other places.

“If only we could have identified the difficulties of these boys,” said Rossieli Soares, the state education secretary, while attending the wake. “This is a problem in our society.”

Joao Camilo Pires de Campos, the state’s public security secretary, summed up what was on the minds of many Brazilians.

“The big question is: What was the motivation of these former students?” he said.

Monteiro’s mother, Tatiana Taucci, offered a possible partial answer, saying that her son had been bullied at the school.

“Bullying, they call it… He stopped going to school… because of this,” she said.

She said she was surprised by his involvement and found out about the attack from the television.

Minutes before the attack, Monteiro posted 26 photos on his Facebook page, including several with a gun.

In some of the photos, he wore a black scarf with a white imprint of a skull and cross bones. No text accompanied the posts.

The assailants were trying to force their way inside a room at the back of the school where many students were hiding when police arrived. Instead of facing officers, Monteiro shot de Castro and then shot himself, authorities said.