//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200500
#define mod 1001
#define eps 1e-9
#define pi 3.1415926
int Num;
//const int inf=0x7fffffff;
const ll inf=999999999;
inline ll read()
{
ll x=0,f=1;char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
return x*f;
}
//*************************************************************************************
int d[maxn];
int N = 10050;
struct node
{
int x,y;
};
bool cmp(node a,node b)
{
if(a.x==b.x)
return a.y>b.y;
return a.x>b.x;
}
node a[maxn];
int lowbit(int x){return x&(-x);}
void updata(int x)
{
while(x<=N)
{
d[x]+=1;
x+=lowbit(x);
}
}
int sum(int x)
{
int ans = 0;
while(x)
{
ans+=d[x];
x -= lowbit(x);
}
return ans;
}
int n,m,k;
int main()
{
int t=read();
for(int cas=1;cas<=t;cas++)
{
memset(a,0,sizeof(a));
memset(d,0,sizeof(d));
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=k;i++)
a[i].x=read(),a[i].y=read();
sort(a+1,a+k+1,cmp);
int ans = 0;
for(int i=1;i<=k;i++)
{
ans+=sum(a[i].y-1);
updata(a[i].y);
}
printf("Test case %d: %d\n",cas,ans);
}
}