1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<stdlib.h>
5 #include<string.h>
6 #include<queue>
7 #include<stack>
8 using namespace std;
9 typedef long long LL;
10 LL ans[66];
11 LL bns[66];
12 LL ask(LL n);
13 int main(void)
14 {
15 LL i,j,k;
16 ans[1]=1;
17 LL ak=2;
18 bns[1]=1;
19 for(i=2; i<=60; i++)
20 {
21 ak*=2;
22 ans[i]=ans[i-1]*2;
23 bns[i]=ak-1;
24 }
25 LL n,m;
26 int s;
27 cin>>s;
28 for(i=0; i<s; i++)
29 {
30 scanf("%lld %lld",&n,&m);
31 printf("%lld\\n",ask(m)-ask(n-1));
32 }
33 return 0;
34 }
35 LL ask(LL n)
36 {
37 int i;
38 LL sum=0;
39 if(n==0)return 0;
40 for(i=1; i<=60; i++)
41 {
42 if(bns[i]>=n)
43 break;
44 }
45 if(n==bns[i])
46 {
47 return ans[i];
48 }
49 else
50 {
51 LL cc=n-bns[i-1];
52 return cc+ask(2*bns[i-1]-n+1);
53 }
54 }