#include<iostream>
#include<stdio.h>
using namespace std;
int x[3276710];
long long p = 1e9+7;
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout); 
	int T;
	cin>>T;
	for(int i = 1;i<=T;i++){
		int n,m,v;
		cin>>n>>m>>v;
		bool end = false;
		for(int j = 1;j<=m;j++){
			int c,d;
			cin>>c>>d;
			if(x[c]!=0){
				end = true;
			}
			x[c] = d;
		}
		if(end) {
			cout<<0<<endl;
			continue;
		}
		
		if(n==m){
			bool check = true;
			for(int j = 1;j<=n;j++){
				if(x[j]!=j) check=false;
			}
			if(check){
				if(v>=n){
					long long ans = (n-1+n*(v-n+1))%p;
					cout<<ans<<endl;
				}else{
					cout<<(v-1)%p<<endl;
				}

			}
		}else{
			cout<<1;
		}
	}
}
