{Problem C}
{$APPTYPE console}
var
  m,n,a,b,p : longint;
  d : array [1..130,1..130,1..130] of smallint;
  i,j,k : longint;
  vektor,vektor1 : array [1..130] of longint;
begin
  Assign ( input , 'd.in' );
  Reset ( input );
  Assign ( output , 'd.out' );
  Rewrite ( output );
  Read ( m,n,a,b,p );
  for i:=1 to m do
    for j:=1 to n do
      for k:=1 to n do read ( d[i][j][k] );
  for i:=1 to n do vektor[i]:=0;
  vektor[b]:=1;
  for i:=m downto 1 do begin
    for j:=1 to n do begin
      vektor1[j]:=0;
      for k:=1 to n do vektor1[j]:=(vektor1[j]+vektor[k]*d[i][j][k]) mod p;
    end;
    vektor:=vektor1;
  end;    
  writeln ( vektor[a] );    

  Close ( input );
  Close ( output );
end.