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>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int lli;
const lli mod = 1e9 +9;

typedef vector<lli> Vec;
typedef vector<vector<lli>> Mat;
Vec operator +(const Vec &a, const Vec &b){
    Vec res(a.size());
    for(int i=0; i<(int)a.size(); i++){
        res[i] = (a[i] + b[i]) %mod;
    }
    return res;
}
Vec operator *(const Mat &a, const Vec &b){
    Vec res(b.size(), 0);
    for(int i=0; i<(int)b.size(); i++){
        for(int j=0; j<(int)a[i].size(); j++){
            res[i] += a[i][j]*b[j] %mod;
        }
        res[i] %= mod;
    }
    return res;
}
Mat operator *(const Mat &a, const Mat &b){
    int p=a.size(), q=b.size(), r=b[0].size();
    Mat res(p, Vec(r, 0));
    for(int i=0; i<p; i++){
        for(int j=0; j<r; j++){
            for(int k=0; k<q; k++){
                res[i][j] += a[i][k]*b[k][j] %mod;
            }
            res[i][j] %= mod;
        }
    }
    return res;
}

Mat modpow(Mat a, lli p){
    Mat res(a.size(), Vec(a.size(), 0));
    for(int i=0; i<(int)a.size(); i++){
        res[i][i] = 1;
    }
    for(int i=63; i>=0; i--){
        res = res*res;
        if((1LL<<i & p) != 0){
            res = res*a;
        }
    }
    return res;
}

int main(){
    for(int dataset=1; ; dataset++){
        lli w,h,n;
        cin >> w >> h >> n;
        if(w == 0) break;

        map<lli, vector<lli>> obs;
        obs[h-1] = vector<lli>();
        for(int i=0; i<n; i++){
            lli x,y;
            cin >> x >> y;
            x--; y--;
            obs[y].push_back(x);
        }
        
        Mat ch(w, Vec(w, 0));
        for(int i=0; i<w; i++){
            for(int j=-1; j<=1; j++){
                if(i+j<0 or i+j>=w) continue;
                ch[i][i+j] = 1;
            }
        }
        Vec curr(w, 0);
        curr[0] = 1;
        lli curridx = 0;
        for(auto p: obs){
            if(curridx < p.first){
                curr = modpow(ch, p.first-curridx)*curr;
            }
            for(lli obsx: p.second){
                curr[obsx] = 0;
            }
            curridx = p.first;
        }
        cout << "Case " << dataset << ": " << curr.back() << endl;
    }
    return 0;
}