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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000009 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

struct Matrix {
  vector<vector<ll>> data;

  Matrix() {};
  Matrix(int n): data(n, vector<ll>(n, 0)) {};
  void init(int n) { data.assign(n, vector<ll>(n, 0)); }

};

Matrix base[100];

Matrix create(int n, bool *cur, bool *next) {
  Matrix res(n);

  for (int i=0; i<n; i++) {
    if (next[i]) continue;

    if (i > 0 && !cur[i-1]) res.data[i][i-1] = 1;
    if (!cur[i]) res.data[i][i] = 1;
    if (i + 1 < n && !cur[i+1]) res.data[i][i+1] = 1;
  }

  return res;
}

Matrix mul(Matrix &a, Matrix &b) {
  int n = a.data.size();
  Matrix res(n);

  for (int i=0; i<n; i++)
    for (int j=0; j<n; j++)
      for (int k=0; k<n; k++)
        res.data[i][j] = (res.data[i][j] + a.data[i][k] * b.data[k][j]) % mod;

  return res;
}

ll solve() {
  int W, N; ll H;
  bool cur[75] = {}, next[75] = {};
  set<ll> line;
  set<pair<int,ll> > pos;

  scanf("%d%lld%d", &W, &H, &N);

  if (W == 0) return -1;

  base[0] = create(W, cur, next);

  for(int i=1; i<64; i++)
    base[i] = mul(base[i-1], base[i-1]);

  Matrix mat(W);

  for (int i=0; i<W; i++) mat.data[i][i] = 1;

  for (int i=0; i<N; i++) {
    int x; ll y;

    scanf("%d%lld", &x, &y);
    x--; y--;
    if (0 < y) line.insert(y);
    if (y+1 < H) line.insert(y+1);
    pos.insert({x, y});
  }
  line.insert(H-1);

  ll last = 0;

  for (auto y : line) {
    ll t = y - last - 1;

    for (int i=0; t; i++) {
      if (t & 1) mat = mul(base[i], mat);
      t /= 2;
    }

    for (int i=0; i<W; i++) {
      cur[i] = pos.find({i, y-1}) != pos.end();
      next[i] = pos.find({i, y}) != pos.end();
    }

    Matrix tmp = create(W, cur, next);
    mat = mul(tmp, mat);
    last = y;
  }



  return mat.data[W-1][0];
}

int main(){

  for (int i=1;; i++) {
    ll ans = solve();

    if (ans == -1) break;

    printf("Case %d: %lld\n", i, ans);
  }

  return 0;
}