**Physical Address**

304 North Cardinal St.

Dorchester Center, MA 02124

Yesterday, puppy Tuzik learned a magically efficient method to find the sum of the integers from **1** to **N**. He denotes it as **sum(N)**. But today, as a true explorer, he defined his own new function: **sum(D, N)**, which means the operation **sum** applied **D** times: the first time to **N**, and each subsequent time to the result of the previous operation.

For example, if **D = 2** and **N = 3**, then **sum(2, 3)** equals to **sum(sum(3)) = sum(1 + 2 + 3) = sum(6) = 21**.

Tuzik wants to calculate some values of the **sum(D, N)** function. Will you help him with that?

The first line contains a single integer **T**, the number of test cases. Each test case is described by a single line containing two integers **D** and **N**.

For each testcase, output one integer on a separate line.

**1**≤**T**≤**16****1**≤**D, N**≤**4**

```
Input:
2
1 4
2 3
Output:
10
21
```

```
#include <iostream>
using namespace std;
int main() {
int t,d,n;
cin>>t;
while(t--)
{
cin>>d>>n;
int sum=(n*(n+1))/2;
while(d!=1)
{
sum=(sum*(sum+1))/2;
d--;
}
cout<<sum<<endl;
}
return 0;
}
```

```
#Solution Provided by Sloth Coders
T = int(input())
for _ in range(T):
a, b = map(int, input().split())
for i in range(0, a):
b = (b *(b +1)) // 2
print(b)
```

```
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static int sum(int b, int res) {
if (b == 0 ) return res;
return sum(b-1, res+b);
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int a = sc.nextInt();
int b = sc.nextInt();
for (int i = 0; i < a; i++) {
b = sum(b, 0);
}
System.out.println(b);
}
}
}
```

In our experience, we suggest you solve this Puppy and Sum CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Puppy and Sum CodeChef Solution

I hope this Puppy and Sum CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

**More Coding Solutions >>**