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;
using ll=long long;
using vl=vector<ll>;
using Mat=vector<vl>;
const ll MOD=1e9+9;



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

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

ll solve(int w,ll h,int n){
    vector<Mat> cals;
    cals.resize(64,Mat(w,vl(w)));
    for(int j=0;j<w;j++){
        for(int k=0;k<w;k++){
            cals[0][j][k]=(abs(k-j)<=1);
        }
    }
    for(int j=0;j+1<cals.size();j++){
        cals[j+1]=cross(cals[j],cals[j]);
    }

    set<pair<int,int>> ob;
    set<ll> hs;
    for(int i=0;i<n;i++){
        int x;
        ll y;
        cin>>x>>y;
        x--,y--;
        hs.insert(y);
        ob.insert({x,y});
    }
    hs.insert(0);
    hs.insert(h-1);
    vector<ll> hv(hs.begin(),hs.end());
    vector<vector<ll>> dp(hv.size(),vector<ll>(w,0));
    dp[0][0]=1;
    for(int i=1;i<hv.size();i++){
        ll dist=hv[i]-hv[i-1];
        vector<ll> next=dp[i-1];
        for(int j=0;j<64 && dist;j++){
            if(dist%2) next=cross(cals[j],next);
            dist/=2;
        }
        for(int j=0;j<w;j++){
            if(!ob.count({j,hv[i]})) dp[i][j]=next[j];
        }
    }
    return dp[hv.size()-1][w-1];
}

int main(){
    int w,n;
    ll h;
    int i=0;
    while(cin>>w>>h>>n,w){
        i++;
        cout<<"Case "<<i<<": "<<solve(w,h,n)<<endl;
    }
    return 0;
}