print query function