#include<iostream>
#include<cstdio>
#include<algorithm>
#include<utility>
#define __start__\
    freopen("assign.in","r",stdin);\
    freopen("assign.out","w",stdout);\
    ios::sync_with_stdio(0);\
    cin.tie(0);
#define def_const 100010
using namespace std;

const int mod=1000000007;

pair<int,int> p[def_const];
long long pv[64];

void init(long long v){
    pv[1]=v;
    for(int i=1;i<63;i++){
        pv[i+1]=pv[i]*pv[i];
        pv[i+1]%=mod;
    }
}

long long powerv(int x){
    int j=1;
    long long ans=1;
    while(x){
        if(x&1){
            ans*=pv[j];
            ans%=mod;
        }
        j++;
        x>>=1;
    }
    return ans;
}

int main(){
    __start__
    int t;
    cin>>t;
    while(t--){
        int n,m,v;
        cin>>n>>m>>v;
        init(v);
        for(int i=1;i<=m;i++){
            cin>>p[i].first>>p[i].second;
        }
        sort(p+1,p+1+m);
        long long ans=1;
        int m1=m;
        for(int i=1;i<m;i++){
            if(p[i].first==p[i+1].first){
                if(p[i].second!=p[i+1].second){
                    ans=0;
                    break;
                }
                else{
                    m1--;
                    continue;
                }
            }
            ans*=powerv(p[i+1].first-p[i].first+1)-1;
            ans%=mod;
        }
        ans*=powerv(2*n-p[m].first+p[1].first-m1-1);
        ans%=mod;
        cout<<ans<<'\n';
    }
    return 0;
}