Welding of polygons and the type of Riemann surfaces