#include #include #include #define MAXN 100010 #define int long long #define forr(i,l,r) for(int i=(l);i<=(r);i++) using namespace std; void read(int &x){ char ch = getchar(); int w = 1; x = 0; while( ch < '0' || '9' < ch ){ if( ch == '-' ) w = -1; ch = getchar(); } while( '0' <= ch && ch <= '9' ) x = x*10+ch-'0', ch = getchar(); x *= w; return ; } const int mod = 1000000007; int fpow(int a,int b){ int c = 1; while(b){ if(b&1) c = c*a%mod; a = a*a%mod; b >>= 1; } return c; } struct LIMIT{ int c,d; } p[MAXN]; bool operator <(LIMIT a,LIMIT b){ return a.c < b.c; } int t,n,m,v,sum,ans; signed main(){ // freopen("assign3.in","r",stdin); freopen("assign.in","r",stdin); freopen("assign.out","w",stdout); read(t); while(t--){ read(n), read(m), read(v); forr(i,1,m) read(p[i].c), read(p[i].d); sort(p+1,p+m+1); ans = 1; forr(i,1,m){ if( p[i].c == p[i-1].c ){ if( p[i].d != p[i-1].d ) { ans = 0; break; } } else{ if( i == 1 ){ sum = fpow(v,(p[i].c-p[i-1].c-1)*2)%mod; ans = ans*sum%mod; } else{ sum = fpow(v,(p[i].c-p[i-1].c)*2)%mod; sum = (sum-fpow(v,p[i].c-p[i-1].c-1)*(v-1))%mod; ans = ans*sum%mod; } } // printf("[%lld] %lld\n",i,sum); } ans = ans*fpow(v,(n-p[m].c)*2)%mod; printf("%lld\n",(ans%mod+mod)%mod); } return 0; }