#include <bits/stdc++.h>

using namespace std;

int n, q, one, two, x, y, i;
long long ans;

int main()
{
 //   freopen("input", "r", stdin);
 //   freopen("output", "w", stdout);

    cin >> q;
    while(q--)
    {
        cin >> x >> y;
        ans = 0;

        for(i=0; i<30; ++i)
        {
            one = (1<<i);
            two = (1<<(i+1)) - 1;

            one = max(one, x);
            two = min(two, y);

            if(one<=two) ans += 1LL * (two-one+1) * (two-one+2) / 2;
        }

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

    return 0;
}