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

#define ll long long
#define INF 0x3f3f3f3f
#define int ll

const int mod = 1e9 + 7;

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

const int N = 2e5+5;

int T,n,m,v;

struct node
{
	int c,d;
}a[N];

bool cmp(node a,node b){return a.c < b.c;
}

int ksm(int a,int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin >> T;
	while (T--)
	{
		n = rd(),m = rd(),v= rd();
		int V2 = v*v%mod;
		for (int i =  1;i <= m;i++) a[i].c= rd(),a[i].d = rd();
		sort(a + 1,a + m + 1,cmp);
		bool flag = 1;
		for (int i = 1;i <= m-1;i++) if (a[i].c == a[i+1].c && a[i].d != a[i+1].d) flag = 0;
		if (!flag)
		{
			puts("0");
			continue;
		}
		int ans =ksm(V2,(a[1].c-1)) * ksm(V2,(n-a[m].c))%mod;
		int last = 1;
	//	cout << ans << endl;
		for (int i = 2;i <= m;i++)
		{
			if (a[i].c == a[last].c) {last = i;continue;}
			int siz = (a[i].c - a[last].c - 1);
			ans = ans * ((ksm(V2,siz+1) - ksm(v,siz) * (v-1)%mod+mod)%mod)%mod;
		//	cout << siz << ' ' << ans << endl;
			last = i;
		}
		printf("%lld\n",ans);
		
	}
	return 0;
}
/*
1
10 11 2
10 2
7 2
7 2
2 2
3 2
4 2
10 2
7 2
10 2
3 2
3 2


*/

