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;
#define mod (int)(1e9 + 9)
#define fir first
#define sec second
#define all(v) begin(v),end(v)
using i64 = int_fast64_t;

i64 w,h;
vector<pair<i64,int>> obs;
vector<i64> dp;
vector<vector<i64>> mt;

vector<vector<i64>> mul(vector<vector<i64>> &a, vector<vector<i64>> &b) {
    vector<vector<i64>> ret(a.size());
    for(int i=0; i<a.size(); ++i) {
        ret[i].resize(b[0].size());
        for(int j=0; j<b[0].size(); ++j) {
            for(int k=0; k<b.size(); ++k) {
                (ret[i][j]+=(a[i][k]*b[k][j])%mod)%=mod;
            }
        }
    }
    return ret;
}

void calc(i64 y1,i64 y2) {
    vector<i64> nx(w);
    i64 dy=y2-y1;
    assert(dy>=0);
    vector<vector<i64>> now(w);
    for(int i=0; i<w; ++i) {
        now[i].resize(w);
        now[i][i]=1;
    }
    auto tmp=mt;
    while(dy) {
        if(dy&1) {
            now=mul(tmp,now);
        }
        dy>>=1;
        tmp=mul(tmp,tmp);
    }
    for(int i=0; i<w; ++i) {
        for(int j=0; j<w; ++j) {
            (nx[i]+=now[i][j]*dp[j])%=mod;
        }
    }
    dp=nx;
}

void solve() {
    obs.clear();
    dp.clear();
    mt.clear();
    static int casenum=0;
    int n;
    cin>>w>>h>>n;
    if(!w) exit(0);
    dp.resize(w);
    mt.resize(w);
    for(int i=0; i<w; ++i) {
        mt[i].resize(w,0);
        mt[i][i]++;
        if(i) mt[i][i-1]++;
        if(i+1<w) mt[i][i+1]++;
    }
    for(int i=0; i<n; ++i) {
        i64 a,b; cin>>a>>b;
        a--,b--;
        if(b) {
            obs.emplace_back(b,a);
        }
    }
    sort(begin(obs),end(obs));
    i64 lasy=0;
    dp[0]=1;
    for(auto i=obs.begin(); i!=obs.end(); ) {
        vector<int> xs;
        i64 y=i->fir;
        calc(lasy,y);
        while(i!=end(obs) && i->fir==y) {
            dp[i->sec]=0;
            ++i;
        }
        lasy=y;
    }
    calc(lasy,h-1);
    cout<<"Case "<<++casenum<<": "<<dp[w-1]<<endl;
}

signed main() {
    while(1) solve();
}