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 <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int MOD=1e9+9;

struct Point{
	ll x,y;
	Point(){}
	Point(ll x,ll y):x(x),y(y){}
};

vvi mul(const vvi& a,const vvi& b)
{
	int size=a.size();
	vvi c(size,vi(size));
	rep(i,size) rep(k,size) rep(j,size)
		c[i][j]=(c[i][j]+(ll)a[i][k]*b[k][j])%MOD;
	return c;
}
vi mul(const vvi& a,const vi& b)
{
	int size=b.size();
	vi c(size);
	rep(i,size) rep(j,size)
		c[i]=(c[i]+(ll)a[i][j]*b[j])%MOD;
	return c;
}

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a)
{
	os<<'[';
	for(int i=0;i<a.size();i++)
		os<<(i?" ":"")<<a[i];
	return os<<']';
}

int solve(int w,ll h,int n,vector<Point>& os)
{
	// a[i]: 遷移行列の(2^i)乗
	vector<vvi> a(70);
	a[0].resize(w,vi(w));
	rep(i,w)
		for(int j=max(i-1,0);j<=min(i+1,w-1);j++)
			a[0][i][j]=1;
	repi(k,1,70)
		a[k]=mul(a[k-1],a[k-1]);
	
	// y座標でソート
	rep(i,n) per(j,i)
		if(os[j].y>os[j+1].y)
			swap(os[j],os[j+1]);
	
	vi p(w); p[0]=1;
	ll cy=0;
	for(int i=0,j,k;cy<h-1;){
		for(j=i;j<os.size() && os[j].y<=cy;j++)
			;
		for(k=j;k<os.size() && os[k].y==os[j].y;k++)
			;
		ll ny=j<os.size()?os[j].y:h-1;
		
		ll r=ny-cy;
		rep(l,60)
			if(r>>l&1)
				p=mul(a[l],p);
		repi(l,j,k)
			p[os[l].x]=0;
		
		cy=ny;
		i=k;
	}
	
	return p[w-1];
}

int main()
{
	for(int tc=1;;tc++){
		int w,n; ll h; scanf("%d%lld%d",&w,&h,&n);
		if(!(w|h|n)) break;
		
		vector<Point> os(n);
		rep(i,n){
			scanf("%lld%lld",&os[i].x,&os[i].y);
			os[i].x--; os[i].y--;
		}
		
		printf("Case %d: %d\n",tc,solve(w,h,n,os));
	}
	
	return 0;
}