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 <algorithm>
#include <cmath>
#include <utility>
#define llint long long
#define mod 1000000009

using namespace std;

llint W, H, N;
pair<llint, llint> p[35];

void getmatE(llint A[80][80])
{
	for(int i = 0; i < W; i++){
		for(int j = 0; j < W; j++){
			A[i][j] = (i == j);
		}
	}
}

void matcopy(llint A[80][80], llint B[80][80])
{
	for(int i = 0; i < W; i++){
		for(int j = 0; j < W; j++){
			B[i][j] = A[i][j];
		}
	}
}

void matmul(llint A[80][80], llint B[80][80], llint C[80][80])
{
	llint tmp[80][80];
	for(int i = 0; i < W; i++){
		for(int j = 0; j < W; j++){
			tmp[i][j] = 0;
		}
	}
	
	for(int i = 0; i < W; i++){
		for(int k = 0; k < W; k++){
			if(A[i][k] == 0) continue;
			for(int j = 0; j < W; j++){
				tmp[i][j] += (A[i][k] * B[k][j]) % mod;
				tmp[i][j] %= mod;
			}
		}
	}
	matcopy(tmp, C);
}

void matpow(llint A[80][80], llint n, llint B[80][80])
{
	if(n == 0){
		getmatE(B);
		return;
	}
	if(n % 2){
		matpow(A, n-1, B);
		matmul(B, A, B);
	}
	else{
		matpow(A, n/2, B);
		matmul(B, B, B);
	}
}

void matvec(llint A[80][80], llint v[80], llint vd[80])
{
	llint tmp[80];
	for(int i = 0; i < W; i++){
		llint sum = 0;
		for(int j = 0; j < W; j++){
			sum += (A[i][j] * v[j]) % mod;
			sum %= mod;
		}
		tmp[i] = sum;
	}
	for(int i = 0; i < W; i++) vd[i] = tmp[i];
}

int main(void)
{
	for(int c = 1; ; c++){
		cin >> W >> H >> N;
		if(W == 0 && H == 0 && N == 0) break;
		for(int i = 0; i < N; i++){
			cin >> p[i].second >> p[i].first;
			p[i].second--, p[i].first--;
		}
		sort(p, p+N);
		
		llint transmat[80][80];
		for(int i = 0; i < W; i++){
			for(int j = 0; j < W; j++){
				if(abs(i-j) <= 1) transmat[i][j] = 1;
				else transmat[i][j] = 0;
			}
		}
		llint vec[80];
		for(int i = 0; i < W; i++) vec[i] = 0;
		vec[0] = 1;
		
		llint dy, prev_y = 0, mat[80][80];
		for(int i = 0; i < N; i++){
			dy = p[i].first - prev_y;
			matpow(transmat, dy, mat);
			matvec(mat, vec, vec);
			
			prev_y = p[i].first;
			while(i < N && p[i].first == prev_y){
				vec[p[i].second] = 0;
				i++;
			}
			i--;
		}
		
		matpow(transmat, (H-1)-prev_y, mat);
		matvec(mat, vec, vec);
		
		cout << "Case " << c << ": " << vec[W-1] << endl;
	}
	
	return 0;
}