#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5,M=1e9+7;
int T,n,m,v,a[N],b[N],r;
map<int,bool>f;
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>T;
	while(T--){
		cin>>n>>m>>v;r=(n*v%M-(m-1)+M)%M;
		for(int i=1; i<=m; i++){
			cin>>a[i]>>b[i];
			if(f[a[i]]){r=0;break;}
			else f[a[i]]=1;
		}
		f.clear();
		cout<<r<<"\n";
	}
	return 0;
}
