////////////////////////////////////////
///  tu3 pro-con template            ///
////////////////////////////////////////
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <regex>
using namespace std;

//// MACRO ////
#define countof(a) (sizeof(a)/sizeof(a[0]))

#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define RFOR(i,s,n) for (int i = (n)-1; i >= (s); i--)
#define pos(c,i) c.being() + (i)
#define allof(c) c.begin(), c.end()
#define aallof(a) a, countof(a)
#define partof(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define apartof(a,i,n) a + (i), a + (i) + (n)
#define long long long

#define EPS 1e-9
#define INF (1L << 30)
#define LINF (1LL << 60)

#define PREDICATE(t,a,exp) [&](const t & a) -> bool { return exp; }
#define COMPARISON_T(t) bool(*)(const t &, const t &)
#define COMPARISON(t,a,b,exp) [&](const t & a, const t & b) -> bool { return exp; }
#define CONVERTER(TSrc,t,TDest,exp) [&](const TSrc &t)->TDest { return exp; }

inline int sign(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }
inline bool inRange(double val, double min, double max) { return val - min > -EPS && val - max < EPS; }

//// i/o helper ////

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
struct _Writer { bool f; _Writer() : f(false) { } template <class T> _Writer operator ,(const T &rhs) { cout << (f ? " " : "") << rhs; f = true; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__
#define WRITE(...) _Writer(), __VA_ARGS__; cout << endl

template <class T> struct vevector : public vector<vector<T>> { vevector(int n = 0, int m = 0, const T &initial = T()) : vector<vector<T>>(n, vector<T>(m, initial)) { } };
template <class T> struct vevevector : public vector<vevector<T>> { vevevector(int n = 0, int m = 0, int l = 0, const T &initial = T()) : vector<vevector<T>>(n, vevector<T>(m, l, initial)) { } };
template <class T> struct vevevevector : public vector<vevevector<T>> { vevevevector(int n = 0, int m = 0, int l = 0, int k = 0, const T &initial = T()) : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) { } };
template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read(int n) { vector<T> v; REP(i, n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i, n) v.push_back(read<T>(m)); return v; }
template <class T> vevector<T> readjag() { return read<T>(read<int>()); }
template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i, n) v.push_back(readjag<T>()); return v; }

template <class T1, class T2> inline istream & operator >> (istream & in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; }
template <class T1, class T2> inline ostream & operator << (ostream &out, pair<T1, T2> &p) { out << p.first << p.second; return out; }
template <class T> inline ostream & operator << (ostream &out, vector<T> &v)
{
	ostringstream ss;
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	out << s.substr(0, s.length() - 1) << endl;
	return out;
}

//// number ////

// 最大公約数
long gcd(long a, long b) { return b ? gcd(b, a%b) : a; }

// 最小公倍数
long lcm(long a, long b) { return a / gcd(a, b) * b; }

// 拡張ユークリッド互除法 ax + by = gcd(a, b) となる xとyを求める
void exgcd(long a, long b, long& x, long& y)
{
	if (b != 0) { exgcd(b, a % b, y, x); y -= a / b * x; }
	else { x = 1; y = 0; }
}

// modを法としたaの逆元を求める。
long modInv(long a, long mod) { long x, y; exgcd(a, mod, x, y); return x >= 0 ? x : x + mod; }

// modInvのvector版
vector<int> modInvVector(int n, int mod)
{
	vector<int> ret(n + 1);
	ret[1] = 1;
	for (int i = 2; i <= n; ++i)
		ret[i] = ret[mod % i] * (mod - mod / i) % mod;
	return ret;
}

// modを法としてx/yを計算する
inline long modDiv(long x, long y, long mod) { return (x * modInv(y, mod) + mod) % mod; }

// modを法としたxのy乗を求める。(繰り返し二乗法)
inline long modPow(long x, long y, long mod)
{
	long r = 1;
	for (; y > 0; y >>= 1)
	{
		if (y & 1) { r = r * x % mod; }
		x = x * x % mod;
	}
	return r;
}

// modが素数のとき、modを法としたaの逆元を求める。
inline long modInvPrime(long a, long mod_prime) { return modPow(a, mod_prime - 2, mod_prime); }

// modが素数のとき、modを法としてx/yを計算する。
inline long modDivPrime(long x, long y, long mod_prime) { return x * modInvPrime(y, mod_prime) % mod_prime; }

// modを法として nPk を計算する。
inline long mod_nPk(long n, long k, long mod)
{
	long r = 1;
	for (; n > n - k; n--)
		r = r * n % mod;
	return r;
}

// modを法として n! を計算する。
inline long modFact(long n, long mod) { return mod_nPk(n, n, mod); }

// modを法として nCk を計算する。
inline long mod_nCk(long n, long k, long mod_prime)
{
	return modDivPrime(mod_nPk(n, k, mod_prime), modFact(k, mod_prime), mod_prime);
}

