#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;


const int mod=1e9+7;
int T,n,m,v;
int a[1000100];

void solve()
{
	
}

int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	while(T--)
	{
		scanf("%d%d%d",&n,&m,&v);
		for(int i=1;i<=m;i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			a[x]=y;
		}
		cout<<v*v%mod;
	}
	return 0;
}
