#include #define ll long long #define pb push_back #define fi first #define se second #define endl '\n' #define debug(x) cerr<<#x<<":"<9){write_(x/10);}putchar((x%10)^48);return; } void write(ll x){write_(x);putchar('\n');return;} void getmax(ll &x,ll y){ if(y>x) x=y; return; } void getmin(ll &x,ll y){ if(y>=1; } return res; } void getadd(ll &x,ll y){ x+=y; if(x>=MOD) x-=MOD; return; } int T; ll n,m; ll V; struct node{ ll x,y; bool operator < (const node &w) const{ return x>T; while(T--){ n=read(),m=read(),V=read(); for(int i=1;i<=m;++i){ t[i].x=read(),t[i].y=read(); } sort(t+1,t+m+1); bool flag=1; for(int i=2;i<=m;++i){ if(t[i].x==t[i-1].x&&t[i].y!=t[i-1].y){ flag=0; break; } } if(!flag){ puts("0"); continue; } int tm=1; for(int i=2;i<=m;++i){ if(t[i].x!=t[tm].x) t[++tm]=t[i]; } m=tm; ll ans=0; ans=kmi(V*V%MOD,t[1].x-1); for(int i=1;i