#include<bits/stdc++.h>
#define int __int128
#define maxn 1000000009
#define maxm 100005
#define endl "\n"
using namespace std;

int read(){
    int f = 1,k = 0;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-') f = -f;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        k=(k<<1)+(k<<3)+c-48;
        c = getchar();
    }
    return f*k;
}

void write(int x){
    if(!x) return;
    write(x/10);
    putchar(x%10+48);
}

struct Fx{
    int id,val;
    bool operator<(const Fx that) const{
        return id < that.id;
    }
}fx[maxm];

int T,n,m,v,cnt,ans[2];
const int q = 1000000007;
bool flag = 0;
vector<Fx> fxd;
signed main(){
    freopen("assign.in","r",stdin);
    freopen("assign.out","w",stdout);
    T = read();
    while(T--){
        n = read();m = read();v = read();
        cnt = 0;
        flag = 0;
        ans[0] = 1;
        ans[1] = 0;
        fxd.clear();
        for(int i = 1;i <= m;i++){
            fx[i].id = read();
            fx[i].val = read();
        }
        sort(fx+1,fx+1+m);
        int lastnum = 0,lastval = 0;
        for(int i = 1;i <= m;i++){
            if(lastnum != fx[i].id){
                lastnum = fx[i].id;
                lastval = fx[i].val;
                fxd.push_back({lastnum,lastval});
            }else{
                if(lastval != fx[i].val){
                    flag = 1;
                    break;
                }
            }
        }
        fxd.push_back({0,0});
        if(flag){
            printf("0\n");
            continue;
        }
        bool flag = 0;
        for(int i = 1;i < n;i++){
            if(fxd[cnt].id < i) cnt++;
            if(cnt >= fxd.size()) cnt =  fxd.size()-1;
            if(i == fxd[cnt].id){
                if(fxd[cnt+1].id == fxd[cnt].id+1){
                    int kk = ans[0];
                    ans[0] *= (v-1)*v+1;
                    ans[0] *= (v-1);
                    ans[0] %= q;
                    ans[0] *= v;
                    ans[0] %= q;
                    ans[0] += kk;
                    ans[0] %= q;
                }else{
                    flag = 1;
                    ans[1] = ans[0]*v;
                    ans[1]%=q;
                    ans[0] = ans[0]*(v-1);
                    ans[0]%=q;
                    ans[0] *= v;
                    ans[0] %= q;
                }
            }else{
                if(i+1 == fxd[cnt].id){
                    int kk = ans[1];
                    int zz = ans[1];
                    kk *= v;
                    kk %= q;
                    kk *= (v-1);
                    kk %= q;
                    kk += zz;
                    kk %= q;
                    ans[0] = ans[0]*v;
                    ans[0]%=q;
                    ans[0] = ans[0]*v;
                    ans[0]%=q;
                    ans[0] += kk;
                    ans[0] %= q;
                    ans[1] = 0;
                    ans[1]%=q;
                }else{
                    int kk = ans[1];
                    ans[1] = ans[1]*v;
                    ans[1] %=q;
                    kk *=(v-1);kk %= q;
                    kk *= v;kk%=q;
                    ans[0]*=v;
                    ans[0]%=q;
                    ans[0]*=v;
                    ans[0]%=q;
                    ans[0]+=kk;
                    ans[0]%=q;
                    // ans[0] = kk*(v-1)*v+ans[0]*v*v;
                    // ans[0]%=q;
                }
            }
        }
        write((ans[0]+ans[1])%q);
        printf("\n");
    }


    return 0;
}