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<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdio>
#include<cassert>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define inf (1<<29)
#define MOD 1000000009

using namespace std;
typedef long long ll;
typedef pair<ll,ll> Coor;

//
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef VVI matrix;

matrix identity(int n)
{
  matrix A(n,VI(n));
  for(int i=0;i<n;i++) A[i][i] = 1;
  return A;
}

VI multi(const matrix& A,const VI& B)
{
  VI ret(A.size());
  for(int i=0;i<A.size();++i)
    for(int j=0;j<A[0].size();++j)
      ret[i] = (ret[i]+(A[i][j]*B[j])%MOD)%MOD;
  return ret;
}

matrix multi(const matrix& A,const matrix& B)
{
  matrix C(A.size(),VI(B[0].size()));
  for(int i=0;i<C.size();++i)
    for(int j=0;j<C[i].size();++j)
      for(int k=0;k<A[i].size();++k)
	C[i][j] = (C[i][j]+(A[i][k]*B[k][j])%MOD)%MOD;
  return C;
}

matrix pow(const matrix& A,ll e)
{
  return !e?identity(A.size()):
    (e%2LL?multi(A,pow(A,e-1LL)):pow(multi(A,A),e/2LL));
}
//
ll W,H,N;
int dx[] = {-1,0,+1};
map<ll,vector<int> > obstruction;

matrix getMatrix(vector<int> vec)
{
  bool out[W];
  rep(i,W)out[i] = false;
  rep(i,vec.size())out[vec[i]] = true;
  matrix A = identity(W);
  rep(i,W)A[i][i] = 0;
  rep(x,W)
    {
      if(out[x])continue;
      rep(k,3)
	{
	  int nx = x + dx[k];
	  if(!(0 <= nx && nx < W))continue;
	  A[x][nx] = 1;
	}
    }
  return A;
}

void print(matrix A)
{
  rep(i,A.size())
    {
      rep(j,A[i].size())
	{
	  cout << A[i][j] << " ";
	}
      cout << endl;
    }
  cout << endl;
}

int main()
{
  int CNT = 1;
  while(scanf("%lld %lld %lld",&W,&H,&N),W|H|N)
    {
      obstruction.clear();
      vector<Coor> vec(N);
      vector<ll> b(W,0);
      b[0] = 1;
      bool out = false;
      rep(i,N)
	{
	  scanf("%lld %lld",&vec[i].first,&vec[i].second);
	  vec[i].first--,vec[i].second--;
	  if(vec[i].first == W-1 && vec[i].second == H-1)out = true;
	  if(vec[i].second == 0)continue;
	  if(vec[i].second == H-1)continue;
	  obstruction[vec[i].second].push_back(vec[i].first);
	}

      if(out)
	{
	  cout << "Case " << CNT++ << ": " << 0 << endl;
	  continue;
	}

      matrix A = getMatrix(vector<int>());
      matrix ans = identity(W);
      //cout << "A : "<< endl;
      //print(A);

      ll cur = 0;
      for(map<ll,vector<int> >::iterator it = obstruction.begin();it!=obstruction.end();it++)
	{
	  vector<int> obst = it->second;
	  matrix B = getMatrix(obst);
	  ll diff = (it->first) - cur - 1;

	  if(diff != 0)
	    {
	      matrix tmp = pow(A,diff);
	      ans = multi(tmp,ans);
	    }

	  ans = multi(B,ans);
	  cur = (it->first);

	}

      if((H-1) != cur)
	{
	  matrix tmp = pow(A,(H-1)-cur);
	  ans = multi(tmp,ans);
	}

      VI vans = multi(ans,b);
   
      cout << "Case " << CNT++ << ": " << vans[W-1]%MOD << endl;

    }
  return 0;
}