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

const int B=1e9+7,N=1e9; 
int T,n,m,v,ci,di,nums[N];
long long ans;
int main() {
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	cout<<0<<'\n';
	for(int i=0;i<T;i++){
		ans=0;
		bool ed=0;
		memset(nums,0,sizeof nums);
		cin>>n>>m>>v;
		for(int i=0;i<m;i++){
			cin>>ci>>di;
		}
		cout<<0<<'\n';
			if(nums[ci] != 0 && nums[ci] != di) {
				cout<<0<<'\n';
				ed=1;
			}
			nums[ci] = di;
			cout<<nums[ci]<<'\n';
		if(ed) continue;
		long long a=1+(v-1)*v;
		ans = ((a%(B))*(n-1))%(B);
		cout<<ans<<'\n';
	}
	return 0;
}
