#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll t,n,m,v;
ll f[100005];
const ll mod=1e9+7;
struct intt{
    ll c,d;
}a[100005];
bool cmp(intt x,intt y){
    return x.c<y.c;
}
ll qpow(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1) (res*=x)%=mod;
        (x*=x)%=mod;
        y>>=1;
    }
    return res;
}
int main(){
    freopen("assign.in","r",stdin);
    freopen("assign.out","w",stdout);
    scanf("%lld",&t);
    while(t--){
        scanf("%lld%lld%lld",&n,&m,&v);
        for(int i=1;i<=m;i++){
            scanf("%lld%lld",&a[i].c,&a[i].d);
        }
        sort(a+1,a+m+1,cmp);
        bool flag=true;
        for(int i=2;i<=m;i++){
            if(a[i].c==a[i-1].c&&a[i].d!=a[i-1].d){
                printf("0\n");
                flag=false;
                break;
            }
        }
        if(!flag) continue;
        ll len=a[1].c-1;
        f[1]=qpow(v,2*len);
        for(int i=2;i<=m;i++){
            if(a[i].c==a[i-1].c){
                f[i]=f[i-1];
                continue;
            }
            len=a[i].c-a[i-1].c;
            f[i]=f[i-1]*((qpow(v,2*len)-(v-1)*qpow(v,len-1)%mod+mod)%mod)%mod;
        }
        len=n-a[m].c;
        printf("%lld\n",f[m]*qpow(v,2*len)%mod);
    }
    return 0;
}