Every node is either in the tail or in the cycle. Nodes in the tail eventually reach the cycle but never return. Once you enter a cycle, you are stuck. Nodes in the cycle loop forever. If you are in the cycle, you can reach any other cycle node by going around.
The distance is determined by positions modulo cycle length. Distance queries depend on which region each node is in. Precompute this during a single traversal. Mark cycle nodes and compute tail distances.