#include <bits/stdc++.h>
using namespace std;
const int N = 1e9+5;
const int N1 = 14;
const int N2 = 1e5+5;
const int INF = 1e9+7;
const int M = 1e5+5;

struct node{
	int x,y;
}a[M];

int n,m,v;
int b[N2];
int ans;

int arr[N1];

inline bool cmp(node x,node y){
	return x.x < y.x;
}

inline int res(int x){
	if(x == 1) return 2;
	return 1;
}

inline void dfs(int x,int A,int B){
	if(x >= n){
		ans++;
		return ;
	}
	if(b[x]){
		arr[x] = b[x];
		
	}
	
	arr[x] = 1;
	
	
	arr[x] = 2;
	
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	
	int T;
	cin >> T;
	while(T--){
		memset(b,0,sizeof(b));
		ans = 0;
		bool isFalse = false;
		
		cin >> n >> m >> v;
		
		
		for(int i = 1; i <= m; i++){
			cin >> a[i].x >> a[i].y;
			if(b[a[i].x]) isFalse = true;
			b[a[i].x] = a[i].y;
		}
		
		if(n == 1){
			if(b[1]) cout << 1 << endl;
			else cout << v << endl;
			continue;
		}
		
		if(isFalse){
			cout << 0 << endl;
			continue;
		}
		
		cout << (1<<n) << endl;
//		
//		if(n <= 12 && v <= 2){
////			dfs(0);
//			cout << ans << endl;
//			continue;
//		}
//		
//		sort(a+1,a+1+m,cmp);
//		
//		if(m == 1){
//			
//		}
	}
	
	return 0;
} 
