#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;
int p,q,k;
int match[200000];
vector<int> connnect[200000];
int visit[200000] = {0};
bool flag[200000] = {0};
void solve();
int dfs(int,int);
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int cases;
cin >> cases;
while(cases--) solve();
}
void solve(){
cin >> p;
cin >> q;
cin >> k;
for(int a = 0;a < p+q;a++) match[a] = -1;
for(int a = 0;a < p+q;a++){
vector<int> k;
connnect[a] = k;
}
for(int a = 0;a < k;a++){
int x,y;
cin >> x;
cin >> y;
connnect[x-1].push_back(y+p-1);
connnect[y+p-1].push_back(x-1);
}
for(int a = 0;a < p+q;a++) {
flag[a] = 0;
}
for(int a = 0;a < p+q;a++){
//for(int b = 0;b < p+q;b++){
//cout << b << " matches " << match[b] << endl;
//cout << flag[b] << " ";
//}
//cout << '\n';
//cin.get();
if (!flag[a]){
for(int b = 0;b < p+q;b++) visit[b] = 0;
int result = dfs(a,0);
}
}
int ans = 0;
for(int a = 0;a < p;a++){
if (match[a] != -1) ans++;
}
cout << ans << '\n';
}
int dfs(int now,int next){
visit[now] = 1;
for(int a = 0;a < connnect[now].size();a++){
if (visit[connnect[now][a]]) continue;
if (!flag[connnect[now][a]]){
match[now] = connnect[now][a];
match[connnect[now][a]] = now;
flag[connnect[now][a]] = 1;
flag[now] = 1;
return 1;
}
else if ((next&&match[now] == connnect[now][a])||(match[now] != connnect[now][a]&&(!next))){
if (dfs(connnect[now][a],(next+1)%2)) {
if (!next){
match[connnect[now][a]] = now;
match[now] = connnect[now][a];
return 1;
}
}
}
}
return 0;
}
連1%都沒過.......(範例明明有過的說)