const
	MAXN = 100;
	MAXK = 11;
	INF = 1000000000;

var
	g: array [0..MAXN * MAXK, 0..MAXN * MAXK] of longint;
	d: array [0..MAXN * MAXK] of int64;
	u: array [0..MAXN * MAXK] of boolean;
	NN, n, m, k, a, b, c, x, v, i: longint;

begin
//	assign(input, 'F.in'); reset(input);
//	assign(output, 'F.out'); rewrite(output);
	
	readln(n, m, k);
	for i := 0 to m - 1 do
	begin
		readln(a, b, c);
		dec(a); dec(b); dec(c);
		g[a * k + c][b * k + c] := INF;
		g[b * k + c][a * k + c] := INF;
	end;
	for i := 0 to n - 1 do
	begin
		for a := 0 to k - 1 do
		begin
			for b := 0 to k - 1 do
			begin
				read(x);
				g[i * k + a][i * k + b] := x;
			end;
			readln;
		end;
	end;
	NN := n * k;
	v := 0;
	for i := 0 to NN - 1 do
	begin
		d[i] := -1;
		u[i] := false;
	end;
	d[0] := 0;
	repeat
		for i := 0 to NN - 1 do
			if not u[i] and (g[v][i] <> 0) and ((d[i] = -1) or (d[i] > d[v] + g[v][i])) then
			begin
				d[i] := d[v] + g[v][i];
			end;
		u[v] := true; v := -1;
		for i := 0 to NN - 1 do
		begin
			if not u[i] and (d[i] <> -1) and ((v = -1) or (d[i] < d[v])) then
			begin
				v := i;
			end;
		end;
	until v = -1;
	writeln(d[NN - 1] div INF, ' ', d[NN - 1] mod INF);
end.
