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>
#include <utility>
#include <climits>
using namespace std;
 
#define MOD 1000000009LL
 
typedef long long LL;
typedef pair<LL,LL> pLL;
typedef vector<LL> vLL;
typedef vector<vLL> vvLL;
 
vvLL make(int n){
	return vvLL(n, vLL(n));
}
 
void mulmm(vvLL &x, const vvLL &y){
	int n = x.size();
	vvLL z = make(n);
	for(int i = 0; i < n; ++i)
	for(int j = 0; j < n; ++j)
	for(int k = 0; k < n; ++k){
		z[i][j] = (z[i][j] + x[i][k] * y[k][j]) % MOD;
	}
	x.swap(z);
}

void mulvm(vLL &x, const vvLL &y){
	int n = x.size();
	vLL z(n);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			z[i] = (z[i] + x[j] * y[j][i]) % MOD;
		}
	}
	x.swap(z);
}

void powm(vvLL &x, LL y){
	int n = x.size();
	vvLL z = make(n);
	for(int i = 0; i < n; ++i){
		z[i][i] = 1;
	}
	while(y){
		if(y & 1){ mulmm(z, x); }
		mulmm(x, x);
		y >>= 1;
	}
	z.swap(x);
}
 
int main(){
	LL w, h, n;
	int T = 0;
	while(scanf("%lld%lld%lld", &w, &h, &n), w){
		vector<pLL> v(n + 1);
		vLL ys;
		LL x, y;
		for(int i = 0; i < n; ++i){
			scanf("%lld%lld", &x, &y);
			v[i] = pLL(y, x);
			if(y > 1 && y < h){
				ys.push_back(y);
			}
		}
		v[n] = pLL(LLONG_MAX, LLONG_MAX);
		sort(v.begin(), v.end());
		ys.push_back(1);
		ys.push_back(h);
		sort(ys.begin(), ys.end());
		ys.erase(unique(ys.begin(), ys.end()), ys.end());
		vvLL s = make(w);
		for(int i = 0; i < w; ++i){
			s[i][i] = 1;
			if(i != 0){ s[i][i - 1] = 1; }
			if(i != w - 1){ s[i][i + 1] = 1; }
		}
		vLL a(w);
		a[0] = 1;

		int k = 0;
		while(v[k].first <= 1){ ++k; }
		for(int i = 1; i < ys.size(); ++i){
			vvLL b = s;
			powm(b, ys[i] - ys[i - 1]);
			mulvm(a, b);

			while(v[k].first == ys[i]){
				x = v[k].second - 1;
				if(x >= 0 && x < w){
					a[x] = 0;
				}
				++k;
			}
		}
		 
		printf("Case %d: %lld\n", ++T, a[w - 1]);
	}
}