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;
constexpr int MOD = 1e9 + 9;
using matrix = vector<vector<ll>>;

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

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

vector<ll> prod(const matrix &a, const vector<ll> &x)
{
    vector<ll> ret(w, 0);
    for (int i = 0; i < w; i++)
    {
        for (int j = 0; j < w; j++)
        {
            ret[i] += a[i][j] * x[j] % MOD;
            ret[i] %= MOD;
        }
    }
    return ret;
}

matrix modmul(matrix const &l, matrix const &r)
{
    matrix ret(l.size(), vector<ll>(r[0].size()));
    for (int i = 0; i < l.size(); i++)
    {
        for (int k = 0; k < r.size(); k++)
        {
            for (int j = 0; j < r[0].size(); j++)
            {
                ret[i][j] += l[i][k] * r[k][j] % MOD;
                ret[i][j] %= MOD;
            }
        }
    }
    return ret;
}

matrix modpow(matrix x, ll n)
{
    matrix ret(x.size(), vector<ll>(x.size(), 0));
    for (int i = 0; i < x.size(); i++)
        ret[i][i] = 1;
    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 = prod(modpow(id, v - pre), x);
            for (auto y : mp[v])
                x[y] = 0;
            pre = v;
        }
        cout << x[w - 1] << endl;
    }
}