Assigning serial number to the pipe as water move in the pipe stream

I would like to give serial number to the pipe in increasing order as water is flowing in the pipes. As showing in the picture 401, 402, 403 etc
In T joint, it will assign the number in till the pipes end and then again start the numbering from T joint stream.
In the given example, number series start with respect to pipe diameter if 4" dia pipe start with 400 series and 3" dia pipe start with 300 series.

Thanks in Advance