A Walk in the Park#539

A Walk in the Park

10 seconds
64 megabytes
Hard

You are responsible for inspecting the trees located in a park to make sure they remain healthy. The location of each tree is given as a point in the two-dimensional plane, and all tree locations are distinct. Due to recently replanted grass, you may only walk through the park along certain paths. Each path is described by an infinite-length horizontal or vertical line in the two-dimensional plane. No tree lies on any path.

Input

There will be multiple input sets. For each input set, the first line contains two integers, and (0 < N, M \leq 100000), separated by a space. is the number of trees, and is the number of paths.

The next lines each contain two space-separated integers, and , specifying the coordinates of a tree. and may be any 32-bit integers.

The next lines each describe a path (vertical or horizontal line). Each is of the form x=K or y=K, with no spaces. may be any 32-bit integer. and are lowercase letters.

The end of input is indicated by a line containing two space-separated .

Output

For each input set, print a single line containing one integer: the number of visible trees. There should be no blank lines between outputs.

Examples

Example 1

Loading
Loading