#include <iostream>
using namespace std;
typedef long long LL;
const int P = 1e9 + 7;
LL qpow(int b,int c){
if(c == 0) return 1;
LL res = 1 % P;
while(c){
if(c & 1){
res = res * b % P;
}
b = (long long)b * b % P;
c = c >> 1;
}
return res;
}
int main() {
int t;
cin>>t;
while(t--){
int a,b;
cin>>a>>b;
a = (a % P + P) % P;
long long res = a * qpow(b,P - 2) % P;
cout<<res<<"\n";
}
}
// 64 位输出请用 printf("%lld")

京公网安备 11010502036488号