#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <bitset>

using namespace std;

const int maxn = 1e7 + 10;
const int mod = 1e9 + 7;
int n, m, v;
int x[maxn];
bitset<maxn> vis;
long long ans;

int main() {
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d%d", &n, &m, &v);
		int c, d;
		bool flag = true;
		for (int i = 1; i <= m; i++) {
			scanf("%d%d", &c, &d);
			if (vis[c] == false) {
				vis[c] = true;
				x[c] = d;
			} else {
				printf("0\n");
				flag = false;
				break;
			}			
		}
		if (flag) {
			printf("%lld\n", ans);
		}
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
} 
