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<iomanip>

using namespace std;

const int mod = 1000000009;

struct Mat{
  int v[80][80];
  int h,w;

  Mat():h(0),w(0){}
  Mat(int h, int w):h(h),w(w){}
};

vector<Mat> A2;

Mat operator * (const Mat &a, const Mat &b){
  Mat c(a.h,b.w);
  for(int i = 0; i < a.h; ++i){
    for(int j = 0; j <= i && j <= a.h - i - 1; ++j){
      c.v[i][j] = 0;
      for(int k = 0; k < a.w; ++k){
        c.v[i][j] += (long long)a.v[i][k] * b.v[k][j] % mod;
        c.v[i][j] %= mod;
      }
      c.v[j][i] = c.v[c.h-i-1][c.w-j-1] = c.v[c.w-j-1][c.w-i-1] = c.v[i][j];
    }
  }
  return c;
}


Mat power(const Mat &a, long long e)
{
  Mat x = a;
  Mat ret(a.h,a.w);
  
  for(int i = 0; i < ret.h; ++i) for(int j = 0; j < ret.w; ++j)
      ret.v[i][j] = i == j ? 1 : 0;
  A2[0] = ret;

  int ref = 1;
  while(e){if(e&1)ret=ret*A2[ref];++ref;e>>=1;};
  
  return ret;
}

int solve(int w, long long h, int n, const vector<pair<long long, int> > &st)
{
  long long pre = 0;
  Mat b1(w,1), b2(w,1);
  Mat A(w,w);

  for(int i = 0; i < w; ++i){
    b1.v[i][0] = 0;
    b2.v[i][0] = 0;
  }
  b1.v[0][0] = 1;
  for(int i = 0; i < w; ++i){
    for(int j = 0; j < w; ++j){
      if( abs(i-j) <= 1 ) A.v[i][j] = 1;
      else A.v[i][j] = 0;
    }
  }

  A2.clear();
  A2.push_back(A);
  A2.push_back(A);
  for(int i = 2; i < 65; ++i){
    A2.push_back( A2[i-1] * A2[i-1] );
  }
  
  for(int i = 0; i < n; ++i){
    Mat Ae = power(A, st[i].first - pre);
    for(int j = 0; j < w; ++j){
      for(int k = 0; k < w; ++k){
        b2.v[j][0] += (long long)Ae.v[j][k] * b1.v[k][0] % mod;
        b2.v[j][0] %= mod;
      }
    }

    for(int j = 0; j < w; ++j){
      b1.v[j][0] = j!=st[i].second?b2.v[j][0]:0;
      b2.v[j][0] = 0;
    }

    pre = st[i].first;
  }

  return b1.v[w-1][0];
}

int main()
{
  int W,N;
  long long H;
  int tc = 1;

  while( cin >> W >> H >> N ){
    if( W == 0 && H == 0 && N == 0 ) break;
    
    vector<pair<long long,int> > stones;
    for(int i = 0; i < N; ++i){
      int x;
      long long y;
      cin >> x >> y;
      stones.push_back(make_pair(y-1,x-1));
    }
    stones.push_back(make_pair(H-1,W));
    sort(stones.begin(),stones.end());
    
    int res = solve(W,H,N+1,stones);

    cout << "Case " << tc << ": " << res << endl;
    ++tc;
  }
  return 0;
}