luogu#P7813. 谜

Background

I need you to give me direction.\text{I need you to give me direction.}

$\text{Even if I have to walk alone through the endless crowd.}$

To taste wind and frost for you.\text{To taste wind and frost for you.}

I wander far away.\text{I wander far away.}

I need you to give me strength.\text{I need you to give me strength.}

No matter what, I will be strong.\text{No matter what, I will be strong.}

As long as you give me hope.\text{As long as you give me hope.}

Source

Problem Description

In a number triangle of size NN:

  • Row 11 is 11.
  • Row 22 is 232\sim3.
  • Row 33 is 464\sim6.
  • Row 44 is 7107\sim10.
  •  \cdots~\cdots
  • Row NN contains NN numbers, which are N(N1)2+1N(N+1)2\frac{N(N-1)}{2}+1\sim\frac{N(N+1)}{2}.

The figure below shows a number triangle with N=5N=5.


Let (i,j)(i,j) denote the jj-th number in the ii-th row.

It is known that (i,j)(i,j) can directly reach (i+1,j)(i+1,j) or (i+1,j+1)(i+1,j+1). Conversely, (i+1,j)(i+1,j) or (i+1,j+1)(i+1,j+1) can also directly reach (i,j)(i,j).

Now choose any number as the starting point. When you continuously pass through KK distinct numbers, find the maximum possible sum of these KK numbers, modulo 109+710^9+7.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer TT, the number of queries.

The next TT lines each contain two positive integers N,KN, K.

Output Format

Output TT lines. Each line contains one integer, the answer modulo 109+710^9+7.

1
5 5
61
5
2676 1930
5148 3667
5453 4764
16734806 16332913
26943973 33293903 
909411538
587883333
823595806
727601062
965648555

Hint

Sample Explanation

For sample #1, as shown in the figure in the statement, one feasible plan is: start from 1313, $13\rightarrow9\rightarrow14\rightarrow10\rightarrow15$, with sum 13+9+14+10+15=6113+9+14+10+15=61.

Constraints

This problem uses bundled testdata.

Subtask Score NN\le KK\le
11 3030 10310^3
22 10610^6
33 10910^9 11
44 1010

For 100%100\% of the testdata: 1T1051\le T\le 10^5, $1\le\color{red}\dfrac{K+1}{2}\le N\color{black}\le10^9$.

Translated by ChatGPT 5