input FILEIO;

prologues := 2;
w = 0.2 mm;
u = 25.0 w;

def t (expr a) =
	((a) yscaled -1.0 shifted (0, n + 2) scaled u)
enddef;

def read_input (expr f) = begingroup
	numeric x, y;
	path p;

	read_line (f);
	m := get_num;
	n := get_num;
	k := get_num;

	pickup pencircle scaled 2 w;
	for i := 1 upto m + 1:
		draw t ((i, 1) -- (i, n + 1));
	endfor;
	for j := 1 upto n + 1:
		draw t ((1, j) -- (m + 1, j));
	endfor;

	for s := 1 upto k:
		read_line (f);
		len := get_num;
		i := 1;
		x := get_num;
		y := get_num;
		p := z;
		for i := 2 upto len:
			x := get_num;
			y := get_num;
			p := p -- z;
		endfor;
%		p := p -- (0.5 * point 0 of p + 0.2 * point (len - 1) of p);
%		p := p -- cycle;
		pickup pencircle scaled 0.8 u;
		draw t (p shifted (0.5, 0.5));
		pickup pencircle scaled 0.34 u;
		draw t (p shifted (0.5, 0.5)) withcolor 0.75 white;
		pickup pencircle scaled 0.82 u;
%		draw (t (point 0 of p + (0.5, 0.5)));
%		pickup pencircle scaled 0.74 u;
%		draw (t (point 0 of p + (0.5, 0.5))) withcolor white;
%		label (decimal (s), t (point 0 of p + (0.47, 0.47)));
	endfor;

	read_line (f); % EOF
endgroup; enddef;

def process (expr f) = begingroup
	read_input (f);
endgroup; enddef;

beginfig (1)
	process ("input.001.txt");
endfig;

beginfig (2)
	process ("input.002.txt");
endfig;

beginfig (3)
	process ("input.003.txt");
endfig;

beginfig (4)
	process ("input.004.txt");
endfig;

end.
