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:
/*
 * 2397.cc: Three-way Branch
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_W = 75;

typedef long long ll;

const ll MOD = 1000000009;

/* typedef */

typedef vector<int> vi;
typedef map<ll,vi> mlvi;

template <typename T, const int N>
struct Matrix {
  int n;
  T m[N][N];

  Matrix(): n(0) {}
  Matrix(int _n): n(_n) {};

  void init() { memset(m, 0, sizeof(m)); }
  void unit() {
    init();
    for (int i = 0; i < n; i++) m[i][i] = 1;
  }
  void bidiag() {
    init();
    if (n == 1) m[0][0] = 1;
    else {
      m[0][0] = m[0][1] = 1;
      m[n - 1][n - 2] = m[n - 1][n - 1] = 1;
      for (int i = 1; i < n - 1; i++)
	m[i][i - 1] = m[i][i] = m[i][i + 1] = 1;
    }
  }

  Matrix<T,N> operator*(const Matrix<T,N>& m0) {
    Matrix<T,N> mm(n);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        mm.m[i][j] = 0;
        for (int k = 0; k < n; k++)
	  mm.m[i][j] = (mm.m[i][j] + (m[i][k] * m0.m[k][j] % MOD)) % MOD;
      }
    return mm;
  }

  Matrix<T,N> pow(T e) {
    Matrix<T,N> mm(n), m0 = *this;
    mm.unit();

    while (e > 0) {
      if (e & 1) mm = mm * m0;
      m0 = m0 * m0;
      e >>= 1;
    }
    return mm;
  }

  void print() {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) printf("%lld ", m[i][j]);
      putchar('\n');
    }
  }
};

typedef Matrix<ll,MAX_W> matrix;

/* global variables */

/* subroutines */

/* main */

int main() {
  for (int tn = 1;; tn++) {
    int w, n;
    ll h;
    cin >> w >> h >> n;
    if (w == 0) break;

    mlvi xys;
    
    for (int i = 0; i < n; i++) {
      int x;
      ll y;
      cin >> x >> y;
      x--, y--;
      if (y == 0) continue;

      mlvi::iterator mit = xys.find(y);
      if (mit == xys.end())
	xys[y].push_back(x);
      else
	mit->second.push_back(x);
    }

    matrix m(w), mb(w);
    m.unit();
    //m.print();
    mb.bidiag();
    ll cy = 0;
    
    for (mlvi::iterator mit = xys.begin(); mit != xys.end(); mit++) {
      vi &xs = mit->second;
      const ll &y = mit->first;

      if (y > cy + 1)
	m = mb.pow(y - cy - 1) * m;

      matrix mo = mb;
      for (int i = 0; i < xs.size(); i++) {
	int &x = xs[i];
	if (x > 0) mo.m[x][x - 1] = 0;
	mo.m[x][x] = 0;
	if (x < w - 1) mo.m[x][x + 1] = 0;
      }
      m = mo * m;

      cy = y;
    }

    if (h - 1 > cy)
      m = mb.pow(h - 1 - cy) * m;
    //m.print();
    
    printf("Case %d: %lld\n", tn, m.m[w - 1][0]);
  }

  return 0;
}