#include <cstdio>
#define ll long long
const int M=1e5+10;
const int Mod=1e9+7;
int t,n,m,v;
int yy[M];
ll ans;
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d%d%d",&n,&m,&v);
		ans=0;
		for(int i=1;i<=m;i++){
			int c,d;
			scanf("%d%d",&c,&d);
			yy[c]=d;
		}
		ans=n%Mod;
		printf("%lld\n",ans);
	}
	return 0;
}
