#C10073. Chain Messaging

    ID: 39238 Type: Default 1000ms 256MiB

Chain Messaging

Chain Messaging

In the chain messaging problem, you are given two integers F and N. The process works as follows: initially, F people receive a message. Then, in each subsequent round (up to N rounds), every person who received the message in the previous round forwards it to F new people. However, the message can only be forwarded at most N times.

If no forwarding is allowed (N = 0), then exactly F people receive the message. Otherwise, the total number of unique recipients is given by the formula:

\(\displaystyle \sum_{i=0}^{N} F^{i}\)

Your task is to calculate the total number of unique recipients for each test case.

inputFormat

The first line contains a single integer T, the number of test cases. Each of the next T lines contains two space-separated integers: F and N.

outputFormat

For each test case, output a single line containing the total number of unique recipients.

## sample
3
2 0
1 1
2 2
2

2 7

</p>