#include #include const unsigned long long MOD = 1000000007; using namespace std; int Q; unsigned long long x,y; unsigned long long total; unsigned long long pow2; int main() { cin >> Q; while(Q--) { cin >> x >> y; total = (y-x+1) * (y-x+2) / 2; pow2 = 2; while (pow2 <= y) { if (pow2 >= x) { unsigned long long cont; cont = pow2-x; total -= (y-x+1 -cont); } pow2 *= 2; } cout << total % MOD << "\n"; } return 0; }