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;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000009;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator >(const Edge& e) const { return cost > e.cost; }
};

/*--------------------template--------------------*/
#define array Array
#define matrix Matrix
typedef ll number;
typedef vector<number> array;
typedef vector<array> matrix;

// O( n )
matrix ident(int n) {
	matrix A(n, array(n));
	for (int i = 0; i < n; ++i) A[i][i] = 1;
	return A;
}
// O( n )
number inner_product(const array &a, const array &b) {
	number ans = 0;
	for (int i = 0; i < a.size(); ++i)
		ans += (a[i] * b[i]) % MOD;
	return ans;
}
// O( n^2 )
array mul(const matrix &A, const array &x) {
	array y(A.size());
	for (int i = 0; i < A.size(); ++i)
		for (int j = 0; j < A[0].size(); ++j)
		{
			y[i] += A[i][j] * x[j];
			y[i] %= MOD;
		}
	return y;
}
// O( n^3 )
matrix mul(const matrix &A, const matrix &B) {
	matrix C(A.size(), array(B[0].size()));
	for (int i = 0; i < C.size(); ++i)
		for (int j = 0; j < C[i].size(); ++j)
			for (int k = 0; k < A[i].size(); ++k)
			{
				C[i][j] += A[i][k] * B[k][j];
				C[i][j] %= MOD;
			}
	return C;
}
// O( n^3 log e )
matrix pow(const matrix &A, ll e) {
	return e == 0 ? ident(A.size()) :
		e % 2 == 0 ? pow(mul(A, A), e / 2) : mul(A, pow(A, e - 1));
}
int main()
{
	ll w, h, n;
	for (int cs = 0; cin >> w >> h >> n&&w; cs++)
	{
		vector<pair<ll,ll>> v;
		REP(i, n)
		{
			ll x, y; cin >> x >> y;
			x--; y--;
			if (y == 0) continue;
			v.emplace_back(y, x);
		}
		n = v.size();
		sort(ALL(v));
		Array ary(w); ary[0] = 1;
		Matrix mat(w, Array(w));
		REP(i, w)REP(j, w)
		{
			if (abs(i - j) <= 1) mat[i][j] = 1;
		}
		ll tmp = 0, p = 0;
		while (1)
		{
			ll next;
			if (p < n) next = v[p].first;
			else next = h;
			ary = mul(pow(mat, (next - tmp - 1)), ary);
			if (next == h) break;
			vi obj; obj.push_back(v[p].second);
			p++;
			while (p < n && v[p].first == v[p-1].first)
			{
				obj.push_back(v[p].second);
				p++;
			}
			Array zero(w);
			Matrix objmat = mat;
			REP(i, obj.size()) objmat[obj[i]] = zero;
			ary = mul(objmat, ary);
			tmp = next;
		}
		cout << "Case " << cs+1 << ": " << ary.back() << endl;
	}
	return 0;
}