#include #include using namespace std; using ll = long long; void solve(){ ll n, m; cin >> n >> m; auto pa = atcoder::crt({-m, 0}, {1'000'000'000, n}); if(pa.second == 0){ cout << "-1\n"; return; } cout << pa.first / n << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--) solve(); }