QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#13221. Barcelona

统计

zzq has several bags of coins, each containing $k$ coins. One bag consists entirely of fake coins, while all other bags consist of genuine coins. Fake coins and genuine coins are identical in every way except for their weight; fake coins are heavier, and coin weights are positive real numbers.

zzq has an electronic scale and intends to perform $m$ weighings. Formally, for each weighing, zzq can specify two disjoint sets of coins $A$ and $B$, and the scale will output the exact value of $W(A) - W(B)$, where $W(A)$ denotes the total weight of the coins in set $A$. The coins used in the weighings can come from any of the bags.

zzq is lazy, so he wants you to help him provide a weighing plan using at most $m$ weighings to determine which bag contains the fake coins. The weighing plan you provide must be fixed (i.e., the $2m$ sets of coins for the weighings must be specified in advance) and must be able to uniquely identify the bag containing the fake coins.

Having reached this point, zzq finally remembered that he did not specify the number of bags of coins, so he wants you to output the maximum number of bags of coins that can be resolved, modulo 998244353. You do not need to output the weighing plan itself.

Input

The first line contains a positive integer $T$, representing the number of test cases. The next $T$ lines each contain two integers $m$ and $k$, representing a test case.

Output

Output $T$ lines, each representing the maximum number of bags of coins that can be distinguished for that test case, modulo 998244353.

Examples

Input 1

4
1 1
2 1
2 2
23 45

Output 1

3
9
17
648619844

For the first test case, we can weigh the first two coins; if the weights are different, the heavier one is the fake coin, otherwise the remaining one is the fake coin.

Regarding the fourth test case, I have a marvelous explanation, but the margin here is too small to contain it.

Note

For all data, $1 \leq m, k \leq 10^{5}, T \leq 10$.

  • Subtask 1 (20 pts): $k=1$.
  • Subtask 2 (20 pts): $m, k \leq 3$.
  • Subtask 3 (30 pts): $m, k \leq 100$.
  • Subtask 4 (30 pts): No special restrictions.

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.