If the train is traveling at a constant rate, then the ratio of distance to time will be the same over any distance and respective time interval. So, we can set up a proportion

Where 300+x represents the distance the train traveled through the 300 meter long tunnel plus its own length.

Since the light is small enough to be considered as a single point, we don't need to consider its length.