#include<bits/stdc++.h>
#define inf 100000000000
#define lnt long long
using namespace std;
lnt xx;char ff,chh;inline lnt read(){
    xx=ff=0;while(!isdigit(chh)){if(chh=='-'){ff=1;}chh=getchar();}
    while(isdigit(chh)){xx=(xx<<1)+(xx<<3)+chh-'0';chh=getchar();}return ff? -xx: xx;
}
const lnt N=2e5,MOD=1e9+7;
void sr_init(){freopen("assign.in","r",stdin);freopen("assign.out","w",stdout);}
void solve();
lnt pow_int(lnt b,lnt k);
int main(){
    sr_init();
    lnt G=read();
    while(G--){
        solve();
    }

    return 0;
}
map<lnt,lnt> ys;
void solve(){
    lnt n=read(),m=read(),v=read(),ans=1;
    ys.clear();
    bool pd=1;
    while(m--){
        lnt b=read(),k=read();
        if(ys[b] && ys[b]!=k){pd=0;}
        ys[b]=k;
    }
    if(pd==0){printf("%lld\n",0ll);return;}
    ys[inf]=0;
    auto i=ys.begin();
    ans*=pow_int(v*v,i->first-1);ans%=MOD;
    for(;i!=ys.end();++i){
        auto nx=i;nx++;
        if(nx->first==inf){
            ans*=pow_int(v*v,n-i->first);ans%=MOD;
            break;
        }
        lnt tp=pow_int(v*v,nx->first-i->first)-((pow_int(v,nx->first-i->first-1)*(v-1))%MOD);
        tp%=MOD;if(tp<0){tp+=MOD;}
        ans*=tp;ans%=MOD;
    }
    printf("%lld\n",ans);
}
lnt pow_int(lnt b,lnt k){
    lnt tp=1;b%=MOD;
    while(k){
        if(k&1){tp*=b;tp%=MOD;}
        b*=b;b%=MOD;k>>=1;
    }
    return tp;
}
