Freaky Function

0

0 votes
Easy
Problem

You are given two positive functions  f(n) and g(n) defined as follows:

f(n)=ng(n1)+(n1)g(n2)+...+2g(1)+g(0)

g(n)=nf(n1)+(n1)f(n2)+...+2f(1)+f(0)

Noteabs(n1000000007)105

You will be asked T queries. In each query you will be given three integers n,f(0),g(0). You need to calculate the value of (f(n)+g(n))mod109+7


Input
The first line contains an integer T as input.
The next T lines contain three integers n,f(0),g(0).

Output
In the output, you need to print the value of (f(n)+g(n))mod109+7.

Constraints
1T1021n1091f(0),g(0)1018

Time Limit: 4
Memory Limit: 256
Source Limit:
Editor Image

?