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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+9;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}


//************************************************************************//

//型を決めてね！！！！！！！！！！！
typedef ll MatType;

//演算の単位元も決めてね！！！！！！！！！！！！！！
const MatType plus_base = 0;
const MatType mul_base = 1;

typedef vector <MatType> Vec;
typedef vector <Vec> Mat;

//A * B = C
Mat mul(const Mat &A, const Mat &B)
{
	//大前提
	assert((int)A[0].size() == (int)B.size());

	Mat C((int)A.size(), Vec((int)B[0].size(), plus_base));

	//メモリへのアクセス的にこうしたほうが早いのです
	rep((int)A.size(), i) rep((int)B.size(), k) rep((int)B[0].size(), j)
	{
		C[i][j] += A[i][k] * B[k][j] % MOD;
		C[i][j] %= MOD;
	}

	return C;
}

// v' = A * v
//オーバーロードしているんです！！！！！！！！！！！！
Vec mul(const Mat &A, const Vec &v)
{
	//大前提
	assert((int)A[0].size() == (int)v.size());

	Vec nv((int)A.size(), plus_base);

	rep((int)A.size(), i) rep((int)v.size(), j)
	{
		nv[i] += A[i][j] * v[j] % MOD;
		nv[i] %= MOD;
	}

	return nv;
}

// A ^ N
Mat mpow(Mat A, ll N)
{
	//大前提
	assert((int)A[0].size() == (int)A.size() && N >= 0);

	Mat Res((int)A.size(), Vec((int)A.size(), plus_base));

	// A ^ 0 = E
	rep((int)A.size(), i)
	{
		Res[i][i] = mul_base;
	}

	while(N)
	{
		if (N & 1)
		{
			Res = mul(Res, A);
		}
		A = mul(A, A);
		N >>= 1;
	}

	return Res;
}

//************************************************************************//

void solve(void){
	int W, N; ll H;
	int cnt = 1;
	while(cin >> W >> H >> N)
	{
		if (!W) break;

		//obs (h, w)
		vector <P> obs(N);
		rep(N, i) cin >> obs[i].snd >> obs[i].fst;
		sort(all(obs));

		Vec V(W, 0);
		V[0] = 1;

		ll acc = 0;

		for (auto p : obs)
		{
			ll n = p.fst - 1 - acc;

			Mat M(W, Vec(W, 0));
			rep(W, i) M[i][i] = 1;
			rep(W-1, i) M[i+1][i] = 1;
			rep(W-1, i) M[i][i+1] = 1;

			M = mpow(M, n);
			V = mul(M, V);
			acc += n;
			V[p.snd-1] = 0;
		}

		Mat M(W, Vec(W, 0));
		rep(W, i) M[i][i] = 1;
		rep(W-1, i) M[i+1][i] = 1;
		rep(W-1, i) M[i][i+1] = 1;

		V = mul(mpow(M, H - acc - 1), V);

		cout << "Case " << cnt++ << ": " <<  V[W-1] << endl;

	}
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}