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;

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

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

const ll MOD = 1e9+9;

mat mul(mat const&A, mat const& 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] = 1;
  }
  while(n > 0) {
    if(n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}

int W; ll H; int N;
mat coef;
vector<pair<ll, vector<int>>> vs;
mat xsmat;

void make_identity_coef() {
  coef.clear(); coef.resize(W); rep(i, W) coef[i].resize(W);
  rep(i, W) rep(j, 3)
    if(i+j-1 >= 0 && i+j-1<W)
      coef[i][i+j-1] = 1;
}

void init_xsmat() {
  xsmat.clear();
  xsmat.resize(W);
  rep(i, xsmat.size()) xsmat[i].resize(1);
  xsmat[0][0] = 1;
}

void input_blocks() {
  vs.clear();
  unordered_map<ll, vector<int>> y2xs;
  rep(i, N) {
    ll x, y; scanf("%lld%lld", &x, &y); x--, y--;
    y2xs[y].push_back(x);
  }
  for(auto& e: y2xs) vs.emplace_back(e.first, e.second);
  vs.emplace_back(H - 1, vector<int>());
  sort(vs.begin(), vs.end());
}

void update_n_step(ll n) {
  xsmat = mul(pow(coef, n), xsmat);
}

int main() {

  for(int tc = 1; cin >> W >> H >> N && (W|H|N); tc++) {
    input_blocks();
    make_identity_coef();
    init_xsmat();
    ll curr = 0;
    rep(i, (int)vs.size()) {
      update_n_step(vs[i].first - curr);
      curr = vs[i].first;
      for(auto& x: vs[i].second) xsmat[x][0] = 0;
    }
    printf("Case %d: %lld\n", tc, xsmat[W-1][0]);
  }

  return 0;
}