Killjee and Sum

3.7

7 votes
Mathematics, Medium, Lucas's theorem
Problem

Killjee loves playing with numbers. Recently, his friend, Sam, gave him 3 numbers N, M, and R and asked him to find a magic value of these numbers.

The magic value of three numbers = (R1i=1(Ni)(M(Ri))i(Ri))%(107+19).

INPUT FORMAT

The first line of input contains a single integer T denoting the number of test cases. T line follows each containing 3 space separated integers N, M, and R.

OUTPUT FORMAT

For each test case, print the magic value in new line.

INPUT CONSTRAINTS

  • 1N,M1018
  • R(N+M)
  • 1T100
Time Limit: 4
Memory Limit: 256
Source Limit:
Explanation

For first test case magic value = (3 choose 1) * (2 choose 1) * (1) * (1), which is eqaul to 6.

Editor Image

?