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 <map>
#include <cstdio>
using namespace std;
const long long int mod = 1e9 + 9;
#define mat vector< vector<long long int> >

mat matrix_product(const mat &A, const mat &B){
  int n = A.size(), m = B[0].size(), l = A[0].size();
  mat ret(n,vector<long long int>(m));
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < m; ++j){
      ret[i][j] = 0;
      for(int k = 0; k < l; ++k){
        ret[i][j] += (A[i][k]*B[k][j])%mod;
        ret[i][j] %= mod;
      }
    }
  }
  return ret;
}

mat matrix_pow(const mat &P, long long int N){
  mat ret(P.size(),vector<long long int>(P.size(),0)), t = P;
  for(int i = 0; i < P.size(); ++i) ret[i][i] = 1;
  int k = 0;
  while((1LL<<k) <= N){
    if((N>>k)&1LL){
      ret = matrix_product(ret,t);
    }
    ++k;
    t = matrix_product(t,t);
  }
  return ret;
}

int main(){
  long long int W, H, N;
  for(int i = 0; ; ++i){
    cin >> W >> H >> N;
    if(!H) break;
    long long int y;
    int x;
    map<long long int, vector<int> > M;
    for(int j = 0; j < N; ++j){
      cin >> x >> y;
      M[y-1].push_back(x-1);
    }
    long long int t = 0;
    mat ans(1,vector<long long int>(W,0)), A(W,vector<long long int>(W));
    for(int i = 0; i < W; ++i){
      A[i][i] = 1;
      if(i > 0) A[i][i-1] = 1;
      if(i < W-1) A[i][i+1] = 1;
    }
    ans[0][0] = 1;
    for(map<long long int, vector<int> >::iterator itr = M.begin(); itr != M.end(); ++itr){
      long long int d = itr->first - t;
      ans = matrix_product(ans,matrix_pow(A,d));
      vector<int> V = itr->second;
      for(int j = 0; j < V.size(); ++j){
        ans[0][V[j]] = 0;
      }
      t = itr->first;
    }
    long long int d = H - 1 - t;
    ans = matrix_product(ans,matrix_pow(A,d));
    printf("Case %d: %lld\n", i + 1, ans[0][W-1]);
  }
  return 0;
}