Problem: There is a grid that consists of W \times H cells. The upper-left-most cell is (1, 1). You are standing on the cell of (1,1) and you are going to move to cell of (W, H). You can only move to adjacent lower-left, lower or lower-right cells.

There are obstructions on several cells. You can not move to it. You cannot move out the grid, either. Write a program that outputs the number of ways to reach (W,H) modulo 1,000,000,009. You can assume that there is no obstruction at (1,1).



Input

The first line contains three integers, the width W, the height H, and the number of obstructions N. (1 \leq W \leq 75, 2 \leq H \leq 10^{18}, 0 \leq N \leq 30) Each of following N lines contains 2 integers, denoting the position of an obstruction (x_i, y_i).

The last test case is followed by a line containing three zeros.

Output

For each test case, print its case number and the number of ways to reach (W,H) modulo 1,000,000,009.

Example

Input

2 4 1
2 1
2 2 1
2 2
0 0 0


Output

Case 1: 4
Case 2: 0

Solution (in CPP):

Solution:
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#define MOD 1000000009LL
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

mat operator*(const mat &A,const mat &B){
	mat C(A.size(),vec(B[0].size()));
	for(int i=0;i<A.size();i++){
		for(int k=0;k<B.size();k++){
			for(int j=0;j<B[0].size();j++){
				C[i][j]=(C[i][j]+A[i][k]*B[k][j]%MOD)%MOD;
			}
		}
	}
	return C;
}

mat pow(mat A,ll n){
	mat B(A.size(),vec(A.size()));
	for(int i=0;i<A.size();i++){
		B[i][i]=1;
	}
	while(n>0){
		if(n&1)B=B*A;
		A=A*A;
		n>>=1;
	}
	return B;
}

int w,n;
ll h;
P o[33];
ll sum[2][80];

ll solve(){
	mat A(w,vec(w));
	for(int i=0;i<w;i++){
		for(int j=0;j<w;j++){
			A[i][j]=0;
		}
	}
	for(int i=0;i<w;i++){
		for(int j=max(0,i-1);j<=min(w-1,i+1);j++){
			A[i][j]=1;
		}
	}
	memset(sum,0,sizeof(sum));
	sum[0][0]=1;
	sort(o,o+n+1);
	ll ny=0;
	int now=1,prev=0;
	for(int i=0;i<=n;i++){
		mat G(w,vec(w));
		G=pow(A,o[i].first-ny);
		ny=o[i].first;
		for(int j=0;j<w;j++){
			for(int k=0;k<w;k++){
				sum[now][j]=(sum[now][j]+sum[prev][k]*G[j][k])%MOD;
			}
		}
		memset(sum[prev],0,sizeof(sum[prev]));
		sum[now][o[i].second]=0;
		swap(now,prev);
	}
	return sum[prev][w-1];
}

int main(void){
	int ca=0;
	while(1){
		ca++;
		scanf("%d%lld%d",&w,&h,&n);
		if(w==0 && h==0 && n==0)break;
		for(int i=0;i<n;i++){
			scanf("%d%lld",&o[i].second,&o[i].first);
			o[i].second--;
			o[i].first--;
		}
		o[n]=P(h-1LL,0);
		printf("Case %d: %lld\n",ca,solve());
	}
	return 0;
}