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 <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000009LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

#define MN 75

int N_;
ll A[MN][MN];
ll B[MN][MN];
ll work[MN][MN];

const ll LIM=LLONG_MAX-(MOD-1)*(MOD-1);

// a := a*b
void matmul(ll a[][MN], ll b[][MN]){
	memset(work,0,sizeof(work));
	rep(i,N_)rep(k,N_)rep(j,N_){
		work[i][j]+=a[i][k]*b[k][j];
		if(work[i][j]>LIM)work[i][j]%=MOD;
	}
	rep(i,N_)rep(j,N_)a[i][j]=work[i][j]%MOD;
}

// a := b*a
void matmulleft(ll a[][MN], ll b[][MN]){
	memset(work,0,sizeof(work));
	rep(i,N_)rep(k,N_)rep(j,N_){
		work[i][j]+=b[i][k]*a[k][j];
		if(work[i][j]>LIM)work[i][j]%=MOD;
	}
	rep(i,N_)rep(j,N_)a[i][j]=work[i][j]%MOD;
}

// a := a^2
void matsq(ll a[][MN]){
	memset(work,0,sizeof(work));
	rep(i,N_)rep(k,N_)rep(j,N_){
		work[i][j]+=a[i][k]*a[k][j];
		if(work[i][j]>LIM)work[i][j]%=MOD;
	}
	rep(i,N_)rep(j,N_)a[i][j]=work[i][j]%MOD;
}

// A := A^n
void matpow(ll a[][MN],ll n){
	memset(B,0,sizeof(B));
	rep(i,N_)B[i][i]=1;
	while(n){
		if(n&1)matmul(B,A);
		matsq(A);
		n>>=1;
	}
	rep(i,N_)rep(j,N_)A[i][j]=B[i][j];
}

ll W,H,n;
map<ll,vi> M;
ll ans[MN][MN];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	int caseno=1;
	while(cin>>W>>H>>n && W){
		N_=W;
		M.clear();
		rep(i,n){
			ll x,y;
			cin>>x>>y;
			x--;y--;
			if(y==0)continue;
			if(M.find(y)==M.end()){
				M[y]=vi(W,1);
			}
			M[y][x]=0;
		}
		M[H]=vi();
		memset(ans,0,sizeof(ans));
		rep(i,W)ans[i][i]=1;
		ll pre=0;
		foreach(it,M){
			ll y=it->fir;
			rep(i,W)rep(j,W){
				A[i][j]=abs(i-j)<=1;
			}
			matpow(A,y-pre-1);
			matmulleft(ans,A);
			if(it->fir==H)continue;
			rep(i,W)rep(j,W){
				A[i][j]=it->sec[i] && abs(i-j)<=1;
			}
			matmulleft(ans,A);
			pre=it->fir;
		}
		cout<<"Case "<<caseno++<<": "<<ans[W-1][0]<<endl;
	}
}