#include #include using namespace std; const int MOD = 1000000007; int main() { //freopen("txt.in", "r", stdin); int64_t q, a, b; int64_t total = 0; cin >> q; while(q--) { cin >> a >> b; int64_t p2 = 1; int64_t last = a; while(p2 <= b) { if(p2 > a) { total = (total + (int64_t) ((p2 - 1 - last + 1) * (p2 - 1 - last + 2) / 2) % MOD) % MOD; last = p2; } p2 = 2 * p2; } total = (total + (int64_t) ((b - last + 1) * (b - last + 2) / 2) % MOD) % MOD; cout << total << "\n"; total = 0; } return 0; }