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 <bits/stdc++.h>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+9;

typedef vector<LL> Col;
typedef vector<Col> Matrix;

Matrix mul(const Matrix& A, const Matrix& B){
  const int R = A.size(), C = B[0].size(), sz = B.size();
  Matrix AB(R, Col(C));

  for(int i=0;i<R;++i)
    for(int j=0;j<C;++j)
      for(int k=0;k<sz;++k)
		(AB[i][j] += A[i][k] * B[k][j] % MOD) %= MOD;

  return AB;
}
Matrix powA(const Matrix& A, LL n){
  const int N = A.size();
  Matrix p(N, Col(N, 0)), w = A;
  for(int i=0;i<N;++i) p[i][i] = 1;

  while(n>0){
	if(n&1)
	  p = mul(p, w);
	w = mul(w, w);
	n >>= 1;
  }

  return p;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  LL W, H, N, cnt = 1;
  while(cin >> W >> H >> N, W){
	map<LL,VL> xs;
	REP(i,N){
	  LL x, y;
	  cin >> x >> y;
	  --y;
	  --x;
	  xs[y].EB(x);
	}
	if(!xs.count(H-1)) xs[H-1] = {};

	Matrix crt(W, Col(1));
	crt[0][0] = 1;
	LL py = 0;
	for(auto&& p: xs){
	  VVL tmp(W, Col(W));
	  REP(i,W){
		if(i-1 >= 0) tmp[i][i-1] = 1;
		tmp[i][i] = 1;
		if(i+1 < W) tmp[i][i+1] = 1;
	  }
	  tmp = powA(tmp, p.FF - py);
	  crt = mul(tmp, crt);
	  py = p.FF;

	  for(LL x: p.SS)
		crt[x][0] = 0;
	}
	cout << "Case " << cnt++ <<": " << crt[W-1][0] << endl;
  }
  

  return 0;
}