

Input: 'N' = 5, 'R' = 2
Output: 10
The value of 5C2 is 10
After taking the modulo with 10^9 + 7 we get 10.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the 'T' test case are as follows.
The first line of each test contains an integer 'N' and an integer ‘R’, both separated by a space.
For every ‘N’ and ‘R’, print its binomial coefficient nCr modulo 10^9 + 7.
Output for each test case will be printed in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 1000
1 <= N <= 1000
1 <= R <= 800
Where ‘N’ and ‘R’ are the constants for calculating the binomial coefficient.
Time limit: 1 sec
The key observation here is that we can the following fact that the value of C(n, k) can be recursively calculated using the following standard formula for Binomial Coefficients.
C(n, k) = C(n-1, k-1) + C(n-1, k)
C(n, 0) = C(n, n) = 1
C(n, k) = n! / (n-k)! * k! = [n * (n-1) *....* 1] / [ ( (n-k) * (n-k-1) * .... * 1) * ( k * (k-1) * .... * 1 ) ]
After simplifying, we get
C(n, k) = [n * (n-1) * .... * (n-k+1)] / [k * (k-1) * .... * 1]
i.e. , C(n, k) = C(n, n-k)
Thus, r can be changed to n-r if r > n-r