 Modified Fibonacci
Submissions: 880   Accuracy: 12.02%   Difficulty: Easy   Marks: 2

Given a number n,  print the value of F(n) given that

F(1) = A + B and
F(2) = B + C.

Here A, B and C are integer inputs provided to the program.
For n > 2, F(n) = F(n-1) - F(n-2)

Since F(n) can be large, print the answer modulo (10^9+7).

Input :
The first line contains integer T, denoting number of test cases.Then T test cases follow. The first line of each test case contains integer N A B C, denoting the number and values of constant A,B,C respectively.

Output :
Print the answer of each test case in a new line.

Constraints :
1 <= T <= 10
1 <= A,B,C <= 10^9
1 <= n <= 10^12

Example:
Input :
2
2 2 3 4
3 2 3 4

Output :
7
2

** For More Input/Output Examples Use 'Expected Output' option **

Author: Sonesh Shukla

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.