Do not substitute #[A-Z] in graphite target when invalid ref (#5581)
* Do not substitute #[A-Z] in graphite target when invalid ref
In the case where #[A-Z] does not reference another query, such as #J when there
are only 2 queries, do not perform the substitution. This prevents the situation
target name without a query labelled J (10th query).
* Do not substitute #[A-Z] in graphite target when invalid ref
In the case where #[A-Z] does not reference another query, such as #J when there
are only 2 queries, do not perform the substitution. This prevents the situation
target name without a query labelled J (10th query).