// MODを法としたint
template <int MOD>
struct modint
{
	typedef int T;
	typedef long DBL_T;
	
	T v;
	modint(T v = 0) : v(mod(v)) { }
	modint operator +() const { return *this; }
	modint operator -() const { return modint(-v); }
	bool operator == (modint i) const { return v == i.v; }
	bool operator != (modint i) const { return !(*this == i); }

	modint operator +(modint i) const { return modint(v + i.v); }
	modint operator -(modint i) const { return modint(v - i.v); }
	modint operator *(modint i) const { return FromValue((DBL_T)v * i.v % MOD); }
	modint operator /(modint i) const { return FromValue(modDivPrime(v, i.v, MOD)); }

	modint& operator +=(modint i) { *this = *this + i; return *this; }
	modint& operator -=(modint i) { *this = *this - i; return *this; }
	modint& operator *=(modint i) { *this = *this * i; return *this; }
	modint& operator /=(modint i) { *this = *this / i; return *this; }
	modint& operator ++() { v = mod(v + 1); return *this; }
	modint operator ++(int) { modint r = *this; ++(*this); return r; }
	modint& operator --() { v = mod(v - 1); return *this; }
	modint operator --(int) { modint r = *this; --(*this); return r; }

	modint power(T k) { return power(v, k); }
	modint inv() { return inv(v); }

	static T mod(T v) { return v %= MOD, v < 0 ? v + MOD : v; }
	static T mod(DBL_T v) { return v %= MOD, v < 0 ? v + MOD : v; }
	static modint FromValue(T v) { modint r; r.v = v; return r; }

	static modint inv(T v) { return modInvPrime(v, MOD); }
	static modint power(T x, T y) { return FromValue(modPow(x, y, MOD)); }
	static modint fact(T n) { return FromValue(modFact(n, MOD)); }
	static modint nPk(T n, T k) { return mod_nPk(n, k, MOD); }
	static modint nCk(T n, T k) { return mod_nCk(n, k, MOD); }
};

//// start up ////
void solve();
inline void readfrom(string filename) { freopen(filename.c_str(), "r", stdin); }
inline void writeto(string filename) { freopen(filename.c_str(), "w", stdout); }
int main()
{
	solve();
	return 0;
}

/// Matrix
template<class T>
struct Matrix
{
	vevector<T> value;

	Matrix(int N, int M) : value(N, M) { }
	Matrix(vevector<T> v) : value(v) { }
	vector<T> &operator [](int i) { return value[i]; }
	const vector<T> &operator [](int i) const { return value[i]; }

	Matrix operator + (const Matrix &m) const
	{
		int H = value.size(), W = value[0].size(); assert(H == m.value.size() && W == m.value[0].size());
		Matrix mtx(H, W);
		REP(i, H) REP(j, W) mtx[i][j] = value[i][j] + m[i][j];
		return mtx;
	}

	Matrix operator * (const Matrix &m) const
	{
		int H = value.size(), X = value[0].size(), W = m[0].size();	assert(X == m.value.size());
		Matrix mtx(H, W);
		REP(i, H) REP(j, W) REP(k, X) mtx[i][j] += value[i][k] * m[k][j];
		return mtx;
	}

	Matrix power(long y) const
	{
		int X = value.size(); assert(X == value[0].size());
		Matrix r = Identity(X);
		Matrix x = *this;
		for (; y > 0; y >>= 1)
		{
			if (y & 1) { r = r * x; }
			x = x * x;
		}
		return r;
	}

	static Matrix Identity(int n) { Matrix e(n, n); REP(i, n) e[i][i] = 1; return e; }
	static Matrix Zero(int n) { return Matrix(n, n); }
};

////////////////////
/// template end ///
////////////////////

void solve()
{
	int testcases = INF;
	REP(testcase, testcases)
	{
		READ(int, W);
		READ(long, H);
		READ(int, N);
		if (!W) { break; }

		typedef pair<long, long> PT;
		typedef modint<1000000009> MI;
		typedef Matrix<MI> MTX;
		
		auto stops = read<pair<long, long>>(N);
		sort(allof(stops), COMPARISON(PT, a, b, a.second < b.second));

		MTX multiplier(W, W);
		REP(i, W) FOR(j, -1, 2) { multiplier[i][min(max(i + j, 0), W - 1)] = 1; }
		vector<MTX> mulTable; mulTable.push_back(multiplier);
		REP(i, 63) { mulTable.push_back(mulTable.back() * mulTable.back()); }

		long cur = 0;
		MTX stt(1, W); stt[0][0] = 1;

		for (auto s : stops)
		{
			long next = s.second - 1 - cur;
			REP(i, 64)
				if (next & 1ull << i)
					stt = stt * mulTable[i];
			stt[0][s.first - 1] = 0;
			cur += next;
		}
		stt = stt * multiplier.power(H - cur - 1);
		printf("Case %d: %d\n", testcase + 1, stt[0][W - 1].v);
	}
}

Measured memory_bytes: 2900