Folding Game

Time limit1sMemory limit128 MB

Problem

Alice places a rectangular sheet of paper in front of Bob. The paper has width $W$ and height $H$ and lies flat. Alice then folds the paper $N$ times. Each fold is either horizontal or vertical: a horizontal fold leaves a rectangle of the same width $W$ but smaller height, and a vertical fold leaves a rectangle of the same height $H$ but smaller width.

When the folding is done, Alice presses a finger onto some point of the resulting rectangle and asks: how many layers of paper lie directly beneath her finger?

Input

The input contains several test cases. Each test case begins with a line of three integers

W H N

where $W$ and $H$ ($0 < W, H \le 10^6$) are the width and height of the paper and $N$ ($0 \le N \le 20$) is the number of folds. Both $W$ and $H$ are even. Each of the next $N$ lines contains a letter and a number separated by one space

D K

The capital letter $D$ is one of T, B, L, R, telling whether the fold comes from the Top, Bottom, Left, or Right. The number $K$ gives the position of the fold, measured from that edge; for instance, if $D$ is T, Alice lifts the top edge and folds it downward. $K$ always lies on the paper and is even. The final line of each test case contains two integers

X Y

the point where Alice puts her finger, measured from the bottom-left corner: $X$ is the distance to the right and $Y$ is the distance upward. The point $(X, Y)$ is guaranteed to lie on the fully folded paper, and both $X$ and $Y$ are odd. Because $W$, $H$, and every $K$ are even, this guarantees that $(X, Y)$ never lies exactly over an edge or a fold. The input ends with a line containing three zeros.

Output

For each test case, output a single integer on its own line: the number of layers of paper at the point $(X, Y)$. Do not print extra spaces, and do not separate the answers with blank lines.