dorel

Time limit: 0.4s Memory limit: 64MB Input: dorel.in Output: dorel.out

Task

Dorel, a 10th-grade student, has recently started experimenting with algorithms to place BB identical balls into CC boxes! He tried to analyze how many ways he can place the BB balls into the CC chosen boxes such that for a chosen constant KK, the algorithm he wrote on paper does not run indefinitely. His algorithm can be found written in pseudocode below:

pos ← 1
sum ← 0
while pos <= c:
    while sum != k:
        sum ← sum + nrbile[pos] + 1
        pos ← pos + 1
    sum ← 0

Task

For BB balls, CC boxes, and a constant KK, determine in how many ways we can place the balls in the boxes such that the algorithm presented above does not run indefinitely. As this number can be very large, Dorel asks you to find the result modulo 109+710^9+7.

Input data

The first line of the input file dorel.in contains the number TT, which represents the number of tests. Then, on the next TT lines, there will be 3 numbers B,CB, C, and KK with the above-mentioned significance. The tests in the input are independent of each other.

Output data

In the file dorel.out, TT numbers will be displayed on separate lines, where on line ii of the output will be the answer to the ii-th test modulo 109+710^9+7.

Constraints and clarifications

  • 1T21051 \leq T \leq 2 \cdot 10^5
  • 1B,C,K1061 \leq B, C, K \leq 10^6
  • According to the OJI regulations, the tests will be evaluated individually, so it is not necessary to pass all tests to receive points for the respective subtask.
# Points Constraints
1 20 T,B,C,K10T, B, C, K \leq 10
2 20 T10;B,C,K1 000T \leq 10; B, C, K \leq 1 \ 000
3 5 B,C,K1 000;B+C=KB, C, K \leq 1 \ 000; B + C = K
4 10 B+C=KB + C = K
5 10 B,C,K1 000B, C, K \leq 1 \ 000
6 35 No additional constraints.

Example 1

dorel.in

6
3 3 3
1 5 6 
10 10 10
5 8 1
10 2 4
961 423 346

dorel.out

4
5
43758
0
0
434187092

Explanation

For the case B=3,C=3,K=3B = 3, C = 3, K = 3 we have the following valid configurations:

  • 0,1,20, 1, 2
  • 1,0,21, 0, 2
  • 2,0,12, 0, 1
  • 2,1,02, 1, 0

For the case B=1,C=5,K=6B = 1, C = 5, K = 6 we have the following valid configurations:

  • 1,0,0,0,01, 0, 0, 0, 0
  • 0,1,0,0,00, 1, 0, 0, 0
  • 0,0,1,0,00, 0, 1, 0, 0
  • 0,0,0,1,00, 0, 0, 1, 0
  • 0,0,0,0,10, 0, 0, 0, 1

Log in or sign up to be able to send submissions!