Task
In Minecraft, for every task completed, the player is rewarded with a certain number of experience points in the form of some green orbs, each orb rewarding the player with different amounts of experience based on its size.
An orb of size i rewards the player with xpi experience points. Where xp is defined as follows:
- xp1=1;
- xpi=prevprime(2⋅xpi−1), where prevprime(a) is the largest prime number that is smaller than or equal to a. For example, prevprime(16)=13 and prevprime(23)=23.
For instance, the first 8 sizes of orbs reward the player with: 1,2,3,5,7,13,23 and 43 experience points, respectively.
Notch, the creator of Minecraft, made it so that any non-negative integer number of experience points can be broken down as a sum of experience rewarded by orbs in the following way (here ⊕ represents array concatenation):
- Let dec(a) be an array representing the decomposition of a experience points as a sum of experience rewarded by orbs;
- dec(0)=[ ] (the empty array)
- dec(a)=[xpmax] ⊕ dec(a−xpmax), where xpmax is the largest element in xp such that xpmax≤a. For example, the decomposition of 11 is dec(11)=[7,3,1] and the decomposition of 15 is dec(15)=[13,2].
He also defined cnt(a) to be the length of the array dec(a), therefore cnt(11)=3,cnt(15)=2.
Notch wants to know the answer to q queries of the following form:
- l,r − find the sum cnt(l)l+cnt(l+1)l+1+⋯+cnt(r−1)r−1+cnt(r)r
The first line contains a single integer representing the number of queries q.
Each of the next q lines contains a pair of integers. The ith of these lines describes the ith query: li and ri.
Output data
The output contains q lines. The ith of these lines contains a single integer representing the answer to the ith query.
Constraints and clarifications
- 1≤q≤5⋅104
- 1≤li≤ri≤1012
- For tests worth 18 points, 0≤ri−li<100
- For tests worth 65 more points, 1≤li≤ri≤108
Example 1
stdin
2
5 12
1 1000000
stdout
166374097
439931963
Explanation
For the first query in the first example, the answer, starting with ans=0, can be computed as follows:
- dec(5)=[5]→ans=ans+15
- dec(6)=[5,1]→ans=ans+26
- dec(7)=[7]→ans=ans+17
- dec(8)=[7,1]→ans=ans+28
- dec(9)=[7,2]→ans=ans+29
- dec(10)=[7,3]→ans=ans+210
- dec(11)=[7,3,1]→ans=ans+311
- dec(12)=[7,5]→ans=ans+212
The total sum is ans=6229 and the output is:
229⋅modinv(6) mod 998 244 353=229⋅166 374 059 mod 998 244 353=166 374 097.
Example 2
stdin
5
11 15
5 14
3 10
12 20
7 19
stdout
166374096
166374117
499122210
499122249
665496322