query: fix last line appearing first