Get a multimeter and a spare piece of wire.
With the house power turned off !!! connect the spare wire to eg. the live connection of one cable then search for continuity between that and the other cable ends.
Identify and mark all cables, eg. both ends of number one, both ends of number two etc., so you can tell where each comes from and goes to. Until you know that, it's just guesswork.
This is the most likely arragement with three cables going to the light - a ceiling rose connection with power in, power out and a spur to the switch: