How to form 6-31G basis set; specific instructions
I believe you have not correctly interpreted the first basis set, which should read:

O1 = 0.061 f(172) + 0.358 f(25) + 0.7 f(5.5)
O2 = -.39 f(3.66) + 1.21 f(.77)
O3 = 1 f(.195)


Note that these are only the s-orbitals. Using the coefficients in the right-most column, two triplets of p-orbitals are also present. By doing it this way for the second basis set, which is 6-31G, you would obtain 3 s-orbitals and two triplets of p-orbitals, making it nine AOs in total. Note that all orbitals in a tuple must have the same contraction scheme, otherwise, the calculation would not be rotationally invariant (to within integration accuracy).

Aside: Why does this basis specify s- and p-orbitals this way?
Depending on the integral scheme, one can reuse certain intermediates of some integrals for others and save some computational time. However, modern programs tend to work better with segmented basis sets (i.e. basis sets that do not allow for reuse, because the $\alpha$ exponents are all different). The results are also of higher quality. IMHO, the Pople basis sets are only of historical interest or for hobbyists with very limited resources.