They weren’t. This is the paradox of the Big Bang, Before the Big Bang there was nothing; no time, no matter, nothing. The Big Bang started as an infinitely dense point source at infinite temperature, which then cooled and expanded rapidly. The gases H and He were both created during the Big Bang.
Comments