#include using namespace std; const int mod = 1e9 + 7; int main() { int t, x, y; cin >> t; while (t --) { cin >> x >> y; int p2 = 1; while (p2 < y) p2 *= 2; long long ans = 0; while (p2 >= 1) { int cate = y - max(p2, x) + 1; if (cate >= 1) { ans = (ans + 1LL * cate * (cate + 1) / 2) % mod; } y = min(y, p2 - 1); p2 /= 2; } cout << ans << "\n"; } return 0; }