Tree Sum is Fun II#11840

Tree Sum is Fun II

1.5 seconds
256 megabytes
Very hard

"Raining Trees !"

—TheFatRat - Out Of The Rain

MathModel is once again climbing "The Tree". The Tree is an infinite binary tree, rooted at , where each node (i \geq 1) has children and 2i + 1.

The uncle x = q(u) of node (u > 3) is the node that satisfies the following:

^{\dagger}p(v) = \text{parent of node } v.

^{\dagger}q(v) = \text{uncle of node } v.

It can be shown that each node has only one uncle.

MathModel draws an edge between every node and its uncle .

An -good path is any path satisfying the following conditions:

  1. The sum of nodes on the path equals .

  2. For the set of nodes u_1, u_2, \ldots, u_m, it holds that u_1 < u_2 < u_3 < \ldots < u_m and u_i \in \{p(u_{i+1}), q(u_{i+1})\}.

MathModel wants you to find the number of -good paths for a given . Since the value might be large, print it modulo 10^9 + 7.

For more clarity, check the below example:

For u = 11, its parent is p(11) = 5.

Since p(4) = p(5) = 2, and 4 \neq 5, is considered the uncle of .

For n = 18, the following paths are valid:

Input

The first line of each test case contains a single integer (1 \leq t \leq 1000) — the number of test cases.

The only line of each test case contains a single integer (3 \leq n \leq 2 \cdot 10^{18}) — the desired sum of the subtree.

Output

The count of such paths among all subtrees of "The Tree" modulo 10^9 + 7.

Examples

Example 1

Loading
Loading

Note

For the first test case, there are two valid paths for n = 6:

  1. (4 \rightarrow 2)

For the second test case, there are four valid paths for n = 7:

  1. (4 \rightarrow 3)

  2. (5 \rightarrow 2)

  3. (4 \rightarrow 2 \rightarrow 1)

For the third test case, there are five paths for n = 8:

  1. (5 \rightarrow 2 \rightarrow 1)

  2. (4 \rightarrow 3 \rightarrow 1)

  3. (5 \rightarrow 3)

  4. (6 \rightarrow 2)

Scoring

  1. Subtask ( points): 3 \leq n \leq 30, t = 1.

  2. Subtask ( points): 3 \leq n \leq 1000.

  3. Subtask ( points): 3 \leq n \leq 10^6, t = 1.

  4. Subtask ( points): 3 \leq n \leq 10^6, t \leq 100.

  5. Subtask ( points): n = 10^9.

  6. Subtask ( points): 3 \leq n \leq 10^9, t \leq 10.

  7. Subtask ( points): n \leq 2 \cdot 10^{18}, t = 1.

  8. Subtask ( points): No additional constraints