#include<bits/stdc++.h>

#define ll long long
#define db double
#define lb lower_bound
#define up upper_bound
#define pb push_back
#define eb emplace_back
#define il inline
using namespace std;

inline long long read(){
	ll res=0,f=1; char c = getchar();
	while('0' > c || c > '9'){ if(c=='-')f=-1; c=getchar(); }
	while('0' <= c && c <= '9'){ res = (res<<1)+(res<<3)+(c-48); c=getchar(); }
	return res*f;
} 

inline void write(long long x){
	if(x < 0) putchar('-'),x=-x;
	if(0 <= x && x <= 9) putchar(x+48);
	else write(x/10),putchar(x%10+48);
	return ;
}

const int MAXN = 1e3+10;
const int MAXV = 1e3+10;
const int MAXM = 1e5+10;
const int Mod = 1e9+7;

ll n,m,v;

struct Node{
	ll pos,val;	
}cd[MAXM];

ll dp[MAXN][MAXV][2][2];
ll t[MAXN];

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ll Tc;Tc = read();
	while(Tc--){
		n = read(),m = read(),v = read();
		for(int i = 1;i <= m;i++) cd[i].pos = read(),cd[i].val = read(),t[cd[i].pos] = cd[i].val; 
		for(int i = 1;i <= v;i++) dp[0][i][0][0] = 1;
		for(int i = 0;i < n;i++){
			if(t[i]){
				ll val = (dp[i][t[i]][1][0] + dp[i][t[i]][1][1] + dp[i][t[i]][0][1] + dp[i][t[i]][0][0]) % Mod;
				for(int k = 1;k <= v;k++){ 
					dp[i+1][k][1][1] = (dp[i+1][k][1][1] + val) % Mod;
					dp[i+1][k][1][0] = (dp[i+1][k][1][0] + val) % Mod;
					dp[i+1][k][0][1] = (dp[i+1][k][0][1] + val) % Mod;
					dp[i+1][k][0][0] = (dp[i+1][k][0][1] + val*(v-1)) % Mod;
				}
			}else{
				for(int j = 1;j <= v;j++){
					ll val = (dp[i][j][1][0] + dp[i][j][1][1] + dp[i][j][0][1] + dp[i][j][0][0]) % Mod;
					for(int k = 1;k <= v;k++){ 
						dp[i+1][k][1][1] = (dp[i+1][k][1][1] + val) % Mod;
						dp[i+1][k][1][0] = (dp[i+1][k][1][0] + val) % Mod;
						dp[i+1][k][0][1] = (dp[i+1][k][0][1] + val) % Mod;
						dp[i+1][k][0][0] = (dp[i+1][k][0][1] + val*(v-1)) % Mod;
					}
				}
				
			}
		}
		ll ans = 0;
		for(int i = 0;i <= 1;i++) for(int j = 0;j <= 1;j++) (ans += dp[n][v][i][j]) %= Mod;
		printf("%lld\n",ans % Mod);
	}
	return 0;
}// NOIP2024 Rp++

