closed surface from a fundamental polygon.

• Closed surfaces are homeomorphic to either $S$, $gT$(connected sum of g tori), $kP$(connected sum of k real projective planes)
My question is that given a polygon, how can I classify it to above types? For example, suppose given klein bottle $K=abab^{-1}$. I know that the connected sum of two projective planes is klein bottle, but if I didn't know about the fact, is it easy to classify $K$? Also for more complicated example such as $abcdecaeb^{-1}d^{-1}$, are there any techniques to classify it? Or is there good reference about these contents?