Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

Description

$N$ people have applied for a voice actor talk event. To apply for this event, a person must purchase between $1$ and $4$ tickets inclusive, and there are $T_i$ people who purchased $i$ tickets ($1 \le i \le 4$). Here, people are distinguished only by the number of tickets they purchased; people with the same number of tickets are considered indistinguishable.

In this talk event, if a person wins the lottery, they can talk with the voice actor for a duration equal to the number of tickets they purchased.

The total duration of the event is $X$ units of time. Puffin Pataro, the god of randomness, selects the winners so that the total duration does not exceed the event time (in other words, the sum of the numbers of tickets purchased by the winners is at most $X$). However, to avoid complaints from those who are not selected, the following condition must be satisfied:

  • For any person who is not selected, if that person were additionally selected, the total duration would exceed the event time.

Find the number of ways to select exactly $K$ winners, modulo $998244353$.

Solve this problem for $\text{TESTCASES}$ test cases.

Input

The input is given in the following format:

TESTCASES
case_1
case_2
:
case_T

Each test case is given in the following format:

N K X
T_1 T_2 T_3 T_4
  • $1 \le \text{TESTCASES} \le 10^4$
  • $1 \le K \le N \le 2.5 \times 10^8$
  • $1 \le X \le 10^9$
  • $0 \le T_i$ ($1 \le i \le 4$)
  • $T_1 + T_2 + T_3 + T_4 = N$
  • All input values are integers

Output

Output $\text{TESTCASES}$ lines.

On the $i$-th line, output the answer for the $i$-th test case.

Example

2
24 8 11
7 6 3 8
24 3 28
7 6 3 8
4
0

Note

Let $t_i$ be the number of winners among the people who purchased $i$ tickets. In the first test case, there are the following $4$ possible selections:

  • $(t_1, t_2, t_3, t_4) = (5, 3, 0, 0)$
  • $(t_1, t_2, t_3, t_4) = (6, 1, 1, 0)$
  • $(t_1, t_2, t_3, t_4) = (7, 0, 0, 1)$
  • $(t_1, t_2, t_3, t_4) = (7, 0, 1, 0)$

In the second test case, there is no selection that satisfies the conditions.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1493EditorialOpen题解jianglyView

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.