Fix query in paging