#P5509. 派遣

派遣

Description

However, these soldiers may not necessarily have the ability to fight the dark forces, so the final set of dispatched soldiers is unknown.

To better understand the dispatched soldiers, Steve needs you to help compute some values.

Steve has a total of tt armies, and each army has a different number of soldiers.

Each army can be arranged into an n×kn \times k grid under a certain standard. Each soldier’s position can be represented by coordinates (x,y)(x,y), where 0x<n0 \le x < n and 0y<k0 \le y < k. The soldier’s index is xk+yx \cdot k + y.

The soldier at position (0,0)(0,0) is the captain, and will be dispatched no matter what.

For the remaining soldiers, they may or may not be dispatched.

The ability value of an n×kn \times k army is defined as follows:

  • If all soldiers are dispatched, then the ability value is 11.
  • If the soldier at position (x,y)(x,y) (with index ii) is not dispatched, then the ability value becomes the previous value multiplied by xix\frac{x}{i-x}.

For example, for a 2×22 \times 2 army, if the soldier at (1,1)(1,1) (index 33) is not dispatched and all other soldiers are dispatched, then the ability value is 131=12\frac{1}{3-1}=\frac{1}{2}.

If both the soldier at (1,1)(1,1) (index 33) and the soldier at (0,1)(0,1) (index 11) are not dispatched, then the ability value is 131×010=0\frac{1}{3-1} \times \frac{0}{1-0} = 0.

If both the soldier at (1,1)(1,1) (index 33) and the soldier at (1,0)(1,0) (index 22) are not dispatched, then the ability value is 131×121=12\frac{1}{3-1} \times \frac{1}{2-1} = \frac{1}{2}.

Now, for each army, Steve needs you to compute the sum of the ability values over all possible dispatch plans.

To avoid fractions, output the result modulo 11451411145141.

If this value does not exist, output 1-1.

That is, if your answer is an irreducible fraction pq\frac{p}{q}, you need to find the smallest non-negative integer aa such that pqa(mod1145141)p \equiv q \cdot a \pmod{1145141}, and output aa. If no such integer exists, output 1-1.

Hint: 11451411145141 is a prime number.

Input Format

The first line contains an integer tt.

The next tt lines each contain two integers n,kn, k.

Output Format

Output tt lines, each containing one integer representing the answer.

5
2 2
3 3
1 4
2 4
3 4

3
7
1
381716
127244

Hint

The actual value for the 4th group of testdata is 73\frac{7}{3}.

The actual value for the 5th group of testdata is 559\frac{55}{9}.

Explanation for the 1st group of testdata:

If all soldiers are dispatched, then the ability value is 11.

If the soldier at (1,1)(1,1) (index 33) is not dispatched, then the ability value is 131=0.5\frac{1}{3-1}=0.5.

If the soldier at (0,1)(0,1) (index 11) is not dispatched, then the ability value is 010=0\frac{0}{1-0} = 0.

If both the soldier at (1,1)(1,1) (index 33) and the soldier at (0,1)(0,1) (index 11) are not dispatched, then the ability value is 131×010=0\frac{1}{3-1} \times \frac{0}{1-0} = 0.

If the soldier at (1,0)(1,0) (index 22) is not dispatched, then the ability value is 121=1\frac{1}{2-1} = 1.

If both the soldier at (1,0)(1,0) (index 22) and the soldier at (1,1)(1,1) (index 33) are not dispatched, then the ability value is 121×131=0.5\frac{1}{2-1} \times \frac{1}{3-1}=0.5.

If both the soldier at (1,0)(1,0) (index 22) and the soldier at (0,1)(0,1) (index 11) are not dispatched, then the ability value is 121×010=0\frac{1}{2-1} \times \frac{0}{1-0}=0.

If only the captain is dispatched, then the ability value is $\frac{1}{3-1} \times \frac{0}{1-0} \times \frac{1}{2-1}=0$.

So, the answer is 1+0.5+0+0+1+0.5+0+0=31+0.5+0+0+1+0.5+0+0=3.

Constraints:

For all testdata, n1,k2n \ge 1, k \ge 2.

Subtask 1 is the testdata used during the contest:

Test point Score tt nn \le kk \le
1 10 5
2 11 100
3 12 100000 5 100000
4 13 100000 5
5 16 5 100000
6 18 10910^9
7 20 100000

Subtask 2 includes two unscored hack testdata, both satisfying t=1t=1.

#8 satisfies the properties of #7.

#9 satisfies the properties of #5.

Translated by ChatGPT 5