Works on given test, have to fix the output (strange endline char)