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>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;


ll M=1e9+9;
ll dp[100][100][100];


int main(){
  ll w,h,n;
  ll T=1;

  while(cin>>w>>h>>n,w){

    vector<P> v;
    for(ll x,y,i=0;i<n;i++){

      cin>>x>>y;
      v.push_back(P(y-1,x-1));
      
    }
    
    sort(v.begin(),v.end());
    ll bt=0;

    memset(dp,0,sizeof(dp));
    
    for(ll i=0;i<w;i++)
      for(ll j=max(0LL,i-1);j<=min(w-1,i+1);j++)
	dp[0][i][j]=1;
  
    h--;

    while((1LL<<bt)<=h){
 
      for(ll i=0;i<w;i++)
	for(ll j=0;j<w;j++)
	  for(ll k=0;k<w;k++)
	    dp[bt+1][j][k]=(dp[bt][j][i]*dp[bt][i][k]+dp[bt+1][j][k])%M;
      
      bt++;
    }

    ll pr=0;

    v.push_back(P(h,-1));

    ll ans[100]={};

    ans[0]=1;
    
    for(ll p=0;p<=n;p++){
      bt=0;
      ll nh=v[p].first-pr;
      pr=v[p].first;
      while((1LL<<bt)<=nh){
	if((1LL<<bt)&nh){
	  ll tmp[100]={};
	  
	  for(ll i=0;i<w;i++)
	    for(ll j=0;j<w;j++)
	      tmp[j]=(tmp[j]+ans[i]*dp[bt][i][j])%M;
	  
	  for(ll i=0;i<w;i++)ans[i]=tmp[i];
	  
	}
	bt++;
      }

      ll yy=v[p].first;

      while(p<=n&&v[p].first==yy){
	if(v[p].second!=-1)ans[v[p].second]=0;
	p++;
      }
      
      p--;
      
    }
    cout<<"Case "<<T++<<": ";
    cout<<ans[w-1]<<endl;

  }



  return 0;
}