#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int M=1e5+5;
const ll mod=1e9+7;
template<typename T>
void read(T &x){
    x=0;
    char ch;
    while((ch=getchar()))
        if('0'<=ch&&ch<='9') break;
    while('0'<=ch&&ch<='9'){
        x = x*10+ch-'0';
        ch=getchar();
    }
}
int T;
ll n,m;
ll v;
struct node{
    ll c,d;
}l[M];
ll f[M];
ll fp(ll x,ll p){
    ll res=1;
    while(p>0){
        if(p&1) res=res*x%mod;
        x=x*x%mod;
        p>>=1;
    }
    return res;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
    read(T);
    while(T--){
        read(n),read(m),read(v);
        for(int i=1;i<=m;i++) read(l[i].c),read(l[i].d);
        sort(l+1,l+m+1,[](node a,node b){return a.c<b.c;});
        f[1] = fp(v*v%mod,l[1].c-1);
        bool flag=0;
        for(int i=2;i<=m;i++){
            // printf("%d\n",l[i].c-l[i-1].c);
            if(l[i].c==l[i-1].c){
                if(l[i].d!=l[i-1].d){
                    flag=1;
                    break;
                }
                f[i]=f[i-1];
                continue;
            }
            if(l[i].c==l[i-1].c+1) f[i] = f[i-1]*(((v*v%mod)-v+1+mod)%mod)%mod;
            else{
                ll more = fp(v,l[i].c-l[i-1].c-1)*((1-v+mod)%mod)%mod;
                f[i] = f[i-1] * ((fp(v*v%mod,l[i].c-l[i-1].c)+more+mod)%mod)%mod;
                continue;
            }
        }
        // printf("\nans:%lld\n",fp(v*v%mod,n-1));
        if(flag) printf("0\n");
        else printf("%lld\n",f[m]*fp(v*v%mod,n-l[m].c)%mod);
    }
	return 0;
}
