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;

using ll = long long;

ll h, w, n;
int cs = 1;

template <typename T>
using matrix = std::vector<std::vector<T>>;

constexpr long long mod = 1e9+9;

template <typename T>
matrix<T> modmul(const matrix<T> &l, const matrix<T> &r)
{
    matrix<T> ret(l.size(), std::vector<T>(r[0].size()));
    for (int i = 0; i < (int)l.size(); i++)
    {
        for (int k = 0; k < (int)r.size(); k++)
        {
            for (int j = 0; j < (int)r[0].size(); j++)
            {
                ret[i][j] += l[i][k] * r[k][j] % mod;
                ret[i][j] %= mod;
            }
        }
    }
    return ret;
}

template <typename T>
std::vector<T> modmul(const matrix<T> &a, const std::vector<T> &x)
{
    const int n = a.size();
    const int m = x.size();
    std::vector<T> ret(n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            ret[i] += a[i][j] * x[j] % mod;
            ret[i] %= mod;
        }
    }
    return ret;
}

template <typename T>
matrix<T> eye(const int n)
{
    matrix<T> ret(n, std::vector<T>(n));
    for (int i = 0; i < n; i++)
        ret[i][i] = 1;
    return ret;
}

template <typename T>
matrix<T> modpow(matrix<T> x, long long n)
{
    auto ret = eye<T>(x.size());
    while (n)
    {
        if (n & 1)
            ret = modmul(ret, x);
        x = modmul(x, x);
        n /= 2;
    }
    return ret;
}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    while (cin >> w >> h >> n, h || w || n)
    {
        cout << "Case " << cs << ": ";
        cs++;
        bool f = false;
        set<ll> st = {h};
        map<ll, vector<ll>> mp;
        for (int i = 0; i < n; i++)
        {
            ll x, y;
            cin >> y >> x;
            if (x == 1)
                continue;
            st.insert(x);
            y--;
            mp[x].push_back(y);
            if (x == h && y == w)
            {
                f = true;
            }
        }
        if (f)
        {
            cout << 0 << endl;
            continue;
        }
        vector<vector<ll>> id(w, vector<ll>(w, 0));
        for (int i = 0; i < w; i++)
        {
            id[i][i] = 1;
            if (i)
                id[i][i - 1] = 1;
            if (i + 1 < w)
                id[i][i + 1] = 1;
        }
        vector<ll> x(w, 0);
        x[0] = 1;
        ll pre = 1;
        for (auto v : st)
        {
            x = modmul(modpow(id, v - pre), x);
            for (auto y : mp[v])
                x[y] = 0;
            pre = v;
        }
        cout << x[w - 1] << endl;
    }
}