Timer is Running

Modified Fibonacci
Submissions: 1004   Accuracy:


  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 (109+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 <= 100
1 <= A,B,C <= 109
1 <= n <= 1012

Input :
2 2 3 4
3 2 3 4

Output :

** 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.