#include <cstdio>
#include <algorithm>

#define MOD 1000000007LL

using namespace std;

long long calc (int val)
{
    return 1LL * val * (val + 1) / 2LL;
}

int main ()
{
   // freopen ("file.in", "r", stdin);

    int q;
    scanf ("%d", &q);

    for (; q; --q)
    {
        long long rez = 0LL;

        int x, y;
        scanf ("%d %d", &x, &y);

        int p1 = 1, p2 = 2;
        for (; p1 <= x; p1 *= 2, p2 *= 2);

        p1 /= 2;
        p2 /= 2;

        if (p2 > y) rez = calc (y - x + 1) % MOD;
        else
        {
            rez = calc (p2 - x) % MOD;

            p1 *= 2, p2 *= 2;
            for (; p2 <= y; p1 *= 2, p2 *= 2)
                rez += calc (p2 - p1),
                rez %= MOD;

            rez += calc (y - p1 + 1);
            rez %= MOD;
        }

        printf ("%lld\n", rez);
    }

    return 0;
}