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 <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)

typedef vector<ll> vec;
typedef vector<vec> mat;

const ll MOD = 1000000009ll;

mat mul(mat &A,mat &B)
{
	mat C(A.size(),vec(B[0].size()));
	for(int i=0;i<A.size();i++)
	{
		for(int k=0;k<B.size();k++)
		{
			for(int j=0;j<B[0].size();j++)
			{
				C[i][j]=(C[i][j]+A[i][k]*B[k][j])%MOD;
			}
		}
	}
	return C;
}

mat pow(mat A, ll n)
{
	mat B(A.size(),vec(A.size()));
	for(int i=0;i<A.size();i++)
	{
		B[i][i]=1ll;
	}
	while(n>0)
	{
		if(n&1)B = mul(B,A);
		A = mul(A,A);
		n >>= 1;
	}
	return B;
}
P obs[40];
void print(mat A)
{
	/*for(int i=0;i<A.size();i++)
	{
		for(int j=0;j<A[0].size();j++)
		{
			cout << A[i][j] << ' ';
		}
		cout << endl;
	}*/
	cout << A.size() << ' ' << A[0].size() << endl;
	cout << endl;
}
int main()
{
	int t = 0;
	while(1)
	{
		int W,N;
		ll H;
		scanf("%d %lld %d",&W,&H,&N);
		if(W==0&&H==0ll&&N==0)break;
		for(int i=0;i<N;i++)scanf("%d %lld",&obs[i].sec,&obs[i].fi);
		sort(obs,obs+N);
		mat A(W,vec(W));
		for(int i=0;i<W;i++)
		{
			int l = i-1,r = l+3;
			l = max(0,l);
			r = min(r,W);
			for(int j=l;j<r;j++)A[i][j]=1;
		}
		//print(A);
		mat cur(1,vec(W));
		cur[0][0]=1ll;
		vector<ll> v;
		for(int i=0;i<N;i++)v.pb(obs[i].fi);
		v.pb(H);
		ll curh = 1ll;
		//print(cur);
		for(int i=0;i<v.size();i++)
		{
			mat k = pow(A,v[i]-curh);
			//print(k);
			cur = mul(cur,k);
			//print(cur);
			curh = v[i];
			if(i<N)cur[0][obs[i].sec-1]=0ll;
		}
		printf("Case %d: %lld\n",++t,cur[0][W-1]);
	}
	return 0;
}