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 <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

using ll=long long;
using vec=valarray<ll>;
using mat=valarray<vec>;

const ll mod=1000000009;

vec mul(mat a,vec b){
	int m=a.size();
	vec c(0LL,m);
	rep(i,m)rep(j,m){
		c[i]+=1LL*a[i][j]*b[j]%mod;
		c[i]%=mod;
	}
	return c;
}

mat mul(mat a,mat b){
	int m=a.size();
	mat c(vec(0LL,m),m);
	rep(i,m)rep(j,m) rep(k,m){
		c[i][j]+=1LL*a[i][k]*b[k][j]%mod;
		c[i][j]%=mod;
	}
	return c;
}

mat power(mat a,ll n){
	int m=a.size();
	mat b(vec(0LL,m),m);
	rep(i,m) b[i][i]=1;
	while(n){
		if(n&1) b=mul(b,a);
		a=mul(a,a);
		n>>=1;
	}
	return b;
}

int main(void){
	ll w,h,n;
	int T=0;
	while(cin >> w >> h >> n,w){
		map<ll,vector<ll>> obj;
		rep(i,n){
			ll x,y;
			cin >> x >> y;
			obj[y-1].emplace_back(x-1);
		}
		
		mat A(vec(0LL,w),w);
		vec ans(0LL,w); ans[0]=1LL;
	
		rep(i,w){
			if(i-1>=0) A[i][i-1]=1LL;
			A[i][i]=1LL;
			if(i+1<w) A[i][i+1]=1LL;
		}
		
		ll cur=0LL;
		for(auto &it:obj){
			ll y=it.first;
			ans=mul(power(A,y-cur),ans);
			for(auto &x:it.second) ans[x]=0LL;
			cur=y;
		}
		ans=mul(power(A,h-1-cur),ans);
		cout << "Case " << ++T << ": "<< ans[w-1] << endl;
	}
	return 0;
}