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<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000009;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;
mat mtmul(mat &A, mat &B) {
	mat C(A.size(), vec(B[0].size()));
	rep(i, (int)A.size()) {
		rep(k, (int)B.size()) {
			rep(j, (int)B[0].size()) {
				C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % mod) % mod;
			}
		}
	}
	return C;
}
mat mtpow(mat A, ll n) {
	mat B(A.size(), vec(A.size()));
	rep(i, (int)A.size()) {
		B[i][i] = 1;
	}
	while (n > 0) {
		if (n&(ll)1)B = mtmul(B, A);
		A = mtmul(A, A);
		n >>= 1;
	}
	return B;
}
int main() {

	int w; ll h; int n; int cnt = 1;
	while (cin >> w >> h >> n, w) {
		mat b;
		rep(i, w) {
			vec nex;
			rep(j, w) {
				if (abs(i-j)<=1) {
					nex.push_back(1);
				}
				else {
					nex.push_back(0);
				}
			}
			b.push_back(nex);
		}
		vector<LP> obs; int staobs = w;
		rep(i, n){
			ll x, y; cin >> x >> y; x--; y--;
			if (y == 0)staobs = min(staobs, (int)x);
			else obs.push_back({ y,x });
	    }
		sort(obs.begin(), obs.end());
		vec val;
		rep(i, w) {
			if (i < 1)val.push_back(1);
			else val.push_back(0);
		}
		ll now = 0;
		rep(i, obs.size()) {
			bool nouse[76] = {};
			ll ny = obs[i].first; nouse[obs[i].second] = true;
			while (i + 1 < obs.size() && ny == obs[i+1].first) {
				i++; nouse[obs[i].second] = true;
			}
			mat need = mtpow(b, ny - now - 1); now = ny;
			vec nextval;
			rep(i, w) {
				ll sum = 0;
				rep(j, w) {
					sum += need[i][j] * val[j]; sum %= mod;
				}
				nextval.push_back(sum);
			}
			val = nextval; nextval.clear();
			if (nouse[0])nextval.push_back(0);
			else nextval.push_back((val[0]+val[1])%mod);
			rep1(i, w - 1) {
				ll sum = val[i - 1] + val[i]; 
				if (i < w - 1)sum += val[i + 1];
				sum %= mod;
				if (nouse[i])sum = 0;
				nextval.push_back(sum);
			}
			val = nextval;
		}
		mat need = mtpow(b, h-1 - now);
		vec nextval;
		rep(i, w) {
			ll sum = 0;
			rep(j, w) {
				sum += need[i][j] * val[j]; sum %= mod;
			}
			nextval.push_back(sum);
		}
		val = nextval;
		cout << "Case " << cnt << ": ";
		cout << val[w - 1] << endl;
		cnt++;
	}
	return 0;
}