#include using namespace std; const int MOD = 1000 * 1000 * 1000 + 7; long long Gauss(long long n) { return 1LL * n * (n + 1) / 2; } long long NextPow(int n) { long long x = 1; while(x <= n) x *= 2; return x; } int main() { // for(int i = 0; i < 100; ++i) { // int sum = i, j = i; // while(sum > 0) { // sum &= ++j; // } // // printf("%d\n", j); // } int q; scanf("%d", &q); while(q--) { long long x, y; scanf("%lld%lld", &x, &y); // if(y - x <= 20) { // int cost = 0; // for(int i = x; i <= y; ++i) { // int sum = i, j = i; // while(j <= y && sum > 0) { // cost++; // sum &= ++j; // } // } // printf("%d\n", cost); // } long long aux = NextPow(x), last = x; int answer = 0; while(aux <= NextPow(y)) { long long a = last, b = min(y, aux - 1); long long q = Gauss(b - a + 1); answer += q % MOD; answer %= MOD; last = aux; aux *= 2; } printf("%d\n", answer); } }