mod = (10**9)+7
def nextPowerOf2(n):
count = 0;
# First n in the below
# condition is for the
# case where n is 0
if (n and not(n & (n - 1))):
return n
while( n != 0):
n >>= 1
count += 1
return 1 << count
for _ in range(int(input())):
l,r=map(int,input().split())
if l==r:
print(l%mod)
else:
res = nextPowerOf2(l)
if res==l:
res = l*2
if res<=r:
ans = (l*(res-l))
else:
ans = (l*(r-l+1))
print(ans%mod)
Can someone please tell me where my code goes wrong