Codeforces Round 946 (Div. 3) |
---|

Finished |

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

binary search

brute force

data structures

implementation

sortings

two pointers

*1900

No tag edit access

The problem statement has recently been changed. View the changes.

×
F. Cutting Game

time limit per test

3 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputAlice and Bob were playing a game again. They have a grid of size $$$a \times b$$$ ($$$1 \le a, b \le 10^9$$$), on which there are $$$n$$$ chips, with at most one chip in each cell. The cell at the intersection of the $$$x$$$-th row and the $$$y$$$-th column has coordinates $$$(x, y)$$$.

Alice made the first move, and the players took turns. On each move, a player could cut several (but not all) rows or columns from the beginning or end of the remaining grid and earn a point for each chip that was on the cut part of the grid. Each move can be described by the character 'U', 'D', 'L', or 'R' and an integer $$$k$$$:

- If the character is 'U', then the first $$$k$$$ remaining rows will be cut;
- If the character is 'D', then the last $$$k$$$ remaining rows will be cut;
- If the character is 'L', then the first $$$k$$$ remaining columns will be cut;
- If the character is 'R', then the last $$$k$$$ remaining columns will be cut.

Based on the initial state of the grid and the players' moves, determine the number of points earned by Alice and Bob, respectively.

Input

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains four integers $$$a$$$, $$$b$$$, $$$n$$$, and $$$m$$$ ($$$2 \le a, b \le 10^9$$$, $$$1 \le n, m \le 2 \cdot 10^5$$$) — the dimensions of the grid, the number of chips, and the number of moves.

Each of the next $$$n$$$ lines contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i \le a$$$, $$$1 \le y_i \le b$$$) — the coordinates of the chips. All pairs of coordinates are distinct.

Each of the next $$$m$$$ lines contain a character $$$c_j$$$ and an integer $$$k_j$$$ — the description of the $$$j$$$-th move. It is guaranteed that $$$k$$$ is less than the number of rows/columns in the current grid. In other words, a player cannot cut the entire remaining grid on their move.

It is guaranteed that the sum of the values of $$$n$$$ across all test cases in the test does not exceed $$$2 \cdot 10^5$$$. It is guaranteed that the sum of the values of $$$m$$$ across all test cases in the test does not exceed $$$2 \cdot 10^5$$$.

Output

For each test case, output two integers — the number of points earned by Alice and Bob, respectively.

Example

Input

64 4 3 24 13 32 4D 2R 14 4 3 34 13 22 3D 1L 1U 23 5 3 21 32 23 3R 2R 26 4 4 21 42 35 31 1R 1U 19 3 2 16 13 3D 810 10 2 57 59 1R 1L 2D 1U 4D 1

Output

2 1 2 0 0 3 1 1 2 0 0 1

Note

Below is the game from the first example:

On her turn, Alice cut $$$2$$$ rows from the bottom and scored $$$2$$$ points, then Bob cut $$$1$$$ column from the right and scored one point. Note that if Bob had cut $$$1$$$ row from the bottom, he would have also scored $$$1$$$ point.

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jun/16/2024 02:06:21 (g1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|