Show node ID when printing the trace.
Better tree construction.

When a rule defines multiple ID, the tree used the first one instead of
the last one (present in the trace). This is now fixed and it behaves as
expected.