#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; for (int i = 0; i < n; i++) { long long a, b; cin >> a >> b; long long ans = max(0LL, (long long)(sqrt(a) + sqrt(b)) - 2); while ((ans * ans - a - b) * (ans * ans - a - b) <= 4 * a * b) { ans++; } cout << ans << "\n"; } }