#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
#define mk make_pair
#define all(x) x.begin(), x.end()

template<typename T>void gmax(T &x,T y) { if(x<y) x=y; }
template<typename T>void gmin(T &x,T y) { if(x>y) x=y; }

#ifdef DEBUG
#define debug(x) cerr<<"["<<#x<<"]: "<<x<<endl
#else
#define debug(...) 114
#endif
constexpr int mod=1e9+7;
#define int long long
i64 qpow(int x,int y,i64 res=1) {
    for(y%=(mod-1),x%=mod; y>0; y>>=1,x=1ll*x*x%mod) if(y&1) res=res*x%mod;
    return res;
}
void solve() {
    int n,m,v; cin>>n>>m>>v;
    vector<pair<int,int>>p(m+1);
    for(int i=1,x,y; i<=m; i++) cin>>p[i].first>>p[i].second;
    sort(all(p));
    for(int i=1; i<m; i++) if(p[i].first==p[i+1].first&&p[i].second!=p[i+1].second) return cout<<"0\n",void();
    p.erase(unique(all(p)),p.end());
    m=p.size()-1;
    const int V=(v*1ll*(v-1)%mod+1)%mod;
    if(m==1) {
        int pos=p.back().first;
        i64 res=(pos==1?1:qpow(v*v,pos-1))%mod*(pos==n?1:qpow(v*v,n-pos))%mod;
        cout<<res%mod<<'\n';
        return ;
    }
    vector<int>f(m+1);
    f[m]=p.back().first==n?1:V;
    f[m]=f[m]*qpow(v*v,n-p.back().first)%mod;
    bool flag=0;
    for(int i=m; i>1; i--) {
        if(p[i-1].first+1==p[i].first)
            f[i-1]=f[i]*1ll*V%mod;//1
        else {
            int len=p[i].first-p[i-1].first;
            f[i-1]=f[i]*qpow(v*v,len-2)%mod*(V+v%mod)%mod;//129600=r
            flag=1;
        }
    }
    i64 res=f[1]*1ll*qpow(v*v,p[1].first-1)%mod;
    if(p[1].first!=1) res=res%mod*V%mod;
    if(p[1].first!=1||p[m].first!=n) res=res*V%mod;
    cout<<res%mod<<'\n';
}

signed main() {
    freopen("assign.in","r",stdin);
    freopen("assign.out","w",stdout);
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int tt; cin>>tt;
    while(tt--) solve();
    return 0;
}