#P7355. 「PMOI-1」抽奖

「PMOI-1」抽奖

Description

There are nn types of items in the event prize pool, and dead_X has mm redemption coupons. One coupon can be exchanged for one lottery chance or 114514114514 coins.

dead_X decides to use some coupons for the lottery, and exchange the remaining coupons for coins.

In one lottery chance, dead_X will obtain, with equal probability, a 19198101919810-second trial card of one item from the prize pool.

Because dead_X bought a VIP card in the event, after all lotteries are finished, he may choose one type of trial card obtained from the lotteries, submit all trial cards of that type, and receive the corresponding type of permanent item.

Note that dead_X may choose not to use this feature, but he cannot use it more than once.

dead_X, who has trouble making choices, wants to know how many possible event outcomes there are.

Two event outcomes are different if and only if the coins obtained are different, or the trial card obtained in any lottery is different (i.e., the sequence of drawn trial cards is different), or the permanent item obtained is different.

Note that the lottery only gives trial cards. The final chosen permanent item is unrelated to which draw each trial card came from.


Update 2023.11.16: The problem setter could not stand the statement written years ago, so here is a formal statement.

Define the weight of a sequence as the number of distinct elements in it +1+1. For example, the weight of [1,9,2,6,8,1,7][1,9,2,6,8,1,7] is 77.

For all integer sequences whose length [0,m]\in[0,m] and each number [1,n]\in [1,n], compute the sum of their weights modulo 109+710^9+7.

Input Format

This problem has multiple test cases.

The first line contains an integer TT, the number of test cases.

For each test case, input two positive integers n,mn,m, representing the number of item types and the number of redemption coupons.

Output Format

Output TT lines in total. Each line contains one positive integer, the number of outcomes modulo 109+710^9+7.

5
2 1
2 2
3 3
114 514
1919810 7872754
5
15
115
338602801
30498159

Hint

[Sample Explanation]

The following are all possible outcomes for the second test case:

Assume the two items are AA and BB.

  1. Exchange for 229028229028 coins.
  2. Exchange for 114514114514 coins, obtain an AA trial card.
  3. Exchange for 114514114514 coins, obtain a BB trial card.
  4. Exchange for 114514114514 coins, obtain an AA permanent item.
  5. Exchange for 114514114514 coins, obtain a BB permanent item.
  6. First obtain an AA trial card, second obtain an AA trial card.
  7. First obtain an AA trial card, second obtain a BB trial card.
  8. First obtain a BB trial card, second obtain an AA trial card.
  9. First obtain a BB trial card, second obtain a BB trial card.
  10. First obtain an AA trial card, second obtain an AA trial card, designate AA as the permanent item.
  11. First obtain an AA trial card, second obtain a BB trial card, designate AA as the permanent item.
  12. First obtain a BB trial card, second obtain an AA trial card, designate AA as the permanent item.
  13. First obtain an AA trial card, second obtain a BB trial card, designate BB as the permanent item.
  14. First obtain a BB trial card, second obtain an AA trial card, designate BB as the permanent item.
  15. First obtain a BB trial card, second obtain a BB trial card, designate BB as the permanent item.

[Constraints]

  • Subtask 1 (10 pts): n,m5,T25n,m\leq5,T\le25.
  • Subtask 2 (10 pts): n=1n=1.
  • Subtask 3 (10 pts): m=1m=1.
  • Subtask 4 (20 pts): n,m1000,T5n,m\leq1000,T\leq 5.
  • Subtask 5 (20 pts): m106\sum m\leq10^6.
  • Subtask 6 (30 pts): no special restrictions.

For 100%100\% of the testdata, 1n,m1091\le n,m\leq 10^9 and 1T1051\le T\leq 10^5.

Translated by ChatGPT 5