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>
typedef long long ll;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <map>
#include <cstdio>

inline ll getLL(){ ll s; scanf("%lld", &s); return s; }

#include <set>
using namespace std;

const int mod = 1000000009;

int pmat[64][75][75];

void mul(int a[75][75], int b[75][75], int ret[75][75], int n){
  REP(i,n) REP(j,n) ret[i][j] = 0;
  REP(k,n) REP(i,n) REP(j,n)
    ret[i][j] = (ret[i][j] + (ll)a[i][k] * b[k][j]) % mod;
}

void mul(int a[75][75], int b[75], int n){
  int tmp[75];
  REP(i,n){ tmp[i] = b[i]; b[i] = 0; }
  REP(i,n) REP(j,n)
    b[i] = (b[i] + (ll)tmp[j] * a[i][j]) % mod;
}

int main(){
  for(int cc = 1; ; cc++){
    const int w = getLL();
    const ll  h = getLL();
    const int n = getLL();

    if(w + h + n == 0) break;

    map<ll, vector<int> > obj;

    REP(k,63) REP(i,w) REP(j,w) pmat[k][i][i] = 0;
    REP(i,w){
      if(i) pmat[0][i][i - 1] = 1;
      pmat[0][i][i] = 1;
      if(i != w - 1) pmat[0][i][i + 1] = 1;
    }

    for(int i = 1; i < 63; i++)
      mul(pmat[i - 1], pmat[i - 1], pmat[i], w);

    REP(i,n){
      const int x = getLL() - 1;
      const ll y = getLL() - 1;

      obj[y].push_back(x);
    }
    obj[h - 1];

    ll now = 0;
    int b[75] = {1, 0};

    for(const auto &it : obj){
      const ll hh = it.first;
      const ll diff = hh - now;
      const vector<int> &v = it.second;

      REP(i,63) if(diff & (1ll << i)){
        // printf("%d:\n", i);
        // REP(j,w){ REP(k,w) printf("%d ", pmat[i][j][k]); puts(""); }

        mul(pmat[i], b, w);
      }

      REP(j,v.size())
        b[v[j]] = 0;

      now = hh;

      // printf("%lld:\n", hh);
      // REP(i,w) printf("%d ", b[i]); puts("");
    }

    printf("Case %d: %d\n", cc, b[w - 1]);
  }

  return 0;
}