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 lli;
typedef vector<lli> vec;
typedef vector<vec> mat;

struct P{
  lli x, y;
  bool operator < (const P &p) const {
    return y == p.y ? x < p.x : y < p.y;
  }
};

const lli MOD = 1000000009;

lli modmul(lli a, lli b){
  return (((a * (b >> 20) % MOD) << 20) + a * (b & ((1 << 20) - 1))) % MOD;
}

void mul(const mat &a, const mat &b, mat &c){
  int n = a.size();

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      c[i][j] = 0;
      for(int k=0;k<n;k++){
        c[i][j] = (c[i][j] + modmul(a[i][k], b[k][j])) % MOD;
      }
    }
  }
}

vec mul(const vec &a, const mat &b){
  int n = a.size();
  vec c(n, 0);

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      c[i] = (c[i] + modmul(a[j], b[j][i])) % MOD;
    }
  }

  return c;
}

lli w, h;
int n;
P v[30];

void init_a(mat &a, mat a_pow[65]){
  a.assign(w, vec(w, 0));
  for(int i=0;i<w;i++){
    if(i - 1 >= 0) a[i][i-1] = 1;
    a[i][i] = 1;
    if(i + 1 < w) a[i][i+1] = 1;
  }

  a_pow[0].assign(w, vec(w, 0));
  a_pow[1] = a;
  for(int i=0;i<w;i++) a_pow[0][i][i] = 1;
  for(int i=2;i<65;i++){
    a_pow[i].assign(w, vec(w, 0));
    mul(a_pow[i-1], a_pow[i-1], a_pow[i]);
  }
}

mat pow(mat a, lli p, mat a_pow[65]){
  int n = a.size(), j = 0;
  mat C[2] = {mat(n, vec(n, 0)), mat(n, vec(n, 0))};

  for(int i=0;i<n;i++) C[0][i][i] = 1;

  for(int i=1;i<65;i++){
    if(p <= 0) break;
    if(p & 1) {
      mul(a_pow[i], C[j&1], C[!(j&1)]);
      j = !j;
    }
    p >>= 1;
  }

  return C[j&1];
}

lli solve(){
  lli pos = 1;
  int v_pos = 0;
  vec b(w, 0);
  vector<lli> obst_y;
  mat a;
  mat a_pow[65];

  init_a(a, a_pow);
  b[0] = 1;

  sort(v, v+n);
  for(int i=0;i<n;i++){
    if(v[i].y == 1) {
      v_pos++;
      continue;
    }
    if(obst_y.size() == 0 || obst_y[obst_y.size()-1] != v[i].y){
      obst_y.push_back(v[i].y);
    }
  }

  for(int i=0;i<obst_y.size();i++){
    b = mul(b, pow(a, obst_y[i]-pos, a_pow));
    for(;v_pos<n;v_pos++){
      if(v[v_pos].y != obst_y[i]) break;
      b[v[v_pos].x-1] = 0;
    }
    pos = obst_y[i];
  }
  b = mul(b, pow(a, h-pos, a_pow));

  return b[w-1];
}

int main(){
  int cnt = 1;

  while(1){
    scanf("%lld%lld%d",&w,&h,&n);
    if(w == 0 && h == 0) break;
    for(int i=0;i<n;i++){
      P p;
      scanf("%lld%lld",&p.x,&p.y);
      v[i] = p;
    }
    printf("Case %d: %lld\n",cnt++,solve());
  }
}