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;

typedef long long int64;
const int mod = 1e9 + 9;

typedef vector< int > vec;
typedef vector< vec > mat;

mat operator*(const mat A, const mat B)
{
  mat ret(A.size(), vec(B[0].size(), 0));
  for(int i = 0; i < A.size(); i++) {
    for(int j = 0; j < B[0].size(); j++) {
      for(int k = 0; k < B.size(); k++) {
        (ret[i][j] += 1LL * A[i][k] * B[k][j] % mod) %= mod;
      }
    }
  }
  return (ret);
}

mat operator^(mat A, int64 n)
{
  mat ret = mat(A.size(), vec(A.size(), 0));
  for(int i = 0; i < A.size(); i++) ret[i][i] = 1;
  while(n > 0) {
    if(n & 1) (ret = ret * A);
    A = A * A;
    n >>= 1LL;
  }
  return (ret);
}

int main()
{
  int64 W, H, N;
  int cc = 1;
  while(cin >> W >> H >> N, W) {
    map< int64, vector< int > > vs;
    vs.emplace(H, vector< int >());
    for(int i = 0; i < N; i++) {
      int64 x, y;
      cin >> x >> y;
      vs[y].push_back(x);
    }
    mat ma(W, vec(W, 0));
    for(int i = 0; i < W; i++) {
      for(int j = max(0, i - 1); j < min(W, i + 2LL); j++) ma[i][j] = 1;
    }
    mat beet(W, vec(1, 0));
    beet[0][0] = 1;
    int64 rev = 1;
    for(auto &p : vs) {
      beet = (ma ^ (p.first - rev)) * beet;
      for(auto &q : p.second) beet[q - 1][0] = 0;
      rev = p.first;
    }
    cout << "Case " << cc++ << ": " << beet[W - 1][0] << endl;
  }
}