Print element of lisrs with indexes

I’m using: SWI-Prolog version 8.4.3 for x64-win64

I want the code to print elements of the list with them indexes

Exemple :

from this list :

[p(301, 1, 2), p(201, 5, 2), p(401, 1, 4), p(501, 1, 5)]

I want to get something like :

1 301 1 2
2 201 5 2
3 401 1 4
4 501 1 5

My code looks like this:

forall(order_by([asc(Z)], p(X,Y,Z)), format("~w ~w ~w~n", [X,Y,Z])).

Thanks to @Boris who helped me with the format

But, how can i add the index in each line ?

You’ve already asked, and received several methods, at Display elements of a list with there index in PROLOG - Stack Overflow

The list is in aformat of (X-Y)
[a-b, c-d, e-f, g-h].
How can i print the key value pairs in the format X Y with the dash ‘-’ ?