#include<bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define fir first
#define sec second
const int maxn=1e5;
const int mod=1e9+7;
int n,m,v;
P a[maxn+5];
int ans;
namespace IO{
    inline int Read(){
        int res=0;char ch=getchar();
        while(ch<'0'||'9'<ch) ch=getchar();
        while('0'<=ch&&ch<='9')
            res=(res<<1)+(res<<3)+ch-'0',ch=getchar();
        return res;
    }
}
using IO::Read;
inline int Fpow(int x,int y){
    int res=1;
    for(;y;y>>=1,x=1ll*x*x%mod)
        if(y&1) res=1ll*res*x%mod;
    return res;
}
inline void Solve(){
    n=Read(),m=Read(),v=Read();
    for(int i=1;i<=m;i++)
        a[i].fir=Read(),a[i].sec=Read();
    sort(a+1,a+m+1);
    m=unique(a+1,a+m+1)-a-1;
    for(int i=1;i<m;i++){
        if(a[i].fir==a[i+1].fir&&a[i].sec!=a[i+1].sec){
            puts("0");
            return;
        }
    }
    ans=Fpow(v,2*(a[1].fir-1));
    int t;
    for(int i=1;i<m;i++){
        t=a[i+1].fir-a[i].fir;
        t=(Fpow(v,2*t)-1ll*(v-1)*Fpow(v,t-1)%mod)%mod;
        ans=1ll*ans*t%mod;
    }
    ans=1ll*ans*Fpow(v,2*(n-a[m].fir))%mod;
    printf("%d\n",(ans+mod)%mod);
}
signed main(){
    freopen("assign.in","r",stdin);
    // freopen("assign2.in","r",stdin);
    freopen("assign.out","w",stdout);
    int tcnt;scanf("%d",&tcnt);
    while(tcnt--) Solve();
    return 0;
}