// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define patkan 9
#define tisic 47
#define soclose 10e-7
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):(x))
// mylittlepony
using namespace std;
int main() {
// freopen("rooks.in","r",stdin);
int T;
scanf(" %d",&T);
for(int t =0; t < T; t++) {
int N,M,K,a,b;
scanf(" %d %d %d",&N,&M,&K);
set<int> X,Y;
for(int i =0; i < K; i++) {
scanf(" %d %d",&a,&b);
X.insert(a);
Y.insert(b);}
int A =X.size(), B =Y.size();
if(A < B) {
swap(N,M);
swap(A,B);}
long long mod =1000000007;
vector< vector<long long> > C(A+1,vector<long long>(B+1,0));
C[0][B] =1;
for(int i =1; i <= A; i++) for(int j =0; j <= B; j++) {
if(j < B) C[i][j] =(C[i-1][j]*(M-j)+C[i-1][j+1]*(j+1))%mod;
else C[i][j] =(C[i-1][j]*(M-B))%mod;
if(C[i][j] < 0) C[i][j] +=mod;}
printf("Case %d: %d %lld\n",t+1,A,C[A][0]);}
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMgdG9vIG1haW5zdHJlYW0KI2luY2x1ZGUgPGNzdGRpbz4KLy8gYml0Y2ggcGxlYXNlCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpb21hbmlwPgojZGVmaW5lIGRpYnMgcmVzZXJ2ZQojZGVmaW5lIE9WRVI5MDAw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