No, the two g's do NOT cancel. Whoever assigned you these problems assumed that you understood basic algebra. Now, I don't wish to sound mean, but it is clear from what I have quoted above that you do not understand basic algebra. I will make one last effort to explain this, but I have to say that after that if you still do not understand, I cannot help you. It is not reasonable to expect somebody on this online forum to teach you algebra.
First of all, saying that the g's cancel is like saying that:
ab - a = b
This is most emphatically NOT true.
ab - a IS NOT EQUAL TO b
This should be obvious, but if you don't understand, then at least try plugging in example numbers so that you can see what I am saying is true
a = 3
b = 7
ab - a = 3*7 - 3 = 21 - 3 = 18 WHICH IS NOT EQUAL TO 7
What I was trying to say in my previous post is that subtracting g from both sides will NOT help. Look at the right hand side. The right hand side is multiplied by g. If something is multiplied by g, what operation could I do to that something to get rid of the g (hint: it would be something that "undos" the multiplication).