How could anybody deduce that? A simple matrix has predefined values for both Rows and Columns. You provided Column Values only. Does the cell values represent Train numbers or Line Numbers?
In the attached workbook there are two examples of a table layouts (Lines/Waypoint, resulting in Train values and Trains/Waypoints resulting in Line values).
How about you construct a table layout showing which Waypoints lie in which Lines, and show us that bit before this breaks down completely.Perhaps looping and taking out those waypoints that don't reach destination (broken route)??