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 <cstdlib>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;

typedef long long LL;
const int maxn = 75, MOD = 1000000009;

int n, N;
LL m;
map<LL, vector<LL> > s;

class Matrix {
public:
	LL val[maxn][maxn];
	Matrix() {
		memset(val, 0, sizeof(val));
	}

	Matrix operator*(const Matrix& c) const {
		Matrix res;
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				for (int k = 0; k < n; ++k) {
					res.val[i][j] += val[i][k] * c.val[k][j];
					res.val[i][j] = (res.val[i][j] + MOD) % MOD; //髦イ豁「遏ゥ髦オ蜈?エ?序荳コ雍滓焚?瑚凶荳埼怙隕?シ悟悉謗?+MOD"
				}
		return res;
	}

	Matrix& operator*=(const Matrix& c) {
		*this = *this * c;
		return *this;
	}

	Matrix Pow(LL k) { //霑泌屓one^k
		Matrix res = Zero();
		Matrix step = One();
		while (k) {
			if (k & 1)
				res *= step;
			k >>= 1;
			step *= step;
		}
		return res;
	}

	Matrix Zero() const {
		Matrix res;
		for (int i = 0; i < maxn; ++i)
			res.val[i][i] = 1;
		return res;
	}

	Matrix One() const {
		Matrix res;
		res.val[0][0] = res.val[0][1] = 1;
		res.val[n-1][n-1] = res.val[n-1][n-2] = 1;
		for (int i = 1; i < n - 1; ++i) {
			res.val[i][i-1] = res.val[i][i] = res.val[i][i + 1] = 1;
		}
		return res;
	}
};

int main() {
	int kcase = 0;
	while (scanf("%d%lld%d", &n, &m, &N) && n) {
		s.clear();
		for (int i = 0; i < N; ++i) {
			LL x, y;
			scanf("%lld%lld", &x, &y);
			s[--y].push_back(--x);
		}
		if (n == 1) {
			if (N) {
				printf("Case %d: 0\n", ++kcase);
			} else {
				printf("Case %d: 1\n", ++kcase);
			}
			continue;
		}
		Matrix res;
		res.val[0][0] = 1;
		LL now = 0;
		for (map<LL, vector<LL> >::iterator it = s.begin(); it != s.end(); ++it) {
			if (it -> first == 0) continue;
			res *= res.Pow((it -> first) - now);
			now = it -> first;
			for (int i = 0; i < (it -> second).size(); ++i) {
				res.val[0][(it -> second)[i]] = 0;
			}
		}
		res *= res.Pow(m - 1 - now);
		printf("Case %d: %lld\n", ++kcase, res.val[0][n - 1]);
	}
    return 0;
}