#include <cstdio> #include <algorithm> inline long long gauss(long long n){ return n*(n+1)/2; } int main(){ int t; scanf("%d", &t); for(; t; t--){ long long x, y; scanf("%lld%lld", &x, &y); long long ans=0; for(int j=0; j<=60; j++) if((x<=((1LL<<(j+1))-1))&&(y>=(1LL<<j))) ans+=gauss(std::min((1LL<<(j+1))-1, y)-std::max((1LL<<j), x)+1); printf("%lld\n", ans); } return 0; }