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

long long H, W, N, x[100], y[100], ID, mod = 1000000009;
long long pre[64][80][80]; vector<long long>A, P;

void precount() {
	for (int i = 0; i < 64; i++) { for (int j = 0; j < 80; j++) { for (int k = 0; k < 80; k++) pre[i][j][k] = 0; } }
	for (int i = 0; i < H; i++) {
		if (i - 1 >= 0) pre[0][i][i - 1] = 1;
		pre[0][i][i] = 1;
		if (i + 1 < H) pre[0][i][i + 1] = 1;
	}
	for (int t = 0; t < 63; t++) {
		for (int i = 0; i < H; i++) {
			for (int k = 0; k < H; k++) {
				for (int l = 0; l < H; l++) { pre[t + 1][i][l] += pre[t][i][k] * pre[t][k][l]; pre[t + 1][i][l] %= mod; }
			}
		}
	}
}
void solve(long long rep) {
	for (int i = 0; i < 62; i++) {
		if ((rep / (1LL << i)) % 2 == 0) continue;
		vector<long long>B; B.resize(H, 0);
		for (int j = 0; j < H; j++) {
			for (int k = 0; k < H; k++) { B[k] += P[j] * pre[i][j][k]; B[k] %= mod; }
		}
		P = B;
	}
}

int main() {
	while (true) {
		ID++; cin >> H >> W >> N; A.clear(); P.clear(); if (H == 0)break;
		for (int i = 1; i <= N; i++) { cin >> x[i] >> y[i]; x[i]--; A.push_back(y[i]); }
		A.push_back(W); sort(A.begin(), A.end()); A.erase(unique(A.begin(), A.end()), A.end());
		precount();
		P.resize(H, 0); P[0] = 1; long long cx = 1;
		for (int i = 0; i < A.size(); i++) {
			solve(A[i] - cx); cx = A[i];
			for (int j = 1; j <= N; j++) { if (y[j] == A[i]) P[x[j]] = 0; }
		}
		cout << "Case " << ID << ": " << P[H - 1] << endl;
	}
	return 0;
}