#include<bits/stdc++.h>
using namespace std;
#define int long long

const int P=1e9+7;

int power(int a,int b,int p){
	int ans=1;
	b=b%p;
	while(b>0){
		if(b&1==1){
			ans=(ans*a)%p;
		}
		a=a*a%p;
		b=b>>1;
	}
	return ans;
}

int t,a,b,p=P;

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>t;
	while(t--){
		
		cin>>a>>b;
		
		int ans_b=power(b,p-2,p);
		int ans_a=(a+p)%p;
		int ans=ans_a*ans_b%p;
		
		cout<<ans<<endl;
	}
	
    return 0;
}