I don’t understand exactlly where you are going so will not try to answer.
With regards to arg/3 the post: Does SWI-Prolog have N+K-trees? helped me learn a lot.
In particular the code from Jan W in this reply.
The notes I took in learning to use it in this reply.
HTH