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 JAVA):

Solution:
import java.util.*;

public class Main implements Runnable {

	private static final long MOD = 1000000009;
	private static final int MAX = 62;

	@Override
	public void run() {
		Scanner sc = new Scanner(System.in);
		for (int c = 1; sc.hasNext(); c++) {
			final int W = sc.nextInt();
			final long H = sc.nextLong();
			final int N = sc.nextInt();
			if (H == 0 && W == 0 && N == 0)
				return;

			NavigableMap<Long, List<Integer>> obs = new TreeMap<Long, List<Integer>>();
			for (int i = 0; i < N; i++) {
				final int x = sc.nextInt() - 1;
				final long y = sc.nextLong() - 1;
				if (!obs.containsKey(y))
					obs.put(y, new ArrayList<Integer>());
				obs.get(y).add(x);
			}
			if (!obs.containsKey(H - 1))
				obs.put(H - 1, new ArrayList<Integer>());
			final long[][][] ms = new long[MAX][W][W];
			for (int i = 0; i < W; i++)
				for (int j = 0; j < W; j++)
					ms[0][i][j] = Math.abs(i - j) <= 1 ? 1 : 0;
			for (int p = 1; p < MAX; p++)
				for (int i = 0; i < W; i++)
					for (int j = 0; j < W; j++)
						for (int k = 0; k < W; k++) {
							ms[p][i][j] += ms[p - 1][i][k] * ms[p - 1][k][j];
							ms[p][i][j] %= MOD;
						}
			long[] v = new long[W];
			v[0] = 1l;
			for (long y = 0; !obs.isEmpty();) {
				Map.Entry<Long, List<Integer>> e = obs.pollFirstEntry();
				final long p = e.getKey() - y;
				for (int b = 0; b < MAX; b++)
					if ((p & (1L << b)) > 0) {
						long[] u = new long[W];
						for (int i = 0; i < W; i++)
							for (int j = 0; j < W; j++) {
								u[i] += ms[b][i][j] * v[j];
								u[i] %= MOD;
							}
						v = u;
					}
				for (final int x : e.getValue())
					v[x] = 0l;
				y += p;
			}
			System.out.println("Case " + c + ": " + v[W - 1]);
		}
	}

	public static void main(String... args) {
		new Main().run();
	}
}