#include <bits/stdc++.h>

using namespace std;

const int M = 105, N = 105;
bool adjmat[M][N], seen[N]; int matchL[M], matchR[N], m, n;
bool bpm(int u) { // Can we find augmenting path starting from u
	for(int v = 0; v < n; v++) if(adjmat[u][v] && !seen[v]) { seen[v] = true;
		if(matchR[v] == -1 || bpm(matchR[v]) ) { matchL[u] = v, matchR[v] = u;
			return true; } }
	return false;
}

int main() {
	int t; cin >> t;
	while (t--) {
		int k;
		cin >> m >> n >> k;
		memset(adjmat, false, sizeof adjmat);
		for (int i = 0; i < k; i++) {
			double x, y; cin >> x >> y;
			int a = int(x), b = int(y);
			adjmat[a][b] = true;
		}
		memset(matchL,-1,sizeof matchL); memset(matchR,-1,sizeof matchR);
		// Read input, set m, n, and populate adjmat here
		int cnt = 0;
		for(int i = 0; i < m; i++) {
			memset(seen, 0, sizeof seen);
			if( bpm(i) ) cnt++; // matchL[i] is the match
		}
		cout << cnt << endl;
	}
	return 0;
}