use template for query instead of ugly replaceAll, avoid querying if q is a coordinate