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;
ll W,H,N;

typedef vector<ll> Vec;
typedef vector<Vec> Mat;
const ll MOD = 1000000009;

void add( ll &a, ll b ){
  a+=b;
  a%=MOD;
}

void view( const Mat& a ){
  cout << "view"<<endl;
  for(int i=0;i<a.size();i++ ){
    for(int j=0;j<a[i].size();j++) cout << a[i][j] << " ";
    cout << endl;
  }
}

Mat mult( const Mat& a, const Mat& b ){
  Mat res=Mat(a.size(), Vec(b[0].size(),0) );
  for(int i=0;i<(int)res.size();i++){
    for(int j=0;j<(int)res[i].size();j++){
      for(int k=0;k<(int)a[0].size();k++){
        add( res[i][j], (a[i][k] * b[k][j])%MOD );
      }
    }
  }
  return res;
}

// a * b^k
Mat pow_m( const Mat &a,const Mat& b,ll k ){
  Mat res = a;
  Mat x = b;
  while( k ){    
    if( k & 1 ){
      res = mult( res, x );
    }    
    x = mult( x, x );
    k>>=1;
  }
  return res;
}

ll X[100],Y[100];
ll fie[400];

Mat get_mat(int y){
  Mat ret=Mat(W,Vec(W,0));
  for(int j=0;j<W;j++)
    for(int i=max(0,j-1);i<min(j+2,(int)W);i++)
      ret[i][j] = 1;  
  if( y == -1 ) return ret;
  for(int i=0;i<N;i++){
    if( (int)Y[i] == y ){
      for(int j=0;j<W;j++)
        ret[j][X[i]]=0;
    }
  }
  return ret;
}

Mat solve(int h){
  Mat res = Mat(1,Vec(W,0));
  res[0][0] = 1;
  ll now_y=1;
  for(int i=0;i<h;i++){
    if( fie[i] <= 1 ) continue;    
    ll t=fie[i]-now_y;
    Mat next = get_mat( i );
    res = pow_m( res, next, t );
    now_y = fie[i];
  }
  return res;
}


int zatu(){
  vector<ll> v;
  v.push_back(1);
  v.push_back(H);
  for(int i=0;i<N;i++)
    for(int j=-1;j<1;j++)
      v.push_back( Y[i]+j );
  sort(v.begin(),v.end());
  v.erase( unique( v.begin(), v.end() ), v.end() );
  for(int i=0;i<(int)v.size();i++)
    fie[i] = v[i];    
  for(int i=0;i<N;i++)
    Y[i] = lower_bound( v.begin(), v.end() , Y[i] ) - v.begin();
  return v.size();
}


int main(){
  while( cin >> W >> H >> N && (W||H||N) ) {
    static int ttt=1;
    cout << "Case " << ttt++ << ": ";
    bool f = false;
    for(int i=0;i<N;i++){
      cin >> X[i] >> Y[i]; --X[i];
      if( X[i] == 0 && Y[i] == 1 ) f = true;
    }
    if( f ){
      cout << 0 << endl; break;
    }
    int h = zatu();
    Mat ans = solve( h );
    cout << ans[0][W-1] << endl;
  }  
}