{$O-,Q+,R+}
{Problem C}
{$APPTYPE console}
uses prime, SysUtils;
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;
  fl:boolean;
begin
  Assign ( input , 'matrix.in' );
  Reset ( input );
  Assign ( output , 'matrix.out' );
  Rewrite ( output );
  assert (not seekeoln); Read ( m); assert ((m>=1) and (m<=130));
  assert (not seekeoln); Read ( n); assert ((n>=1) and (n<=130));
  assert (eoln); readln;
  assert (not seekeoln); Read ( a); assert ((a>=1) and (a<=n));
  assert (not seekeoln); Read ( b); assert ((b>=1) and (b<=n));
  assert (eoln); readln;
  assert (not seekeoln); Read ( p); assert ((p>=2) and (p<=997));
  assert (eoln); readln;
  fl:=false;
  for i:=1 to pn do if prime.p[i]=p then fl:=true;
  assert (fl);
  for i:=1 to m do begin
    assert (seekeoln); readln;
    for j:=1 to n do begin
      for k:=1 to n do begin
        assert (not seekeoln);
        read ( d[i][j][k] );
        assert ((d[i, j, k]<p) and (d[i, j, k]>=0));
      end;
      assert (eoln and not eof); readln;
    end;
  end;
  assert (eof);
  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.