#include <bits/stdc++.h>

using namespace std;

// Optimization stuff
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("debug.in", "r", stdin);
    #endif // ONLINE_JUDGE
}

inline void optimizeIt() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
}
// End optimization stuff

inline double ABS(const int &x) {
    return max(x, -x);
}

inline bool isPrime(const int &x) {
    if(x == 1) return false;

    for(int d = 2; d * d <= x; d++) {
        if(x % d == 0) return false;
    }

    return true;
}

inline int GCD(int a, int b) {
    while(b) {
        int r = a % b;
        a = b;
        b = r;
    }
    return a;
}

typedef long long int ll;
typedef long double ld;

const int NMax = 1e3 + 5;
const int LIM = 1e3;
const int MOD = 1e9 + 7;

int main(){
    debugMode();
    optimizeIt();

    int t;
    cin >> t;

    while(t--) {
        int a, b;
        cin >> a >> b;

        int ans = 0;
        if(a == 1) ans++;

        int i;
        for(i = 1; (1 << i) <= b; i++) {
            int lo = (1 << i);
            int hi = (1 << (i + 1)) - 1;

            lo = max(a, lo);
            hi = min(b, hi);

            int d = hi - lo + 1;
            if(lo <= b && hi >= a) ans = (ans + (1LL * d * (d + 1) / 2)) % MOD;
        }

        cout << ans << "\n";
    }
    return 0;
}