//	Mohib Manva
#include<bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define LOCAL 0
#define pb push_back
#define ll long long

ll po(ll a,ll b){
	ll x = 1,y=a;
	while(b>0){
		if(b%2){
			x = x*y;
			x %= mod;
		}
		y=y*y;
		y%=mod;
		b/=2;
	}
	return x;
}

int main(){
	if(LOCAL){
    	freopen("C:/Users/gold/Desktop/sublime IO/input.txt","r",stdin);
    	freopen("C:/Users/gold/Desktop/sublime IO/output.txt","w",stdout);
	}
	int T = 1;
	scanf("%d",&T);
	while(T--){
		int x,y;
		scanf("%d %d",&x,&y);
		ll num = y - x + 1;
		long long ans = 0ll;
		for(int i=30;i>=0;i--){
			//printf("%d %d\n",x,y);
			if((x&(1<<i))&&(y&(1<<i))){
				ll nums = y - x + 1ll;
				nums = (nums*(nums-1))/2;
				nums += (y-x+1ll);
				nums %= mod;
				ans += nums;
				ans %= mod;
				break;
				//puts("Hell");
			} else
			if((y&(1<<i))){
				ll y1 = (1<<i) - 1;
				ll nums = (y-y1);
				nums = (nums*(nums-1))/2;
				nums += (y-y1);
				nums %= mod;
				ans += nums;
				ans %= mod;
				y = y1;
				//printf("%d %lld\n",i,y1);
				//puts("Hell");
			}
		}	
		printf("%lld\n",ans);
	}
	return 0;	
}