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

const
	maxN = 130;
	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 );
        	fillchar( v, sizeOf( v ), 0 ); v[a] := 1;
	        for k := 1 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.
