#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define F first
#define S second
typedef long long ll;
ll R,C,K;
ll grid[3001][3001];
ll dp[3001][3001];
ll ans ;
int main(){
boost;
ll tt,T,i,j,k;
cin >> T;
for(tt = 1 ; tt <= T ; tt++){
ans = 0;
cin >> R >> C >> K;
memset(grid,0,sizeof(grid));
for(i = 0 ; i <= 3000 ; i++){
for(j = 0 ; j <= 3000 ; j++)
dp[i][j] = 0;
}
for(i = 0 ; i < K ; i++){
ll r,c;
cin >> r >> c;
grid[r][c] = 1;
}
for(i = 0 ; i < C ; i++){
if(grid[0][i] == 0)
dp[0][i] = 1;
else
dp[0][i] = 0;
}
for(i = 1 ; i < R ; i++){
if(grid[i][0] == 0)
dp[i][0] = 1;
else
dp[i][0] = 0;
}
for(i = 1 ; i < R ; i++){
for(j = 1 ; j < C ; j++){
if(grid[i][j] == 0)
dp[i][j] = min(dp[i][j-1],min(dp[i-1][j],dp[i-1][j-1]))+1;
else
dp[i][j] = 0;
}
}
for(i = 0 ; i < R ; i++){
for(j = 0 ; j < C ; j++)
ans += dp[i][j];
}
cout << "Case #" << tt <<": "<<ans << endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBib29zdCBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTtjaW4udGllKDApO2NvdXQudGllKDApCiNkZWZpbmUgRiBmaXJzdAojZGVmaW5lIFMgc2Vjb25kCgoKdHlwZWRlZiBsb25nIGxvbmcgbGw7CmxsIFIsQyxLOwoKbGwgZ3JpZFszMDAxXVszMDAxXTsKbGwgZHBbMzAwMV1bMzAwMV07CgoKbGwgYW5zIDsKCmludCBtYWluKCl7CiAgYm9vc3Q7CgogIGxsIHR0LFQsaSxqLGs7CiAgY2luID4+IFQ7CiAgZm9yKHR0ID0gMSA7IHR0IDw9IFQgOyB0dCsrKXsKICAgIGFucyA9IDA7CiAgICBjaW4gPj4gUiA+PiBDID4+IEs7CiAgICBtZW1zZXQoZ3JpZCwwLHNpemVvZihncmlkKSk7CiAgICBmb3IoaSA9IDAgOyBpIDw9IDMwMDAgOyBpKyspewogICAgICBmb3IoaiA9IDAgOyBqIDw9IDMwMDAgOyBqKyspCiAgICAgICBkcFtpXVtqXSA9IDA7CiAgICB9CgogICAgZm9yKGkgPSAwIDsgaSA8IEsgOyBpKyspewogICAgICBsbCByLGM7CiAgICAgIGNpbiA+PiByID4+IGM7CiAgICAgIGdyaWRbcl1bY10gPSAxOwogICAgfQoKICAgIGZvcihpID0gMCA7IGkgPCBDIDsgaSsrKXsKICAgICAgaWYoZ3JpZFswXVtpXSA9PSAwKQogICAgICAgIGRwWzBdW2ldID0gMTsKICAgICAgZWxzZSAKICAgICAgICBkcFswXVtpXSA9IDA7CiAgICB9CgogICAgZm9yKGkgPSAxIDsgaSA8IFIgOyBpKyspewogICAgICBpZihncmlkW2ldWzBdID09IDApCiAgICAgICAgZHBbaV1bMF0gPSAxOwogICAgICBlbHNlIAogICAgICAgIGRwW2ldWzBdID0gMDsKICAgIH0KCiAgICBmb3IoaSA9IDEgOyBpIDwgUiA7IGkrKyl7CiAgICAgIGZvcihqID0gMSA7IGogPCBDIDsgaisrKXsKICAgICAgICBpZihncmlkW2ldW2pdID09IDApCiAgICAgICAgICBkcFtpXVtqXSA9IG1pbihkcFtpXVtqLTFdLG1pbihkcFtpLTFdW2pdLGRwW2ktMV1bai0xXSkpKzE7CiAgICAgICAgZWxzZSAKICAgICAgICAgIGRwW2ldW2pdID0gMDsKICAgICAgfQogICAgfQogICAgZm9yKGkgPSAwIDsgaSA8IFIgOyBpKyspewogICAgICBmb3IoaiA9IDAgOyBqIDwgQyA7IGorKykKICAgICAgICBhbnMgKz0gZHBbaV1bal07CiAgICB9CgoKICAgIGNvdXQgPDwgIkNhc2UgIyIgPDwgdHQgPDwiOiAiPDxhbnMgPDwgZW5kbDsKICB9Cn0=