Universal Cup Judging System

Universal Cup

Limite de temps : 3.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓
Statistiques

Panda is playing a game, in which he is fighting the Demon's army with a party of $n$ characters, numbered $1$ to $n$. Each round begins with $m$ Ap (energy points) available to the party.

Each character $i$ has a skill that deals $a_i$ damage and normally costs $c_i$ Ap. In any round, each character can choose to either use their skill once or do nothing with zero cost. The total Ap cost of all skills used in a round must not be more than $m$. Any remaining Ap at the end of the round is discarded, and the party is fully refreshed with $m$ Ap for the next round.

Due to the unique mechanics of this game, if a character uses their skill in a round, its Ap cost for the next round becomes $c_i + k$. If the character continues using the skill in consecutive rounds, the cost stays at $c_i + k$ (it does not increase further). If a character does not use their skill in a round, the skill cost will reset to $c_i$ for the very next round.

Panda wants to maximize the total damage dealt over a total of $R$ rounds. Find the maximum possible total damage.

Input

The first line contains a single integer $T$ ($1 \le T \le 100$), denoting the number of test cases.

For each test case, the first line contains four integers $n, m, k, R$ ($1 \le n \le 6$, $1 \le m, k \le 10^3$, $1 \le R \le 10^9$). $n$ is the number of characters in the party, $m$ is the Ap gained at the start of each round, $k$ is the temporary Ap cost increase when a skill is used, and $R$ is the total number of rounds.

For the next $n$ lines, each line contains two integers $a_i, c_i$ ($1 \le a_i \le 10^6$, $1 \le c_i \le m$), which are the damage and initial Ap cost for character $i$.

Output

Output a single integer, denoting the maximum total damage that can be achieved.

Examples

Input 1

3
3 7 1 5
59 3
13 2
81 4
5 14 2 9
66 8
20 2
25 4
39 6
57 7
4 13 7 16
18 2
13 5
33 4
7 1

Output 1

490
939
741

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#2660EditorialOpen$O\left(\frac{8^n}{\sqrt n}+n^{3/2}4^n\right)\log R$ by GPT6 ProAnonymousView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.