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 <vector>
#include <map>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<ll> Vec;
typedef vector<Vec> Mat;
const ll MOD = 1000000009LL;
Mat mul(const Mat& m1, const Mat& m2){
    int N = m1.size();
    int M = m2[0].size();
    int K = m1[0].size();
    Mat res(N, Vec(M, 0));
    for(int i = 0; i < N; i++){
        for(int k = 0; k < K; k++){
            for(int j = 0; j < M; j++){
                res[i][j] = (res[i][j] + m1[i][k] * m2[k][j]) % MOD;
            }
        }
    }
    return res;
}
Mat pow(Mat m, ll p){
    int N = m.size();
    Mat res(N, Vec(N, 0));
    for(int i = 0; i < N; i++) res[i][i] = 1;
    while(p > 0){
        if(p & 1) res = mul(res, m);
        m = mul(m, m);
        p >>= 1;
    }
    return res;
}
Mat make_mat(ll W, ll H){
    Mat m(W, Vec(W, 0));
    for(int i = 0; i < W; i++){
        for(int j = 0; j < W; j++){
            if(abs(i - j) <= 1) m[i][j] = 1;
        }
    }
    return pow(m, H);
}
Vec mul(const Vec& v, const Mat& m){
    int N = v.size();
    Vec res(N, 0);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            res[j] = (res[j] + v[i] * m[i][j]) % MOD;
        }
    }
    return res;
}
int main(){
    ll W, H, N;
    int casenum = 1;
    while(cin >> W >> H >> N && W){
        map<ll, vector<ll> > obs_dict;
        obs_dict[0] = vector<ll>();
        obs_dict[H - 1] = vector<ll>();
        while(N--){
            ll x, y;
            cin >> x >> y;
            obs_dict[y - 1].push_back(x - 1);
        }
        ll curr = 0;
        Vec v(W, 0);
        v[0] = 1;
        for(auto& kv : obs_dict){
            ll next = kv.first;
            vector<ll>& bad = kv.second;
            v = mul(v, make_mat(W, next - curr));
            for(auto bi : bad) v[bi] = 0;
            curr = next;
        }
        printf("Case %d: %lld\n", casenum++, v[W - 1]);
    }
}