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;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1000000009;

using vl = vector<ll>;
using mat = vector<vl>;

mat mul(const mat &A, const mat &B){
    int n = A.size();
    mat C(n,vl(n));
    rep(i,n)rep(j,n)rep(k,n) (C[i][j] += A[i][k]*B[k][j]) %= mod;
    return C;
}

mat mat_pow(const mat &A, ll x){
    int n = A.size();

    mat ret(n,vl(n));
    rep(i,n) ret[i][i] = 1;

    mat P(A);
    while(x){
        if(x&1) ret = mul(ret,P);
        P = mul(P,P);
        x>>=1;
    }
    return ret;
}

vl mul(const mat &A, const vl &b){
    int n = A.size();
    vl ret(n);
    rep(i,n)rep(j,n) (ret[i] += A[i][j]*b[j]) %= mod;
    return ret;
}

int main(){
    int T = 1;
    int w,n;
    ll h;
    while(cin >>w >>h >>n,w){
        map<ll,vector<int>> obj;
        rep(i,n){
            ll x,y;
            cin >>x >>y;
            --x;
            --y;

            if(y>0){
                obj[y].pb(x);
            }



        }

        mat O(w,vl(w));
        rep(i,w){
            for(int j=-1; j<=1; ++j){
                if(0<=i+j && i+j<w) O[i][i+j] = 1;
            }
        }

        mat A(w,vl(w));
        rep(i,w) A[i][i] = 1;

        ll ny = 0;
        for(const auto &p:obj){

            ll Y = p.fi;
            if(Y - ny > 1){
                A = mul(mat_pow(O, Y-ny-1), A);
            }

            mat B(O);
            for(int i:p.se){
                for(int j=-1; j<=1; ++j){
                    if(0<=i+j && i+j<w) B[i][i+j] = 0;
                }
            }

            A = mul(B,A);
            ny = Y;
        }

        if(ny != h-1) A = mul(mat_pow(O, h-1-ny), A);

        vector<ll> b(w);
        b[0]=1;

        vector<ll> res = mul(A,b);
        ll ans = res[w-1];
        printf("Case %d: %lld\n", T++, ans);
    }
    return 0;
}