#include #include #include #include #include #include #include #include #include #include using namespace std; using namespace chrono; bool Mbe; bool File(string Name) { string In=Name+".in",Out=Name+".out"; freopen(In.c_str(),"r",stdin); freopen(Out.c_str(),"w",stdout); return true; } bool fle=File("assign"); template void Debug(T s) { cerr< void Debug(T s,Args... args) { cerr<'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0' && ch<='9'){s=s*10+ch-'0';ch=getchar();}return s*f;}void rd(Type &x){x=rd();}templatevoid rd(Type &x,Args&... args){rd(x);rd(args...);}void rdArr(Type *arr,int Len){for(int i=1;i<=Len;i++)rd(arr[i]);}void wr(Type x){if(x<0)putchar('-'),x=-x;if(x>9)wr(x/10);putchar(x%10+'0');}void wr_space(Type x){wr(x);putchar(' ');}void wr_endl(Type x){wr(x);putchar('\n');}void wrArr(Type *arr,int Len){for(int i=1;i>=1; } return res; } void Input() { long long ret=1; rd(n,m,v); for(int i=1;i<=m;i++) rd(p[i].c,p[i].d); sort(p+1,p+m+1); // int st=0,ed=0; p[0].c=p[m+1].c=-1; for(int i=1;i<=m;i++) { if(p[i].c==p[i-1].c && p[i].d!=p[i-1].d) return wr_endl(0); } m=unique(p+1,p+m+1)-p-1; p[m+1].c=-1; // Debug(m); // for(int i=1;i<=m;i++) // Debug(p[i].c," ",p[i].d); for(int i=2;i<=m;i++) ret=ret*(qpow(v*v%M,p[i].c-p[i-1].c)-qpow(v,p[i].c-p[i-1].c-1)%M*(v-1)%M+M)%M; // ret=(qpow(v*v%M,ret)-qpow(V,ret)+M)%M*qpow(v*v%M,n-1-ret)%M; // wr_endl((qpow(v*v%M,n-1)-ret+M)%M); if(m>1) wr_endl(ret*qpow(v*v%M,(p[1].c-1+n-p[m].c+M)%M)%M); else wr_endl(qpow(v*v%M,n-1)); } void Solve() { // Hello } void Output() { // Hello } bool Med; int main() { fprintf(stderr,"%0.3lf MiB\n",(&Mbe-&Med)/1048576.0); while(T--) Input(); Solve(); Output(); return 0; } // wocao���ݳ�ԭ���� /* ����ÿһ�ο��н⣺ qpow(v*v%M,ed-st)-qpow(V,ed-st) Ӧ����ȫ���ģ����� */