I do more graph theory, but we touch on a bit of topology there, so assuming that I understand your question, it's basically the same procedure.
Using a diagram such as this one, you paste the edges marked with the same letters together. You line up the two edges with the same letter in such a way that the arrows are pointing in the same direction. If you think about it for a few minutes, you'll see how this forms the handles for an orientable surface, or the crosscaps for a non-orientable surface.
For example, let's look at diagram 8.5.4 in the link. For those following along at home, this is a surface with two handles, so the flat representation is an octagon, with edge sequence
$aba^{-1}b^{-1}cdc^{-1}d^{-1}$
where the negative one means that the edge has direction reversed. So we start by pasting $a$ to $a^{-1}$, remembering to keep the arrows pointing in the same direction, which you can imagine forms a sort of cylinder with $b$ as an edge. Now you can paste $b$ to $b^{-1}$, which is a little harder to visualize but if you stare at it, you'll see that you have formed a handle. Now repeat with the other 4 edges, and you have a surface with 2 handles.