#include <cstdio>
#include <algorithm>

inline long long gauss(int n){
    return 1LL*n*(n+1)/2;
}

int main(){
    int t;
    scanf("%d", &t);

    for(; t; t--){
        int x, y;
        scanf("%d%d", &x, &y);

        long long ans=0;
        for(int j=0; j<30; j++)
            if((x<=((1<<(j+1))-1))&&(y>=(1<<j)))
                ans+=gauss(std::min((1<<(j+1))-1, y)-std::max((1<<j), x)+1);

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

    return 0;
}