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:
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
//#include<unordered_map>
#include<utility>
#include<cmath>
//#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU

int MOD=1000000009;
vector<vvi> X(60);
vvi mul(vvi A,vvi B){
    vvi C(A.size(),vi(B[0].size()));
    rep(i,A.size())rep(k,B.size())rep(j,B[0].size())
        (C[i][j]+=A[i][k]*B[k][j])%=MOD;
    return C;
}
vvi pow(vvi A,ll n){
    vvi B(A.size(),vi(A.size()));
    rep(i,A.size())B[i][i]=1;
    rep(i,60)if(1ll<<i&n)
        B=mul(B,X[i]);
    return B;
}
void init(vvi A){
    rep(i,60){
        X[i]=A;
        A=mul(A,A);
    }
}
signed main(){
    int n,m,k,cnt=1;
    while(cin>>m>>n>>k,n|m|k){
        vvi in(k);
        rep(i,k){
            int a,b;
            cin>>b>>a;
            a--;b--;
            in[i]=vi{a,b};
        }
        vi y=vi{0,n-1};
        rep(i,k)y.pb(in[i][0]);
        sort(all(y));
        y.erase(unique(all(y)),y.end());
        vvi G(y.size());
        rep(i,k)G[lower_bound(all(y),in[i][0])-y.begin()].pb(in[i][1]);

        vvi A(m,vi(m));
        rep(i,m)rep(j,m)if(abs(i-j)<=1)A[i][j]=1;
        init(A);
        vvi X(m,vi(1));
        X[0][0]=1;
        rep(j,G[0].size())X[G[0][j]][0]=0;
        rep(i,y.size()-1){
            X=mul(pow(A,y[i+1]-y[i]),X);
            rep(j,G[i+1].size())X[G[i+1][j]][0]=0;
        }
        cout<<"Case "<<cnt++<<": "<<X[m-1][0]<<endl;
    }
}