#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;constintN=100010,M=2000010;intn,m,mod;inth[N],hs[N],e[M],ne[M],idx;intdfn[N],low[N],scc[N],sz[N],dfncnt,sc;intf[N],g[N];boolstk[N];stack<int>St;voidadd(inth[],inta,intb){e[idx]=b,ne[idx]=h[a],h[a]=idx++;}voidtarjan(intu){dfn[u]=low[u]=++dfncnt;St.push(u);stk[u]=true;for(inti=h[u];i!=-1;i=ne[i]){intj=e[i];if(!dfn[j]){tarjan(j);low[u]=min(low[u],low[j]);}elseif(stk[j])low[u]=min(low[u],dfn[j]);}if(dfn[u]==low[u]){inty;sc++;do{y=St.top();St.pop();stk[y]=false;scc[y]=sc;sz[sc]++;}while(u!=y);}}intmain(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);memset(h,-1,sizeofh);memset(hs,-1,sizeofhs);cin>>n>>m>>mod;while(m--){inta,b;cin>>a>>b;add(h,a,b);}for(inti=1;i<=n;i++)if(!dfn[i])tarjan(i);// 边判重,建新图unordered_set<LL>S;// u -> v == u * 1000000 + v;for(inti=1;i<=n;i++)for(intj=h[i];j!=-1;j=ne[j]){intk=e[j];inta=scc[i],b=scc[k];LLhash=a*1000000+b;if(a!=b&&!S.count(hash)){S.insert(hash);add(hs,a,b);}}// 拓扑序DPfor(inti=sc;i;i--){if(!f[i]){f[i]=sz[i];g[i]=1;}for(intj=hs[i];j!=-1;j=ne[j]){intk=e[j];if(f[k]<f[i]+sz[k]){f[k]=f[i]+sz[k];g[k]=g[i];}elseif(f[k]==f[i]+sz[k])g[k]=(g[k]+g[i])%mod;}}intmaxf=0,res=0;for(inti=1;i<=n;i++)if(maxf<f[i]){maxf=f[i];res=g[i];}elseif(maxf==f[i])res=(res+g[i])%mod;cout<<maxf<<endl<<res<<endl;return0;}