#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
const int N=1e5+10;
int n,m,v;
pair<int,int> a[N];
ll ksm(ll a,ll b)
{
    ll ans=1;
    while(b){
        if(b&1) ans=ans*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return ans;
}
void solve()
{
    cin>>n>>m>>v;
    for(int i=1;i<=m;i++) cin>>a[i].first>>a[i].second;
    sort(a+1,a+1+m);
    for(int i=1;i<m;i++){
        if(a[i].first==a[i+1].first&&a[i].second!=a[i+1].second){
            cout<<"0\n";
            return;
        }
    }
    m=unique(a+1,a+1+m)-a-1;
    ll mul=1;
    for(int i=1;i<m;i++){
        ll czn=(ksm(v,a[i+1].first-a[i].first<<1)-ksm(v,a[i+1].first-a[i].first-1)*(v-1)%mod+mod)%mod;
        mul=mul*czn%mod;
    }
    cout<<mul*ksm(v,a[1].first-1<<1)%mod*ksm(v,n-a[m].first<<1)%mod<<"\n";
}
int main()
{
    // int tim=clock();
    freopen("assign.in","r",stdin);
    freopen("assign.out","w",stdout);
    cin.tie(0)->sync_with_stdio(0);
    int T;
    cin>>T;
    while(T--) solve();
    return 0;
    // cerr<<1.0*(clock()-tim)/CLOCKS_PER_SEC;
}
/*
1
1000000000 2 1
1 1
2 1
*/