#include using namespace std; typedef long long LL; const int nmax = 1000010; const LL mod = 1000000007; int N,a[nmax],bit[25]; LL k,lg,pr,ans; int main(void){ int i,j,aux,x,y; // freopen("txt.in","r",stdin); // freopen("txt.out","w",stdout); ios::sync_with_stdio(false); cin >> N; while(N--){ cin >> x>>y; pr = x; ans=0; for(k = 2;k<=y;k*=2) if(k>=x){ lg = k-pr; ans+=lg+1; if(pr!=x)--ans; ans%=mod; // cout << lg <<' '; LL w = lg*(lg-1)/2; w%=mod; ans+=w; ans%=mod; pr=k; } // cout << ans <<' '; if(pr!=y){ lg = y-pr+1; // if(pr==x)++lg; ans+=lg; if(pr!=x)--ans; ans%=mod; LL w = lg*(lg-1)/2; w%=mod; ans+=w; ans%=mod; } cout << ans%mod << '\n'; } return 0; }