This came from a database theory study about queries on graphs:
https://dl.acm.org/doi/10.1145/3517804.3524149 for the paywalled version,
https://www.theoinf.uni-bayreuth.de/pool/documents/Paper2021... for the open-access paper. But honestly I find the problem intriguing for its own sake.