Under construction

Still being built. Things may change

Permutation Descent Counts

Time limit2sMemory limit512 MB

Summary
Count permutations of order N with exactly v descents, modulo 1001113, for up to 1000 queries with N at most 100.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Math, Prefix sum
Solved
No attempts yet

Problem

For a positive integer NN, a permutation of order NN is a one to one function from the set of integers 1 through NN onto itself. Such a function pp is written as the list of its values, [p(1) p(2) ... p(N)].

For example, [5 6 2 4 7 1 3] is the function on {1, ..., 7} that sends 1 to 5, 2 to 6, and so on through 7 to 3.

A descent of a permutation pp is an integer kk with p(k)>p(k+1)p(k) > p(k+1). The permutation [5 6 2 4 7 1 3] has a descent at 2 (6 > 2) and at 5 (7 > 1).

Let des(p)\mathrm{des}(p) be the number of descents of pp, so des\mathrm{des} of [5 6 2 4 7 1 3] is 2. The identity permutation is the only permutation with des(p)=0\mathrm{des}(p) = 0, and the reversing permutation given by p(k)=N+1−kp(k) = N+1-k is the only permutation with des(p)=N−1\mathrm{des}(p) = N-1.

The permutation descent count PDC(N,v)\mathrm{PDC}(N, v) is the number of permutations pp of order NN with des(p)=v\mathrm{des}(p) = v. For order 3:

  • PDC(3,0)=1\mathrm{PDC}(3, 0) = 1, counting [1 2 3]
  • PDC(3,1)=4\mathrm{PDC}(3, 1) = 4, counting [1 3 2], [2 1 3], [2 3 1], [3 1 2]
  • PDC(3,2)=1\mathrm{PDC}(3, 2) = 1, counting [3 2 1]

Compute PDC(N,v)\mathrm{PDC}(N, v) for the given NN and vv. The counts get very large, so the answer and every intermediate value are taken modulo 1001113.

Input

The first line contains one integer PP (1≤P≤10001 \le P \le 1000), the number of data sets that follow. Every data set is processed in the same way and independently of the others.

Each data set is one line. It contains the data set number KK, then the order NN (2≤N≤1002 \le N \le 100), then the value vv (0≤v≤N−10 \le v \le N-1).

Output

Print one line for each data set. The line holds the data set number KK, a single space, and PDC(N,v)\mathrm{PDC}(N, v) modulo 1001113 as a decimal integer.

Examples4

  1. Example 1

    Input
    4
    1 3 1
    2 5 2
    3 8 3
    4 99 50
    
    Expected output
    1 4
    2 66
    3 15619
    4 325091
    
  2. Example 2

    Input
    1
    1 2 0
    
    Expected output
    1 1
    
  3. Example 3

    Input
    6
    1 6 0
    2 6 1
    3 6 2
    4 6 3
    5 6 4
    6 6 5
    
    Expected output
    1 1
    2 57
    3 302
    4 302
    5 57
    6 1
    
  4. Example 4

    Input
    3
    1 3 0
    2 3 1
    3 3 2
    
    Expected output
    1 1
    2 4
    3 1