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 <cstdio>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstring>
using namespace std;
#define MOD 1000000009
struct Matrix{
    long long n;

    Matrix(){
        memset(m,0,sizeof m);
    };
    long long m[80][80];
    Matrix operator * (const Matrix &b) const{
        Matrix c;
        for (long long i=0;i<n;i++)
        for (long long j=0;j<n;j++){
            c.m[i][j]=0;
            for (long long k=0;k<n;k++)
                c.m[i][j]=(c.m[i][j]+(m[i][k]*b.m[k][j])%MOD)%MOD;
        }
        c.n=n;
        return c;
    }
};
Matrix ones;
Matrix Pow(const Matrix &a,long long n){
    Matrix t=ones,y=a;
    while (n){
        if (n & 1) t = (t * y) ;
        y = (y * y) ;
        n /= 2;
    }
    return t;
}
struct node{
    long long a,b;
}Pos[80];
bool cmp(node a,node b){
    return a.b<b.b;
}
Matrix A,B;
long long x[80];
void get_x(Matrix A){
    long long y[80];
    //printf("!!!");
    memset(y,0,sizeof y);
    for (long long i=0;i<A.n;i++){
        for (long long j=0;j<A.n;j++){
            y[i]=(y[i]+(x[j]*A.m[i][j])%MOD)%MOD;
        }
    }
    for (long long i=0;i<A.n;i++)
        x[i]=y[i];
}
long long sum;
long long w,n;
long long h;
long long k,p,q;
int main(){
    int i,j;
    int d=0;
    while (scanf("%lld%lld%lld",&w,&h,&n),w||h||n){
        memset(ones.m,0,sizeof ones.m);
        ones.n=w;
        for (i=0;i<w;i++)
            ones.m[i][i]=1;
        for (i=0;i<n;i++){
            scanf("%lld%lld",&Pos[i].a,&Pos[i].b);
            //Pos[i].a--;Pos[i].b--;
        }
        sort(Pos,Pos+n,cmp);

        memset(x,0,sizeof x);
        x[0]=1;
        memset(A.m,0,sizeof A.m);

        A.n=w;
        A.m[0][0]=1; A.m[0][1]=1;
        for (i=1;i<w;i++){
            A.m[i][i-1]=1;
            A.m[i][i]=1;
            A.m[i][i+1]=1;
        }
        //for (i=0;i<w;i++)
        //    x[i]=0;//蛻怜髄驥?        
        k=0;
        j=0;
        //k=0;
        //j=0;
        /*
        sort(Pos,Pos+n,cmp);
        //if ((w==0)&&(h==0)&&(n==0)) return 0;
        memset(x,0,sizeof x);
        x[0]=1;
        memset(A.m,0,sizeof A.m);

        A.n=w;
        A.m[0][0]=1;
        A.m[0][1]=1;
        for (i=1;i<w;i++){
            A.m[i][i]=1;
            A.m[i][i-1]=1;
            A.m[i][i+1]=1;
        }
        k=0;
        j=0;
        */

        // ****************************************
        /*
        int i,j;
    int d=0;
    while (scanf("%lld%lld%lld",&w,&h,&n),w||h||n){
        memset(ones.m,0,sizeof ones.m);
        for (i=0;i<w;i++)
            ones.m[i][i]=1;
        ones.n=w;
        for (i=0;i<n;i++)
            scanf("%lld%lld",&Pos[i].a,&Pos[i].b);
        sort(Pos,Pos+n,cmp);
        //if ((w==0)&&(h==0)&&(n==0)) return 0;
        memset(x,0,sizeof x);
        x[0]=1;
        memset(A.m,0,sizeof A.m);
        A.n=w;
        A.m[0][0]=1;
        A.m[0][1]=1;
        for (i=1;i<w;i++){
            A.m[i][i]=1;
            A.m[i][i-1]=1;
            A.m[i][i+1]=1;
        }
        k=0;
        j=0;
        */
        //****************************************
        //printf("!!!");
        while (j<n){
            p=Pos[j].b-1;
            if (k==p){
                x[Pos[j].a-1]=0;
            }
            else{
                get_x(Pow(A,p-k));
                k=p;
                x[Pos[j].a-1]=0;
            }
            //printf("%d",k);
            //for (int i=0;i<w;i++)
            //    printf("%5d",x[i]);
            //printf("\n");
            j++;

        }
        //printf("!!!");
        if (k<h-1){

//            B=Pow(A,h-1-k);printf("#!!!");
            get_x(Pow(A,h-1-k));
        }
        printf("Case %lld: %lld\n",++d,(x[w-1]%MOD+MOD)%MOD);
    }
}