All Tracks Problem

Find the term
Tag(s):

Hard, Math

Problem
Editorial
Analytics

The \( n^{th}\) term of a mathematical series is described as follows:

\( K_{n} = K_{n-1} - K_{n+1}\)

You have to find the \(m^{th}\) term, given the first two terms \(K_{1}\) and \(K_{2}\) of the series.

Input format:
The first line contains T, which denotes the number of test cases, after which T test cases follow.
Each test case is made up of two lines. The first line contains \(K_{1}\) and \(K_{2}\), the first two terms of the series. The second line contains m, for which \(K_{m}\) has to be calculated.

Output format:
T lines each containing the value of \(K_{m}\) for the corresponding test case. Since the value of \(K_{m}\) can be large, print the value modulo \(10^9 +7\).

Input constraints:
\(1 \leq T \leq 10^5\)
\(1 \leq N \leq 2 \times 10^9\)
\(|K_1| \leq 10^9\)
\(|K_2| \leq 10^9\)

SAMPLE INPUT
2
4 2
3
6 7
2
SAMPLE OUTPUT
2
7
Explanation

In Test case 1:

\(K_3 = K_1 - K_2 = 4 - 2 = 2\)

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

Relapse_2

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?