Alternating-Direction Galerkin Methods for Parabolic and Hyperbolic Problems on Rectangular Polygons