import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln

void main() {
	int q;
	scanf("%d", &q);
	foreach (i; 0..q) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a > b) swap(a,b);
		int l = 0, r = b;
		while (l+1 < r) {
			int x = (l+r)/2;
			bool judge(long a, long b, long x) {
				// (x..1) * (a+1..a+x) < a*b
				if (x*(a+1) >= a*b) return false;
				if (1*(a+x) >= a*b) return false;
				long l = (x+a+1)/2;
				long r = (x+a+1)-l;
				if (l > x) return true;
				if (r < a+1) return true;
				if (l*r >= a*b) return false;
				return true;
			}
			if (judge(a, b, x)) l = x;
			else r = x;
		}
		writeln(l + (a-1));
	}
}
