

P(i) = P(i-1) + P(i-2) + P(i-1) * P(i-2)
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the T test cases follow.
The first line of each test case contains three space-separated integers, ‘A’, ‘B’ and ‘N’ Where ‘A’ and ‘B’ denote the prices on the first and second days respectively. ‘N’ denotes the day on which the stock price needs to be calculated.
For each test case, print a single integer, denoting the price of the stock on the ‘Nth’ day. Since the answer can be very large, calculate the answer modulo 10^9+7.
Output for each test case will be printed in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= A,B, <= 10^9
3 <= N <= 5000
Time Limit: 1sec
The approach is to simply call the function recursively to find the prices on the last day and the second last day. These two values can then be used to calculate the prices for the current day.
The approach is to store the result for smaller subproblems so that we don’t have to recalculate the result for the same subproblem multiple times. We can create a vector to store the results. First, initialize all the elements in it with a particular value. After finding the result of a subproblem, update this value at the corresponding position. Before solving the result for any subproblem, we can check whether the result for this problem has already been solved or not.
The approach is to store the result for smaller subproblems and use these values to calculate prices for the next days. We can create a vector to store the results.