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;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

typedef vector<ll> Row;
typedef vector<Row> Matrix;

const ll mod = 1e9+9;

ll add(ll a, ll b) {
    return (a + b) % mod;
}
ll mul(ll a, ll b) {
    return a * b % mod;
}
Matrix mul(Matrix A, Matrix B) {
    Matrix res(A.size(), Row(B[0].size(), 0));
    REP(i, res.size()) REP(j, res[i].size()) REP(k, B.size()) {
        res[i][j] = add(res[i][j], mul(A[i][k], B[k][j]));
    }
    return res;
}
Row mul(Matrix A, Row B) {
    Row res(B.size(), 0);
    REP(i, res.size()) REP(j, A[i].size()) {
        res[i] = add(res[i], mul(A[i][j], B[j]));
    }
    return res;
}
Matrix power(Matrix A, ll n) {
    Matrix res(A.size(), Row(A.size(), 0));
    REP(i, res.size()) res[i][i] = 1;
    for (ll i = 1; i <= n; i <<= 1) {
        if (i & n) res = mul(res, A);
        A = mul(A, A);
    }
    return res;
}

Row dp(const Row& prev, const Row& m) {
    int W = prev.size();
    Row res(W, 0);
    REP(i, W) {
        if (m[i] == 0) {
            if (i > 0) res[i] = add(res[i], prev[i-1]);
            res[i] = add(res[i], prev[i]);
            if (i < W-1) res[i] = add(res[i], prev[i+1]);
        }
    }
    return res;
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll W, H, N;
    int id = 1;
    while (cin >> W >> H >> N, W || H || N) {
        map<ll, Row> m;
        REP(i, N) {
            ll x, y; cin >> x >> y; --y, --x;
            if (y == 0) continue;
            if (m.count(y) == 0) m[y].assign(W, 0);
            m[y][x] = 1;
        }
        Matrix A(W, Row(W, 0));
        REP(i, W) {
            REP(j, W) {
                if ( abs(i - j) <= 1 ) A[i][j] = 1;
            }
        }
        ll pos = 0;
        Row v(W, 0); v[0] = 1;
        EACH(p, m) {
            ll ny = p.first;
            if (pos < ny-1) {
                v = mul(power(A, ny-1-pos), v);
            }
            v = dp(v, p.second);
            pos = ny;
        }
        v = mul(power(A, H-1-pos), v);
        cout << "Case " << id++ << ": " << v[W-1] << endl;
    }
}