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 <algorithm>
#include <map>
#include <vector>
using namespace std;
using ll = long long int;
using Matrix = vector< vector<ll> >;
const ll MOD = 1000000009;

Matrix mul(const Matrix &A, const Matrix &B) {
    int H = A.size(), W = B[0].size(), C = B.size();
    Matrix res(H, vector<ll>(W));
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            for(int k=0; k<C; k++) {
                (res[i][j] += A[i][k] * B[k][j] % MOD) %= MOD;
            }
        }
    }
    return res;
}

Matrix pow(Matrix A, ll k) {
    int N = A.size();
    Matrix res(N, vector<ll>(N));
    for(int i=0; i<N; i++) res[i][i] = 1;

    for(; k>0; k>>=1) {
        if(k & 1) res = mul(res, A);
        A = mul(A, A);
    }
    return res;
}

int solve_testcase(int case_num) {
    ll W, H, N; cin >> W >> H >> N;
    if(W == 0) return 1;
    
    map< ll, vector<int> > rows;
    for(int i=0; i<N; i++) {
        ll r, c; cin >> c >> r; r--; c--;
        rows[r].emplace_back(c);
    }
    rows[0], rows[H-1];

    Matrix A(W, vector<ll>(W));
    for(int i=0; i<W; i++) {
        for(int dx=-1; dx<=1; dx++) {
            int ni = i + dx;
            if(ni < 0 or ni >= W) continue;
            A[i][ni] = 1;
        }
    }

    Matrix vec(W, vector<ll>(1)); vec[0][0] = 1;
    for(auto itr=rows.begin(); next(itr)!=rows.end(); itr++) {
        ll r1 = itr->first, r2 = next(itr)->first;

        // r2 - r1 - 1 分だけ進める
        Matrix P = pow(A, r2 - r1 - 1);
        vec = mul(P, vec);

        // r2 に移動
        vector<bool> ok(W, true);
        auto& cols = next(itr)->second;
        for(auto w : cols) ok[w] = false;

        Matrix nvec(W, vector<ll>(1));
        for(int i=0; i<W; i++) {
            for(int dx=-1; dx<=1; dx++) {
                int ni = i + dx;
                if(ni < 0 or ni >= W or !ok[ni]) continue;
                (nvec[ni][0] += vec[i][0]) %= MOD;
            }
        }
        swap(vec, nvec);
    }

    cout << "Case " << case_num << ": " << vec[W-1][0] << endl;
    return 0;
}

int main() {
    int case_num = 0;
    while(!solve_testcase(++case_num));
    return 0;
}