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 MOD 1000000009

typedef long long int LLI;
typedef LLI Matrix[75][75];

int Case;
int w;
LLI h;
int n;

void Add(Matrix &A, Matrix &B, Matrix &C) {
  for (int i=0; i<w; i++) {
    for (int j=0; j<w; j++) {
      C[i][j] = (A[i][j]+B[i][j])%MOD;
    }
  }
}

void Mul(Matrix &A, Matrix &B, Matrix &C) {
  Matrix res;
  for (int i=0; i<w; i++) {
    for (int j=0; j<w; j++) {
      res[i][j] = 0;
      for (int k=0; k<w; k++) {
        res[i][j] = (res[i][j]+A[i][k]*B[k][j]%MOD)%MOD;
      }
    }
  }

  for (int i=0; i<w; i++) {
    for (int j=0; j<w; j++) {
      C[i][j] = res[i][j];
    }
  }
}

void Exp(Matrix &A, LLI k, Matrix &C) {
  Matrix mul;
  Matrix res;

  for (int i=0; i<w; i++) {
    for (int j=0; j<w; j++) {
      mul[i][j] = A[i][j];
      if (i == j) C[i][j] = 1;
      else C[i][j] = 0;
    }
  }

  LLI g = 0;
  while (k >> g) {
    if (k >> g & 1) {
      Mul(C, mul, C);
    }
    Mul(mul, mul, mul);
    g++;
  }
}

int main() {
  while (1) {
    scanf("%d%lld%d", &w, &h, &n);
    if ((w|h|n) == 0) return 0;

    map<LLI, set<int> > objs;
    for (int i=0; i<n; i++) {
      int x;
      LLI y;
      scanf("%d%lld", &x, &y);
      if (y == 1) continue;
      objs[y].insert(x);
    }
    objs[h].insert(0);

    Matrix Ans;
    Matrix Base;
    for (int i=0; i<w; i++) {
      for (int j=0; j<w; j++) {
        if (i == j) Ans[i][j] = 1;
        else Ans[i][j] = 0;
        if (i-1 <= j && j <= i+1) Base[i][j] = 1;
        else Base[i][j] = 0;
      }
    }
  
    LLI cury = 1;
    for (auto &itr : objs) {
      LLI t = itr.first;
      Matrix mul, one;

      if (t-1-cury > 0) {
        Exp(Base, t-1-cury, mul);
        Mul(Ans, mul, Ans);
      }

      for (int j=0; j<w; j++) {
        for (int k=0; k<w; k++) {
          if (itr.second.count(k+1)) one[j][k] = 0;
          else one[j][k] = Base[j][k];
        }
      }
      Mul(Ans, one, Ans);
      cury = t;
    }
  
    printf("Case %d: %lld\n", ++Case, Ans[0][w-1]);
  }
}