I would like to ask how to write the query as shown in drawing below, from point d to point a, the TRAIL does not include d → b → a → j → a.

If I don't want it to pass through a before going forward, is there any query method?
Thanks!