ll@t; rep(t){ ll@x,@a,@b; sortE(a,b); ll g=gcd(a,b); x%=a/g*b; wt((a/g-x/b)*2+((x+1)/+a*a<(x+1)/+b*b&&x%a)); }