#include <bits/stdc++.h>

using namespace std;
int main() {
	int q;
	scanf("%d", &q);
	while (q--) {
		int a, b;
		scanf("%d %d", &a, &b);
		int r = sqrt(1LL * a * b);
		int res = 2 * r;
		if (1LL * r * r == 1LL * a * b) { // square root not counted
			res -= 2 + (a < r) + (b < r);
		} else if (r * (r + 1LL) >= 1LL * a * b || a == r + 1 || b == r + 1) { // square root counted once
			res -= 1 + (a <= r) + (b <= r);
		} else {
			res -= (a <= r) + (b <= r);
		}
		printf("%d\n", res);
	}
	return 0;
}
