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 <algorithm>

using namespace std;

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
constexpr ll MOD = ((1e9) + 9);

mat mul(const mat& A, const mat& B)
{
    mat C(A.size(), vec(B[0].size()));
    for (int i = 0; i < (int)A.size(); i++) {
        for (int k = 0; k < (int)B.size(); k++) {
            for (int j = 0; j < (int)B[0].size(); j++) {
                C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % MOD) % MOD;
            }
        }
    }
    return C;
}

mat pow(mat A, ll n)
{
    mat B(A.size(), vec(A.size()));
    for (int i = 0; i < (int)A.size(); i++) {
        B[i][i] = 1;
    }
    while (n > 0) {
        if (n & 1) {
            B = mul(B, A);
        }
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

int main()
{
    ll W, H, N, tc = 0;
    while (cin >> W >> H >> N, W) {
        map<ll, vector<ll>> mp;
        for (int i = 0; i < N; i++) {
            ll x, y;
            cin >> x >> y; x--; y--;
            mp[y].emplace_back(x);
        }        

        for (auto& m : mp) {
            auto& v = m.second;
            sort(v.begin(), v.end());
        }
        
        mat A(W, vec(W));
        for (int i = 0; i < W; i++) {
            for (int j = -1; j <= 1; j++) {
                int k = i + j;
                if (0 <= k && k < W) {
                    A[i][k] = 1;
                }
            }
        }
        
        ll curr = 0;
        mat B(W, vec(W, 0)); B[0][0] = 1;
        for (const auto& m : mp) {
            ll next = m.first;
            B = mul(B, pow(A, next - curr));
            for (const auto& x : m.second) {
                B[0][x] = 0;
            }                
            curr = next;
        }

        B = mul(B, pow(A, H - curr - 1));

        if (mp.count(0) > 0 && mp[0][0] == 0) {
            cout << "Case " << ++tc << ": " << 0 << endl;
        } else {            
            cout << "Case " << ++tc << ": " << B[0][W - 1] << endl;
        }
    }        
    return 0;
}