#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
int a[100001];
const int mod  = 1e9+7;
int pow(long long a,int b)
{
	long long c = 1;
	while(b>0)
	{
		if (b&1)
		{
			c = (c*a)%mod;
		}
		a = (a*a)%mod;
		b>>=1;
	}
	return c;
}
signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>t;
	while(t--)
	{
		int n, m, v;
		cin>>n>>m>>v;
		for(int i = 1;i<=m;i++)
		{
			int c, d;
			cin>>d>>c;
			a[i] = d;
		}
		if (v==1)
		{
			cout<<1<<endl;
			continue;
		}
		long long ans = 1;
		for(int i = 1;i<m;i++)
		{
			ans = (ans*((v-1)*v%mod+1))%mod;
		}
		cout<<ans<<endl;;
	}
	return 0;
}
