Hongjun and balanced tables

Count the ways to fill a 3-by-C grid with nonnegative integers so that every triple of cells satisfying a + c = 2b sums to S.

Medium6CombinatoricsMathDynamic programmingImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given an empty table with 3 rows and CC columns, together with an integer SS. Hongjun writes one nonnegative integer in every cell of the table.

Take three cells, one from each of the three rows. If the center of one of them is the midpoint of the segment joining the centers of the other two, the three cells are called balanced. If the three cells lie in column aa of row 1, column bb of row 2, and column cc of row 3, this condition is the same as a+c=2ba + c = 2b. The picture below shows one balanced set of three cells when C=8C = 8.

Three balanced cells in a table with 3 rows and 8 columns

Hongjun wants to fill the table so that for every balanced set of three cells, the numbers written in those three cells add up to SS. For two tables AA and BB, let A(i,j)A(i, j) and B(i,j)B(i, j) be the numbers written in row ii and column jj. The two tables are different if A(i,j)B(i,j)A(i, j) \neq B(i, j) for at least one pair ii, jj. Given CC and SS, write a program that counts the tables Hongjun can write.

Input

The first line contains the number of test cases TT (1T1001 \le T \le 100).

Each of the next TT lines contains CC and SS (1C501 \le C \le 50, 0S500 \le S \le 50), separated by a space.

Output

For each test case, print the number of possible tables on its own line.