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;

struct I{I(){ios::sync_with_stdio(false);cin.tie(0);}}init;
typedef long long LL;
const LL MOD=1e9+9;
typedef vector<LL> V;
typedef vector<V> M;

LL d[70][100][100];
void pow_init(int n){
    for(int b=1;b<70;b++){
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++){
                d[b][i][j]=0;
                for(int k=0;k<n;k++)
                    d[b][i][j]+=d[b-1][i][k]*d[b-1][k][j]%MOD;
                d[b][i][j]%=MOD;
            }
    }
}
M o(int n){
    return M(n,V(n,0));
}
M e(int n){
    M ret=o(n);
    for(int i=0;i<n;i++)
        ret[i][i]=1;
    return ret;
}
M mul(M a, M b){
    int n=a.size();
    M c=o(n);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++)
                c[i][j]+=a[i][k]*b[k][j]%MOD;
            c[i][j]%=MOD;
        }
    return c;
}
M mul(M a,int m){
    int n=a.size();
    M c=o(n);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++)
                c[i][j]+=a[i][k]*d[m][k][j]%MOD;
            c[i][j]%=MOD;
        }
    return c;
}
M mat_pow(int m,LL n){
    M ret=e(m);
    int i=0;
    while(n){
        if(n&1)ret=mul(ret,i);
        n>>=1;
        i++;
    }
    return ret;
}

V mul(V a,M b){
    int n=a.size();
    V res(n,0);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            res[i]+=a[j]*b[j][i]%MOD;
        res[i]%=MOD;
    }
    return res;
}

LL solve(LL C,LL R,LL N){
    map<LL,vector<LL>> O;
    O[R]=vector<LL>();
    for(LL i=0,r,c;i<N;i++){
        cin>>c>>r;
        O[r].push_back(c-1);
    }
    LL now=1;
    for(int i=0;i<C;i++)
        for(int j=0;j<C;j++)
            d[0][i][j]=0;
    for(int i=0;i<C;i++)
        for(int j=max(0,i-1);j<min((int)C,i+2);j++)
            d[0][i][j]++;
    pow_init(C);
    V res(C,0);
    res[0]=1;
    for(auto &it:O){
        LL nxt=it.first;
        res=mul(res,mat_pow(C,nxt-now));
        for(auto &c:it.second)res[c]=0;
        now=nxt;
    }
    return res[C-1];
}
int main(){
    for(LL i=1,w,h,n;cin>>w>>h>>n,w+h+n;i++){
        cout<<"Case "<<i<<": "<<solve(w,h,n)<<endl;
    }
    return 0;
}