Difficulty Level:


Total Submissions: 70 Accuracy:


Little Murph and knots

M hooks in a straight line are present on wall A and these are connected to N hooks (also in a straight line) on another wall B by means of ropes. There can be multiple number of ropes between any two hooks. Being bored and having nothing to do, little Murph takes K of these ropes and ties a knot (somehow! i.e. K of these ropes together forms a single knot, she doesn’t need the ropes to intersect to be able to tie them). Given the values of M, N, and K, can you help her figure out how many knots she can tie?
Assume walls to be of sufficient length to contain the given number of hooks.

Do not take into account a particular group of hooks more than once (there should be at least one different hook in any 2 groups). For example, let M=3, N=2, and K=2, and let hooks on Wall A be numbered as (A1, A2, A3) and on wall B as (B1, B2). Then joining A1 to B1 and A3 to B2 and tying a knot using these two ropes is same as joining A1 to B2 and A3 to B1 and tying a knot as both the groups (A1-B1, A3-B2) and (A1-B2, A3-B1) contains exactly same hooks.
But the groups (A1-B1, A3-B2), (A1-B1, A2-B2), (A2-B1, A3-B2) are all different.

The first line contains a single integer T denoting the number of test cases. Next T lines follow each of which contains 3 integers M, N and K as described in the problem.

For each test case, print in new line the number of knots little Murph can tie. Print your answer modulo 10^9 + 7.

1 <= T <= 1000
2 <= K, M, N <= 1000
K <= min(M, N)


4 3 3
4 3 2



The possible groups are (A1-B1, A2-B2, A3-B3), (A1-B1, A2-B2, A4-B3), (A1-B1, A3-B2, A4-B3), (A2-B1, A3-B2, A4-B3). Hence, she can tie 4 knots.

Other possible combination can be (A1-B3, A2-B1, A3-B2), (A1-B2, A2-B1, A4-B3), (A1-B3, A3-B2, A4-B1), (A2-B2, A3-B1, A4-B3).

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sajal Agrawal

Set Default Code

It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use, generate link and share the link here.