#P1939. 矩阵加速(数列)

矩阵加速(数列)

Description

Given a sequence aa, it satisfies:

$$a_x= \begin{cases} 1 & x \in\{1,2,3\}\\ a_{x-1}+a_{x-3} & x \geq 4 \end{cases}$$

Find the nn-th term of sequence aa modulo 109+710^9+7.

Input Format

The first line contains an integer TT, denoting the number of queries. Each of the following TT lines contains a positive integer nn.

Output Format

Output one non-negative integer per line, representing the answer.

3
6
8
10

4
9
19

Hint

  • For 30%30\% of the testdata, n100n \leq 100.
  • For 60%60\% of the testdata, n2×107n \leq 2 \times 10^7.
  • For 100%100\% of the testdata, 1T1001 \leq T \leq 100, 1n2×1091 \leq n \leq 2 \times 10^9.

Translated by ChatGPT 5