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 <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int64;
typedef vector<vector<int64> > matrix;
const int64 mod = 1000000009LL;

matrix mul_matrix(const matrix &a, const matrix &b)
{
	const int l = a[0].size();
	const int m = a.size();
	const int r = b.size();

	matrix ret;

	ret.resize(r);
	for(int i = 0; i < r; ++i)
		ret[i].resize(l);

	for(int i = 0; i < r; ++i) {
		for(int j = 0; j < l; ++j) {
			for(int k = 0; k < m; ++k)
				ret[i][j] = (ret[i][j] + a[k][j] * b[i][k] % mod) % mod;
		}
	}

	return ret;
}

void pow_matrix_b(matrix &a, int64 x)
{
	matrix ret;
	const int n = a.size();

	ret.resize(n);
	for(int i = 0; i < n; ++i) {
		ret[i].resize(n, 0);
		ret[i][i] = 1;
	}

	for(int64 i = 1; i <= x; i *= 2) {
		if(i & x)
			ret = mul_matrix(ret, a);
		a = mul_matrix(a, a);
	}

	a = ret;
}

void fall(vector<int64> &v, int64 len)
{
	const int w = v.size();
	matrix f;

	f.resize(w);
	for(int i = 0; i < w; ++i)
		f[i].resize(w, 0);
	for(int i = 0; i < w; ++i) {
		for(int d = -1; d <= 1; ++d) {
			if(0 <= i + d && i + d < w)
				f[i+d][i] = 1;
		}
	}

	pow_matrix_b(f, len);

	matrix m, ret;

	m.push_back(v);
	ret = mul_matrix(f, m);
	v = ret[0];
}

int main()
{
	int case_count = 1;

	while(true) {

		int64 w, h;
		int n;
		vector<pair<int64, int64> > objs;
		vector<int64> v;
		vector<int64> ys;

		scanf("%lld%lld%d", &w, &h, &n);
		if(w == 0)
			break;
		objs.resize(n);
		for(int i = 0; i < n; ++i) {
			scanf("%lld%lld", &objs[i].first, &objs[i].second);
			objs[i].first -= 1; objs[i].second -= 1;
			ys.push_back(objs[i].second);
		}
		ys.push_back(h - 1);
		sort(ys.begin(), ys.end());
		ys.erase(unique(ys.begin(), ys.end()), ys.end());
		v.resize(w, 0);
		v[0] = 1;

		for(int step = 0; step < ys.size(); ++step) {
			int64 y = ys[step];
			int64 len = step > 0 ? y - ys[step - 1] : y;
			fall(v, len);
			for(int i = 0; i < n; ++i) {
				if(objs[i].second == y)
					v[objs[i].first] = 0;
			}
		}

		int64 ans = v[w - 1];
		printf("Case %d: %lld\n", case_count++, ans);
	}

	return 0;
}