f = {(3, 1), (9, 3), (12, 4)} and g = {(1, 3), (3, 3) (4, 9) (5, 9)}
f : {3, 9, 12} → {1, 3,4} and g : {1, 3, 4, 5} → {3, 9}
Co-domain of f is a subset of the domain of g.
So, gof exists and gof : {3, 9, 12} → {3, 9}
Co-domain of g is a subset of the domain of f.
So, fog exists and fog : {1, 3, 4, 5} → {3, 9, 12}