//Jagsxi
//This is a code trying to explain the above tutorial. Please try to code it yourself for better understanding.Submitting this will not get you AC. :)
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
vector<long> allfib;
int fibn;
vector<int> getLetty(long x)
{
// get the Letty representation of x
vector<int> res(fibn);
for (int i = fibn - 1; i >= 0; i--) {
if (x >= allfib[i]) {
res[i] = 1;
x -= allfib[i];
}
}
return res;
}
vector<int> getXorFirst(long x) // get the Fibonacci xor of 0, 1, ... x.
{
vector<int> X = getLetty(x);
vector<int> res(fibn);
for (int i = 0; i < fibn; i++) { // for each bit position i
// is the number of fibonacci numbers <= X with 1 in the i-th
// position an odd number or not?
int dp[fibn + 1][2][2];
// solve function f(j, less, last):
// j : We have assigned all positions greater than or equal to i
// less: The chosen number is already less than X
// base case j = 0
for (int less = 0; less < 2; less++) {
for (int last = 0; last < 2; last++) {
dp[0][less][last] = 1;
}
}
for (int j = 1; j <= fibn; j++) {
for (int less = 0; less < 2; less++) {
for (int last = 0; last < 2; last++) {
dp[j][less][last] = 0;
// decide position j - 1
int mx;
if ( (last == 1) || ( !less && (X[j-1] == 0) ) ) {
mx = 0;
} else {
mx = 1;
}
for (int v = 0; v <= mx; v++) {
if ( (j-1 != i) || (1 == v) ) {
// we can
int newless = (less || (v < X[j-1]) );
dp[j][less][last] ^= dp[j-1][newless][v];
}
}
}
}
}
//base cases, j = -1, j = -2
res[i] = dp[fibn][0][0];
}
return res;
}
void makeFibonacci(long T)
{
long a = 1, b = 2;
while (a <= T) {
allfib.push_back(a);
long c = a + b;
a = b;
b = c;
}
fibn = allfib.size();
//cout << fibn <<endl;
//cout << allfib[fibn-1] << " is the " << (fibn-1)<<"-th"<<" fibonacci"<<endl;
}
int find(long A, long B)
{
makeFibonacci(max(A,B));
vector<int> sb = getXorFirst(B);
vector<int> sa = getXorFirst(A - 1);
int res = 0;
for (int i = fibn - 1; i >= 0; i--) {
res = (2*res) % MOD;
if (sb[i] != sa[i]) {
res++;
}
}
return (int)(res % MOD);
}
int main()
{
int t;
cin>>t;
while(t--)
{
long A,B;
cin>>A>>B;
allfib.clear();
makeFibonacci(max(A,B));
vector<int> sb = getXorFirst(B);
vector<int> sa = getXorFirst(A - 1);
int res = 0;
for (int i = fibn - 1; i >= 0; i--) {
res = (2*res) % MOD;
if (sb[i] != sa[i]) {
res++;
}
}
cout<<res%MOD<<endl;
}
}