#P8440. Aleph-0 (Fan-made LGC 7)
Aleph-0 (Fan-made LGC 7)
Background
Rolling_Code is a girl who likes rhythm games.

Rolling_Code’s score when playing is as follows:

However, this is not an IN.
Breaking news: Rolling_Code achieved All Perfect on Aleph-0 [IN 15(15.7)]!
Problem Description
As a math teacher, LeaF has opened a series of perfect math classes. The students include: Rolling_Code, you, and Miuho. Teaching assistant: Cirno.
In the first class, there is an exam.
Students who solve this problem can get early access to a special edition of ! — LeaF
Aleph-0 (Legacy - SP Lv.?)
Rolling_Code is very interested in rhythm games, so she also really wants to get this song. But when she opened the problem statement, she was shocked:
$f(x)=\begin{cases}0&x=0\\1&x=1\\2f(\frac{x}{2})&2|x\operatorname{and} x>0 \\ 2f(\frac{x-1}{2})+\frac{2}{x-1}f(\frac{x-1}{2})+x&\text{otherwise}\end{cases}$
Compute $S=\left(\sum\limits_{i=0}^{r} f^k(i)\right)\bmod (10^9+7)$.
Here, .
Originally, the answer for was desired, but unfortunately it is not defined, so the range of is made smaller. — LeaF
For some reason, LeaF defines .
To make it more interesting, LeaF also added multiple queries for .
Rolling_Code cannot solve it, so she asks you for help.
Input Format
This problem has multiple test cases.
The first line contains an integer , the number of test cases.
The next lines each contain two integers , meaning the in the -th query.
Output Format
For each test case, output one integer , the answer to the -th query.
5
1 2
14 2
51 2
4 2
1919810 2
1
6480
495741
57
936062395
5
43752 25
26701 25
43734 25
37553 25
67839 25
252345090
86394269
406573405
129371352
118835650
Hint
This problem uses bundled testdata.
This problem has multiple test cases.
For of the testdata, it is guaranteed that .
Subtask 1: For of the testdata, it is guaranteed that .
Subtask 2: For of the testdata, it is guaranteed that , depends on Subtask 1.
Subtask 3: For of the testdata, it is guaranteed that , and is a fixed value.
Subtask 4: For of the testdata, it is guaranteed that .
Subtask 5: For the last of the testdata, there are no special constraints, depends on Subtask 1, 2, 3, 4.
Sample Explanation
.
For , .
Translated by ChatGPT 5