You are right that 3 is for the Trinity and you have general gist down. Here is a little more.
40 is a number associated with penance, purgation, and preparation. Instances, Christ's 40 days in the desert (preparation), the Hebrews in the desert 40 years (all three).
12 is a foundational number. there are 12 sons and tibes of Israel, there are 12 Apostles, 12 foundation stones in the New Jerusalem, Jesus had is first public teaching at age 12. All of these are foundations or beginnings to things.
In the Typicon the order is given as "40-30-50-3-3". In the pre-revolutionary editions, the second petition (with "Lord, have mercy" 30 times) is for the Tsar and the Royal House, while the third petition (with "Lord, have mercy" 50 times) is for the hierarchy and numerous other concerns.
If I find time to look up more for you I will.