#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#define i64 __int64
#define out64 %I64d
#define in64 "%I64d"
#else
#define i64 long long
#define out64 %lld
#define in64 "%lld"
#endif
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a) for( int i = (a)-1 ; i >= 0 ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define SZ(a) ((int)a.size())
#define PP(n,m,a) puts("---");FF(i,n){FF(j,m)cout << a[i][j] << ' ';puts("");}
#define pb push_back
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-10;
const double pi = acos(-1.0);
const int maxn = 222;
const int add = 111;
int T,n,m,e;
vector<int>g[maxn];
bool a[maxn][maxn];
int back[maxn];
bool vis[maxn];
bool dfs(int now)
{
int to;
for(int i=0;i<g[now].size();i++)
{
to = g[now][i];
if(!vis[to])
{
vis[to] = true;
if(back[to] == -1 || dfs(back[to]) )
{
back[to] = now;
return true;
}
}
}
return false;
}
int dpstart()
{
MM(vis,false);
MM(back,-1);
int ans = 0;
for(int i=1;i<=n;i++)
{
MM(vis,false);
ans += dfs(i);
}
return ans;
}
int main()
{
cin>>T;
for(int tt=1;tt<=T;tt++)
{
FF(i,maxn) g[i].clear();
MM(a,false);
cin>>n>>m>>e;
int now,to;
for(int i=1;i<=e;i++)
{
cin>>now>>to;
to += add;
a[now][to] = true;
a[to][now] = true;
}
for(int i=1;i<=n;i++)
{
now = i;
for(int j=1;j<=m;j++)
{
to = j+add;
if(a[now][to]==false)
{
g[now].pb(to);
g[to].pb(now);
}
}
}
cout<<"Case "<<tt<<": ";
cout<<dpstart()<<endl;
}
return 0;
}