#include <bits/stdc++.h>
using namespace std;
int t,l,r,x,y,i;
long long len,s;
int main() {
  scanf("%d",&t);
  while (t--) {
    scanf("%d%d",&l,&r);
    for (s=0, i=1; i<=30; i++) {
      x=max(l,1<<(i-1));
      y=min(r,(1<<i)-1);
      if (x<=y) {
        len=y-x+1;
        s+=len*(len+1LL);
      }
    }
    printf("%lld\n",s/2);
  }
  return 0;
}