Please, use the
<code>...</code> tags for the sample input, too, so we can see where the line breaks are. Your code kind of works for me: it prints the lines
before the html tag. Inside the HTML, @query is empty, because you already
shifted everything from it in the loop.