Sum of a series

4.7

3 votes
Basics of Combinatorics, Modular arithmetic, Matrix, Combinatorics, Mathematics, Math, Number theory
Problem

You are given a function f(n,k)=s=ns=0r=nr=st=st=0(nr)(rs)(st)t(3k2)t/2I(t)(s+1)

where I(x)={1x0 (mod 4)0x1 (mod 4)1x2 (mod 4)0x3 (mod 4)

and (nr) known as Binomial Coefficient denotes the number of ways to choose an unordered subset of r elements from a fixed set of n elements.

You must find the value of f(n,k) (modulo 109+21).

Integers n and k are given to you.

Input format

  • The first line consists of a single integer T denoting the number of test cases.
  • Each of the next T lines consists of two space-separated integers n and k respectively.

Output format

The output should consist of T lines each containing a single integer corresponding to the required value f(n,k).

Print the answer modulo 109+21. If the answer is of the form PQ, then print PQ1(mod 109+21).

Constraints

1T1051n10180k1018

Sample Input
4
1 2
2 1
3 1
5 3
Sample Output
0
1000000019
499999994
4464
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first test case: f(1,2) = 0

For the second test case: f(2,1) = -2

For the third test case: f(3,1) = -6-6-9/2 = -33/2

For the fourth test case: f(5,3) = 4464

Editor Image

?