#include <iostream>
#include <cstdio>
#include <stdlib.h>
#define ll long long
using namespace std;
ll mod=1e9+7;
ll n,l;
int main ()
{
ll tmp;
int t;
scanf ("%d",&t);
while (t--)
{
scanf ("%lld%lld",&n,&l);
if (n==1)
{
printf ("0\n");
continue;
}
ll p=l*l/4;
for (int i=0;i<32;i++)
{
tmp=(1<<i)-1;
if (tmp>=n)
{
break;
}
}
tmp%=mod;
ll ans=tmp*p%mod;
printf ("%lld\n",ans);
}
system("pause");
return 0;
}