#include<bits/stdc++.h>
using namespace std;
using ui=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128_t;
using u128=__uint128_t;
using ld=long double;
const ll mod=1e9+7;
ll power(ll a,ll b,ll p)
{
ll ans=1;
while(b>0)
{
if((b&1)==1) ans=(ans*a)%p;
a=(a*a)%p;
b>>=1;
}
return ans;
}
void solve()
{//利用乘法快速幂求出b在mod1e9+7下的逆元 然后取模计算即可
//注意当a<0时 可以让a加mod直到为正数
ll a,b;
cin >> a >> b;
if(a<0) while(a<0) a+=mod;
ll ans=((a%mod)*(power(b,mod-2,mod)))%mod;
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;
cin >> t;
while(t--)
{
solve();
}
return 0;
}