#include<bits/stdc++.h>
#define int long long
#define up(i,l,r) for(int i=l; i<=r; ++i)
#define dn(i,r,l) for(int i=r; i>=l; --i)

using namespace std;

const int N=100005, P=1e9+7;

int ksm(int a,int b) {
	int ret=1;
	for( ; b; b>>=1) {
		if(b&1) ret=ret*a%P;
		a=a*a%P;
	}
	return ret;
}

int T, n, m, v, Ans;
struct node {
	int x, v;
	bool operator<(const node &rhs) const { return x<rhs.x; }
} p[N];

void mian() {
	cin >> n >> m >> v, Ans=1;
	up(i,1,m) cin >> p[i].x >> p[i].v;
	sort(p+1,p+1+m);
	if(p[1].x>1) Ans=Ans*ksm(v*v%P,p[1].x-1);
	up(i,2,m) {
		if(p[i].x==p[i-1].x) {
			if(p[i].v==p[i-1].v) continue;
			cout << 0 << '\n';
			return;
		}
		int len=p[i].x-p[i-1].x;
		int f=ksm(v,len), ran=f*f%P, g=ksm(v,len-1);
		Ans=((ran-f)%P+g)%P*Ans%P;
	}
	if(p[m].x<n) Ans=Ans*ksm(v*v%P,n-p[m].x);
	cout << (Ans%P+P)%P << '\n';
}

signed main() {
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> T;
	while(T--) mian();
	return 0;
}
