The simplest answer is someone tried it and published their findings.
You can reasonably guess which chemicals should react more strongly to others but it is pretty much a guess unless you find previous research.
Most chemistry I’ve seen is you add A to B to get C, add C to D to get E and so on until you get the compound you want.
NileRed on YouTube is pretty good at explaining chemistry and does some fun experiments where you see the process.
There is not one, universal law for those reactions, but there are rules which we can use to know. I think it never happens that more than two molecules react together, so we can find out, based on what we already know about reaction speeds, which of those reactions will happen and how much will they happen, then we search whether those new chemicals have some effects on other reactants, and that’s how we get to the end of the reaction.
That or the more obvious answer of just testing the final product, until we find out what’s in it
Latest Answers