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 <vector>
#include <iostream>
#include <cassert>
#include <map>

using namespace std;
using ll = long long;
constexpr ll MOD = 1000000009LL;

struct Matrix {
    Matrix(const int N) : N(N), table(N, vector<ll>(N, 0LL)) {}
    static Matrix Unit(const int N)
    {
        Matrix ans(N);
        for (int i = 0; i < N; i++) {
            ans.table[i][i] = 1;
        }
        return ans;
    }
    Matrix operator*(const Matrix& mat) const
    {
        assert(mat.N == N);
        Matrix ans(N);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int k = 0; k < N; k++) {
                    (ans.table[i][j] += table[i][k] * mat.table[k][j] % MOD) %= MOD;
                }
            }
        }
        return ans;
    }
    int N;
    vector<vector<ll>> table;
};

Matrix power(const Matrix& mat, const ll n)
{
    if (n == 0) {
        return Matrix::Unit(mat.N);
    }
    if (n % 2 == 1) {
        return mat * power(mat, n - 1);
    } else {
        const Matrix pp = power(mat, n / 2);
        return pp * pp;
    }
}

int main()
{
    int CASE = 0;
    while (true) {
        int W;
        ll H;
        int N;
        cin >> W >> H >> N;
        if (W == 0 and H == 0 and N == 0) {
            break;
        }
        CASE++;
        Matrix usual(W);
        for (int i = 0; i < W; i++) {
            usual.table[i][i] = 1;
            if (i > 0) {
                usual.table[i][i - 1] = 1;
            }
            if (i < W - 1) {
                usual.table[i][i + 1] = 1;
            }
        }
        map<ll, vector<int>> obst;
        for (int i = 0; i < N; i++) {
            int x;
            ll y;
            cin >> x >> y;
            x--, y--;
            obst[y].push_back(x);
        }
        Matrix ans = Matrix::Unit(W);
        ll previous = 0;
        for (const auto& v : obst) {
            const ll h = v.first;
            Matrix unusual = usual;
            for (const int x : v.second) {
                unusual.table[x][x] = 0;
                if (x > 0) {
                    unusual.table[x - 1][x] = 0;
                }
                if (x < W - 1) {
                    unusual.table[x + 1][x] = 0;
                }
            }
            ans = (h - previous > 0 ? ans * power(usual, h - previous - 1) : ans) * unusual;
            previous = h;
        }
        ans = (ans * power(usual, H - previous - 1));
        cout << "Case " << CASE << ": " << ans.table[0][W - 1] << endl;
    }

    return 0;
}