Building query to verify the task history