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>

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

using namespace std;
const int64_t mod = 1000000009;

struct Mod {
  int64_t num;
  Mod () : num(0) {;}
  Mod (int64_t n) : num(n) {;}
  operator int64_t() { return num; }
};

Mod operator+(Mod a, Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator-(Mod a, Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator*(Mod a, Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator+=(Mod &a, Mod b) { return a = a + b; }
Mod operator-=(Mod &a, Mod b) { return a = a - b; }
typedef Mod Data;
typedef vector<Data> Array;
typedef vector<Array> Matrix;

Matrix operator*(const Matrix &lhs, const Matrix &rhs) {
  Matrix res(lhs.size(), Array(rhs[0].size(), 0));
  REP(i,lhs.size()) REP(j,rhs[0].size()) REP(k,rhs.size())
    res[i][j] = res[i][j] + lhs[i][k] * rhs[k][j];
  return res;
}
Matrix scalar(int size, Data k) {
  Matrix mat(size, Array(size, 0));
  REP(i,size) mat[i][i] = k;
  return mat;
}

Matrix operator^(const Matrix &lhs, const int64_t n) {
  if (n == 0) return scalar(lhs.size(), 1);
  Matrix res = (lhs * lhs) ^ (n / 2);
  if (n % 2) res = res * lhs;
  return res;
}

int main() {
  int dts = 0;
  while(1){
    int64_t w,h,n;
    cin>>w>>h>>n;
    if(!w)break;
    Matrix mat(w,Array(w));
    REP(i,w){
      if(i) mat[i][i-1] = 1;
      mat[i][i] = 1;
      if(i<w-1) mat[i][i+1] = 1;
    }
    map<int64_t,set<int64_t>> mm;
    vector<int64_t> ys;
    ys.push_back(0);
    ys.push_back(h-1);
    REP(i,n) {
      int64_t x,y;
      cin>>x>>y;
      --x;--y;
      mm[y].insert(x);
      ys.push_back(y);
    }
    sort(begin(ys),end(ys));
    ys.erase(unique(begin(ys),end(ys)),end(ys));
    int m=ys.size();
    Matrix ary(w,Array(1));
    ary[0][0]=1;
    REP(i,m-1){
      int64_t y=ys[i+1];
      int64_t d = ys[i+1]-ys[i]-1;
      auto pm = mat ^ d;
      ary = pm * ary;
      vector<Data> dp2(w+2);
      REP(j,w) {
        REP(k,3) {
          if (mm.count(y) == 0 || mm[y].count(j+k-1) == 0)
            dp2[j+k] += ary[j][0];
        }
      }
      REP(j,w) {
        ary[j][0] = dp2[j+1];
      }
    }
    ++dts;
    cout << "Case " << dts << ": " << ary[w-1][0] << endl;
  }
  return 0;
}