Under construction

Still being built. Things may change

Crazy Malvika discovers Crazy Fibonacci function

Interview

Time limit1sMemory limit1024 MB

Summary
Given f(1)=A, f(2)=B, and f(x)=f(x-1)+f(x+1), find f(N) modulo 10^9+7 for up to 10^5 queries.
Level

Medium4 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Malvika was getting bored of the usual Fibonacci problems, so she added a twist. She defined a new function f() with these properties:

  • You are given two integers, A and B. f(1) is A and f(2) is B.
  • For every integer x ≥ 2, f(x) = f(x-1) + f(x+1).

You are given an integer N. Find f(N). Output the answer modulo 109+710^9+7.

Input

The first line contains a single integer T, the number of test cases.

Each test case is one line with three integers A, B, and N, where A is f(1), B is f(2), and N is the query.

Output

For each test case, print one line containing f(N).

Constraints

  • 1≤T≤1051 \le T \le 10^5
  • −109≤A,B≤109-10^9 \le A, B \le 10^9
  • 1≤N≤1091 \le N \le 10^9

Hint

In the first test case, f(3) = 7, so that is the output.

In the second test case, f(3) = -6, and the answer modulo 109+710^9+7 is 1000000001.

Examples1

  1. Example 1

    Input
    2
    10 17 3
    23 17 3
    
    Expected output
    7
    1000000001