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 int long long

typedef int number;
typedef vector<number> Array;
typedef vector<Array> matrix;

const int mod = 1000000009;

// O( n )
matrix identity(int n) {
  matrix A(n, Array(n));
  for (int i = 0; i < n; ++i) A[i][i] = 1;
  return A;
}
// O( n^2 )
Array mul(const matrix &A, const Array &x) {
  Array y(A.size());
  for (int i = 0; i < A.size(); ++i)
    for (int j = 0; j < A[0].size(); ++j)
      y[i] = (y[i] + A[i][j] * x[j]) % mod;
  return y;
}
// O( n^3 )
matrix mul(const matrix &A, const matrix &B) {
  matrix C(A.size(), Array(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;
  return C;
}
// O( n^3 log e )
matrix pow(const matrix &A, int e) {
  return e == 0 ? identity(A.size())  :
     e % 2 == 0 ? pow(mul(A, A), e/2) : mul(A, pow(A, e-1));
}

#define range(i,x,y) i=(x);i<(y);i++
#define rep(i,n) for(int i=0,i##_len=n;i<i##_len;i++)
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)
typedef long long ll;
typedef long double ld;


signed main(){
  int w, h, n; int num = 1;
  while(cin >> w >> h >> n, w != 0){
  map<int, vector<int>> obst;
  rep(i, n){
    int x, y; cin >> x >> y;
    if (obst.find(y) == obst.end()){
      obst[y] = vector<int>{x};
    } else {
      obst[y].push_back(x);
    }
  }
  if (obst.find(h) == obst.end()){
    obst[h] = vector<int>{1};
  }
  Array res(w);
  res[0] = 1;

  matrix way(w, Array(w));
  rep(i, w){
    if(i-1 >= 0) way[i][i-1] = 1;
                  way[i][i] = 1;
    if(i+1 <  w) way[i][i+1] = 1;
  }

  int prv = 1;
  for(auto ob : obst){
    int y; vector<int> xs; tie(y, xs) = ob;
    res = mul(pow(way, y - prv), res);
    for(int x: xs){
      res[x - 1] = 0;
    }
    prv = y;

  }
  cout << "Case " << num << ": " << res[w-1] << endl;
  num++;
  }
}