#include<bits/stdc++.h>
using namespace std;
int count_bits(int a,int b)
{
int count=0,res=0;
for(int i=a;i<=b;i++)
{
while( (i&1)!=1)
{
res=(i&1);
count=count+res;
i=i>>1;
}
}
return count;
}
int main()
{
int q,num1[q],num2[q],ans[q];
cin>>q;
for(int i=0;i<q;i++)
{
cin>>num1[i]>>num2[i];
ans[i]=count_bits(num1[i],num2[i]);
}
for(int i=0;i<q;i++)
{
cout<<ans[i]<<endl;
}
return 0;
}