Chiaki Sequence Revisited

자기 참조 점화식으로 정의된 수열 a_n에서 n이 최대 10^18일 때 첫 n개 항의 합을 10^9+7로 나눈 나머지를 구한다.

어려움9수학조합론동적 계획법구현아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

Chiaki is interested in an infinite sequence a_1,a_2,a_3,...a\_1, a\_2, a\_3, ..., which is defined as follows: 

a_n={1n=1,2 a_na_n1+a_n1a_n2n3a\_n=\begin{cases}1 & n = 1,2 \\\ a\_{n - a\_{n-1}} + a\_{n-1 - a\_{n-2}} & n \ge 3\end{cases}

Chiaki would like to know the sum of the first nn terms of the sequence, i.e. _i=1na_i\sum\limits\_{i=1}^{n}a\_i. As this number may be very large, Chiaki is only interested in its remainder modulo (109+710^9 + 7).

입력

There are multiple test cases. The first line of input contains an integer TT (1T1051 \le T \le 10^5), indicating the number of test cases. For each test case:

The first line contains an integer nn (1n10181 \le n \le 10^{18}).

출력

For each test case, output an integer denoting the answer.