RECFUN - Recursive function

no tags 

 

Alice loves mathematics. She recently got a Laptop and so is excited to solve her crazy mathematics problems using her Lappy.
One day, she discovered something known as RecursiveSum. RecursiveSum is a recursive function defined as:
    * RecursiveSum(0 , n) = n, for all n > 0.
    * RecursiveSum(k , n) = RecursiveSum(k-1 , 1) + RecursiveSum(k-1 , 2) + ... + RecursiveSum(k-1 , n), for all positive k, n.
She wants to make a program that can find recursive sum for any given pairs of k and n. She has no coding experience yet, so she wants you to solve this problem for her. Given k and n, your task is to write a code that can return the value for RecursiveSum(k , n)

Alice loves mathematics. She recently got a Laptop and so is excited to solve her crazy mathematics problems using her Lappy.

One day, she discovered something known as RecursiveSum. RecursiveSum is a recursive function defined as:

1. RecursiveSum(0,n) = n, for all n > 0.

2. RecursiveSum(k,n) = RecursiveSum(k-1,1) + RecursiveSum(k-1,2) + ... + RecursiveSum(k-1,n), for all positive k, n.

She wants to make a program that can find recursive sum for any given pairs of k and n. She has no coding experience yet, so she wants you to solve this problem for her. Given k and n, your task is to write a code that can return the value for RecursiveSum(k , n).

Input

First line of input consists of an integer T <= 200 which is the number of test cases. Each test case consists of two integers k and n (1 <= k <=14 and 1 <= n <= 14).

Output

For each test case, output a single line containing the integer RecursiveSum(k,n). The output is gauranteed to fit in 32-bit integer.

Example

Input:
4
1 3
5 1
4 10
8 6
Output:
6
1
2002
2002

hide comments
dewa251202: 2018-09-10 18:39:23

Memoization!


Added by:Mahesh Chandra Sharma
Date:2011-01-07
Time limit:0.294s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:C CSHARP C++ 4.3.2 CPP C99 JAVA PHP PYTHON PYTHON3 RUBY SCALA
Resource:Based on a topcoder problem