{$APPTYPE CONSOLE}
{$Q+,R+,O-}

const
	maxN = 200;
	fName = 'd';

type TV = array[ 1 .. maxN ] of integer;

var	m, n, a, b, p, i, j, k, x: integer;
	u, v: TV;

begin
	assign(input, 'd.in');
  reset(input);
  
  assign(output, 'd.out');
  rewrite(output);
	repeat
        readln( m, n, a, b, p );
        for i := 1 to a - 1 do readln;
        for j := 1 to n do read( v[j] ); readln;
        for i := a + 1 to n do readln;
        for k := 2 to m do begin
        	fillChar( u, sizeOf( u ), 0 );
        	for i := 1 to n do
        		for j := 1 to n do begin
        			read( x ); inc( u[j], v[i] * x );
        		end;
        	v := u;
        	for i := 1 to n do v[i] := v[i] mod p;
        end;
        writeln( v[b] );
	until seekEOF;
end.
