Nonisomorph groups of order 2002

While searching for non-isomorph subgroups of order 2002 I just encountered something, which I want to understand. Obviously I looked for abelian subgroups first and found $2002={2}^{2}\ast 503$ so we have the groups

$$\mathbb{Z}/{2}^{2}\mathbb{Z}\times \mathbb{Z}/503\mathbb{Z},\mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/503\mathbb{Z}$$

Now I want to understand why those two are not isomorph. I know that for two groups $\mathbb{Z}/n\mathbb{Z}\times \mathbb{Z}/m\mathbb{Z}\cong \mathbb{Z}/(nm)\mathbb{Z}$ it has to hold that $gcd(n,m)=1$. But I don't understand how we can compare Groups written as two products with groups written as three products as above, how does that work? And I think that goes in the same direction: How is it then at the same time that

$$\mathbb{Z}/4\mathbb{Z}\times \mathbb{Z}/503\mathbb{Z}\cong \mathbb{Z}/2012\mathbb{Z}\u2246\mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/503\mathbb{Z}\cong \mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/1006Z$$

because $gcd(4,2012)\ne 1,gcd(2,2)\ne 1,gcd(503,1006)\ne 1$. I don't understand the difference to the first comparison.

While searching for non-isomorph subgroups of order 2002 I just encountered something, which I want to understand. Obviously I looked for abelian subgroups first and found $2002={2}^{2}\ast 503$ so we have the groups

$$\mathbb{Z}/{2}^{2}\mathbb{Z}\times \mathbb{Z}/503\mathbb{Z},\mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/503\mathbb{Z}$$

Now I want to understand why those two are not isomorph. I know that for two groups $\mathbb{Z}/n\mathbb{Z}\times \mathbb{Z}/m\mathbb{Z}\cong \mathbb{Z}/(nm)\mathbb{Z}$ it has to hold that $gcd(n,m)=1$. But I don't understand how we can compare Groups written as two products with groups written as three products as above, how does that work? And I think that goes in the same direction: How is it then at the same time that

$$\mathbb{Z}/4\mathbb{Z}\times \mathbb{Z}/503\mathbb{Z}\cong \mathbb{Z}/2012\mathbb{Z}\u2246\mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/503\mathbb{Z}\cong \mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/1006Z$$

because $gcd(4,2012)\ne 1,gcd(2,2)\ne 1,gcd(503,1006)\ne 1$. I don't understand the difference to the first comparison.