#include #include #include #include #include #include #include using namespace std; #define x first #define y second #define NMAX 105 #define INF 1000000007 int q, a, b, last; long long answer; int main (){ scanf("%d",&q); for(int i = 1; i <= q; i++) { scanf("%d%d",&a,&b); int step = 1; for(int j = 1; j - 1 <= b; j *= 2){ if(j - 1 < a) continue; if(step == 1) { answer += ((long long)j - a) * (j - a + 1) / 2; step = 2; } else { answer += ((long long)j / 2) * (j / 2 + 1) / 2; } last = j; // printf("%d a = %d b = %d j = %d ans = %lld\n", q,a,b,j,answer); } if(last >= a) answer += ((long long)b - last + 1) * (b - last + 2) / 2; else answer += ((long long)b - a + 1) * (b - a + 2) / 2; printf("%lld\n", answer); answer = 0; last = 0; } return 0; }