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<iostream>
#include<set>
#include<vector>
#include<map>

using namespace std;

typedef vector<vector<int> > Mat;

long long W,H,N;

Mat operator*(const Mat &a,const Mat &b){
  Mat m(W,vector<int>(W));
  for(int i=0;i<W;i++){
    for(int j=0;j<W;j++){
      for(int k=0;k<W;k++){
	m[i][j]=(m[i][j]+a[i][k]*1LL*b[k][j])%1000000009;
      }
    }
  }
  return m;
}

Mat bm(const set<int> &s=set<int>()){
  Mat m(W,vector<int>(W));
  for(int i=0;i<W;i++){
    if(s.count(i)==0){
      for(int j=-1;j<=1;j++){
	int x=i+j;
	if(0<=x&&x<W){
	  m[i][x]=1;
	}
      }
    }
  }
  return m;
}

Mat pm(const Mat &m,long long p){
  if(p==0){
    Mat m(W,vector<int>(W));
    for(int i=0;i<W;i++){
      m[i][i]=1;
    }
    return m;
  }else{
    auto r=pm(m*m,p>>1);
    if(p%2){
      r=r*m;
    }
    return r;
  }
}

int main(){
  for(int t=1;cin>>W>>H>>N,W;t++){
    map<long long,set<int> > m;
    while(N--){
      long long x,y;
      cin>>x>>y;
      if(y>1){
	m[y-1].insert(x-1);
      }
    }
    vector<Mat> v;
    long long l=0;
    for(auto e:m){
      v.push_back(pm(bm(),e.first-l-1));
      v.push_back(bm(e.second));
      l=e.first;
    }
    v.push_back(pm(bm(),H-l-1));
    auto am=pm(bm(),0);
    for(int i=v.size()-1;i>=0;i--){
      am=am*v[i];
    }
    cout<<"Case "<<t<<": "<<am[W-1][0]<<endl;
  }
}