#include using namespace std; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int T; cin >> T; while(T--){ int X=1, A, B; cin >> A >> B; if (B < A*2){ cout << -1 << endl; continue; } while(1){ if ((B+X) % (A+X) == 0){ cout << X << '\n'; break; } X++; } } return 0; }