#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#define mp make_pair
#define pb push_back
#define LL long long
#define inf 2e9
#define zeros x^(x-1)&x
#define MOD 1000000007
using namespace std;

LL X,Y;

LL _max(LL a,LL b)
{
    if (a>b)
        return a;
    return b;
}

LL _min(LL a,LL b)
{
    if (a<b)
        return a;
    return b;
}
LL calc(LL x,LL y,LL k)
{
    LL rez = 0;
    if (y>1)
        rez = calc(x/2,y/2,k*2);
    if (x==0)
    {
        if (y<3)
            k = Y-k+1;
        else
            k = k-1;
        return (1LL * rez  + ((1LL*k*(k+1) / 2) % MOD))%MOD;
    }
    else if (x==1)
    {
        k = _max(0,_min(k*2-1,Y) - X+1);
        return (1LL * rez  + ((1LL*k*(k+1) / 2) % MOD))%MOD;
    }
    else
        return rez;
}
int main()
{
    int t;
    cin>>t;
    while (t--)
    {
        cin>>X>>Y;


        cout<<calc(X,Y,1)<<'\n';
    }
    return 0;
}