cswork / OAOpen practice workspace

IBMOA #20

Find Arrangements

Estimated HardJudge-ready

Topics (AI-labelled)State MachinesPrefix & Ranges

Schedule exactly P physics classes and C chemistry classes so that the same subject never appears more than N times in a row; find the number of distinct subject sequences modulo 1000000007. Each line is an independent test, and classes of the same subject have no individual identities.

Input

The first line contains T, followed by T lines of P C N. Full source ranges: 1≤T≤100, 1≤P,C,N≤1000.

Output

Output T integers in input order, one result per line, each modulo 1000000007.

Example 1

Input:

1
1 1 2

Output:

2

Example 2

Input:

1
1 2 1

Output:

1

Example 3

Input:

2
3 1 1
2 2 1

Output:

0
2

Example notes

The example outputs are 2, 1; and 0 2 respectively.

Editorial

Loading solution…