不知道哪里错了

#include<cstdio>
#include<vector>
#include<cmath>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
using namespace std;
typedef long long ll;
#define maxm 102
const  int p = 1e9 + 7;
ll a[maxm],b[maxm],c[maxm];
template <typename T> void inline read(T &x) {
    ll f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
    x *= f;
}
ll len_2(ll x){
	ll res = 0;
	while(x){
		x>>=1LL,res++;
	}
	return res;
}
void _get(ll x,ll h[]){
	ll t = len_2(x);
	for(ll i = 0;i<t;++i){
		ll fpow = 1LL<<(i+1);
//		cout<<"##"<<fpow<<endl;
		ll bound = fpow>>1;
		h[i]+=x/fpow*bound;
		ll s = x%fpow;
		if(s>=bound) h[i]+=s-bound+1;
//		cout<<h[i]<<"***"<<i<<endl;
	}
}
ll mypow(ll x , ll n){
	ll res = 1;
	while( n ){
		if(n & 1LL){
			res  =res%p * (x%p)%p;
		}
		n>>=1LL,x = (x%p)*(x%p)%p;
	}
	return res ; 
} 
struct point {
	ll place ;
	ll value;
}cMp[100];
bool cmp(point x,point y){
	if(x.value!=y.value ) return x.value<y.value;
	return x.place<y.place;
}
void init(){
	memset(a,0,sizeof a);
	memset(b,0,sizeof b);
	memset(c,0,sizeof c);
	for(ll i  = 0;i<maxm ;++i) {
		cMp[i].value=0,cMp[i].place= 0;
	}
}
int main (){
/*	FILE *fin,*fout;
	fin = fopen("data.in","rb");
	fout = fopen("data.out","wb");*/
	ll T;
	read(T);
//	fscanf(fin,"%lld",&T);
	while(T--){
		init();
		ll l,r;
//		fscanf(fout,"%lld%lld",&l,&r);
		read(l),read(r);
		if(l==r) {
			cout<<r<<endl;
			continue;
		}
		_get(l-1,a),_get(r,b);
		ll _len = len_2(r);
		ll maxplace = -1,maxvalue = -1;
		for(ll i = 0;i<_len;++i){
			c[i] = b[i]-a[i];
			if(c[i]>maxvalue){
				maxvalue = c[i];
				maxplace = i;
			}
		}
		ll  t = r - l + 1LL;
		ll ans = 1;
		ll need  = t - maxvalue;
		c[0] = c[0] - need;
		ll st = (1LL<<_len)-1LL;
		for(ll  i = 0; i<_len ;++i){
			cMp[i].place = i,cMp[i].value = c[i];
		}	
		sort(cMp,cMp+_len,cmp);
		ll f = 0;
		for(ll i =0;i< _len ;++i){
			ll minus = (1LL<<cMp[i].place);
			if(cMp[i].value-f){
				
				ll h = mypow(st,cMp[i].value-f);
				if(st)	ans = ans%p*(h%p)%p;
				
				f=cMp[i].value;
			}
			st -= minus;
		}
		printf("%lld",ans%p);
	//	fprintf(fout,"%lld\n",ans%p);
		
	}
/*	fclose(fin);
	fclose(fout);*/
	return 0;
}