Woburn ECOO 1998

Ships

INPUT FILE: ships.in
OUTPUT FILE: ships.out

The Palmia country is divided by a river into the north and south bank. There are N towns on both the north and south bank. Each town on the north bank has its unique friend town on the south bank. No two towns have the same friend.

Each pair of friend towns would like to have a ship line connecting them. They applied for permission to the government. Because it is often foggy on the river the government decided to prohibit intersection of ship lines (if two lines intersect there is a high probability of ship crash).

Your task is to write a program to help government officials decide to which ship lines they should grant permission to get maximum number of non intersecting ship lines.

INPUT
The input file consists of several blocks. In the first line, there is the number of inputs.

Each input set start with 2 integers X,Y separated with exactly one space: X represents the length of the Palmia river bank (10 <= X <= 6000), Y represents the width of the river (10 <= Y <= 100). The second line contains the integer N, the number of towns situated on both south and north riverbanks (1 <= N <= 5000). On each of the next N lines there are two non-negative integers C, D separated with space (C, D <= X), representing distances of the pair of friend towns from the western border of Palmia measured along the riverbanks (C for the town on the north bank, D for the town on the south bank). There are no two towns on the same position on the same riverbank.

OUTPUT
For each block of the input file print to the output file the maximum possible number of ship lines satisfying the conditions above.

Sample Input File

1
30 4
7
22 4
2 6
10 3
15 12
9 8
17 17
4 2

Output for Sample Input

4
Downloader failed! Response object 006~ASP 0159~Buffering Off~Buffering must be on.