#include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef pair P; typedef long double ld; templateistream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} templateostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} const int INF = 1001001001; int solve(){ int a, b; cin >> a >> b; if(b % a == 0){ cout << "0\n"; return 0; } int d = b - a; set se; for(int x = 1; x * x <= d; x++){ if(d % x == 0){ se.insert(x); se.insert(d / x); } } int ans = INF; for(int x : se){ int c = d / x; if(c < a) continue; chmin(ans, c - a); } if(ans == INF) cout << "-1\n"; else cout << ans << "\n"; return 0; } int main(){ int t; cin >> t; rep(_, t) solve(); return 0; }