#include <iostream>
#include <cmath>

using namespace std ;

/*ifstream cin ("input") ;
ofstream cout ("output") ;*/

const long long MOD = 1e9 + 7 ;

int main(int argc, char const *argv[])
{
	int q ; 
	cin >> q ; 
	while (q --) {
		long long solution = 0 ;
		long long x, y ; 
		cin >> x >> y ; 
		while (x <= y) {
			long long highest = (long long) log2(x) ;
			long long next = (1LL << (highest + 1LL)) - 1 ;
			next = min (next, y) ;
			long long len = next - x + 1 ;
			solution = solution + len * (len + 1) / 2LL ; 
			solution %= MOD ; 
			x = next + 1 ; 
		}
		cout << solution << '\n' ;
	} 
	return 0;
}