#include<bits/stdc++.h>
#define ay array<int,2>
typedef long long LL;
using namespace std;
inline int read(){
    char ch=getchar(); while(ch!='-' && !isdigit(ch)) ch=getchar();
    int x=0,ff=1; if(ch=='-') ff=-1,ch=getchar();
    while(isdigit(ch)) x=(x<<3) + (x<<1) + (ch^48),ch=getchar();
    return x*ff;
}
const int N=1e5+5,P=1e9+7;
inline void add(int &x,int y) {x+=y; x=x>=P?x-P:x;}
int n,m,V,b[N],m1;
struct dt {int x,y;} c[N];
struct mat{
int mx[2][2];
void clr(){ mx[0][0]=mx[0][1]=mx[1][0]=mx[1][1]=0; }
mat operator * (mat A) const { mat B; B.clr();
    for(int i=0;i<2;i++) for(int k=0;k<2;k++) for(int j=0;j<2;j++)
        add(B.mx[i][j],1ll*mx[i][k]*A.mx[k][j]%P);
    return B;
}
} A,B[30];
ay operator *(ay A,mat B) {ay C; C[0]=C[1]=0;
    for(int i=0;i<2;i++) for(int j=0;j<2;j++) add(C[j],1ll*A[i]*B.mx[i][j]%P);
    return C;
}
void vmain(){
    n=read(); m=read(); V=read(); m1=0;
    for(int i=1;i<=m;i++) c[i]={read(),read()};
    sort(c+1,c+m+1,[&](dt x,dt y){return x.x<y.x;});
    for(int i=1;i<m;i++) if(c[i].x==c[i+1].x && c[i].y!=c[i+1].y) {puts("0"); return ;}
    for(int i=1;i<=m;i++) b[++m1]=c[i].x;
    m=unique(b+1,b+m1+1)-b-1;
    ay a; a[0]=a[1]=0; int j=1;
    if(m && b[1]==1) a[1]=1,++j;
    else a[0]=1;
    A.clr(); B[0].clr();
    A.mx[0][1]=1ll*V*V%P; A.mx[1][1]=(1ll*(V-1)*V+1)%P;
    B[0].mx[0][0]=1ll*V*V%P; B[0].mx[1][0]=1ll*(V-1)*V%P; B[0].mx[1][1]=V;
    for(int i=1;i<30;i++) B[i]=B[i-1]*B[i-1];
    for(int l=1,r;l<n;l=r+1){ r=l;
        if(j<=m && b[j]==l+1) a=a*A,++j;
        else {
            if(j>m) r=n-1;
            else r=b[j]-2;
            int k=r-l+1; for(int i=29;i>=0;i--) if(k>>i & 1) a=a*B[i];
        }
    }
    int ans=(a[0]+a[1])%P; printf("%d\n",ans);
}
int main(){
    freopen("assign.in","r",stdin);
    freopen("assign.out","w",stdout);
    int T=read(); while(T--) vmain();
    return 0;
}
/*
g++ assign.cpp -o assign -Wl,-stack=999999999 -Wall -std=c++14
*/