finish query template, start to handle input