#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 ng = 0, ok = a + b + 1; while (ng + 1 < ok) { long long mid = (ng + ok) / 2; long long m_sq = mid * mid; if (m_sq <= a + b) { ng = mid; continue; } if (4 * a * b / (m_sq - a - b) > m_sq - a - b) { ng = mid; continue; } if (4 * a * b < (m_sq - a - b) * (m_sq - a - b)) { ok = mid; } else { ng = mid; } } cout << ok << "\n"; } }