#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <set>
#define Inf (1ll<<60)
#define MAXX 30000
#define ll long long
using namespace std;


int Ao[1111111];
int Bo[1111111];

int A,B;

void Solve(int pos, int maxscore, set<int>* Boset, int* worse_case_count) {
    
    
    if (pos-1 > *worse_case_count) {
        *worse_case_count = pos-1;
        for(int i=1;i<=pos-1;i++)
            printf("%d,%d ",Ao[i],Bo[i]);
        printf("\n");
        return;
    }
    
    
    
    if (Ao[pos-1]+1 > maxscore)
        return;
    
    
    
    
    
    
    for(int a=Ao[pos-1]+1;a<=20;a++) {
        for(int b=1;b<=20;b++) {
            if (a == A || b == B || Boset->find(b) != Boset->end())
                continue;
            if (a*b > maxscore)
                break;
            
            Boset->insert(b);
            
            
            Ao[pos]=a;
            Bo[pos]=b;
            Solve(pos+1,maxscore,Boset,worse_case_count);
            Boset->erase(b);
            
        }
    }
    
    
}

int Solve(int A,int B) {
    
    int prod = A*B;
    
    set<int> Ao,Bo;
    vector<int> Aovec,Bovec;
    for(int p=prod-1;p>=1;p--) {
        for(int a=1;a<=p;a++) {
            if (p%a==0) {
                int b = p/a;
                if (Ao.find(a) != Ao.end() || Bo.find(b) != Bo.end() || a==A || b==B)
                    continue;
                Ao.insert(a);
                Bo.insert(b);
                Aovec.push_back(a);
                Bovec.push_back(b);
            }
        }
    }
    
    /*
    for(int i=0;i<Aovec.size();i++)
        printf("%d,%d ",Aovec[i],Bovec[i]);
    cout << endl;
    
    
    
    
    set<int> already;
    for(int a=1;a<=prod-1;a++) {
        
        if (a==A)
            continue;
        
        int b = (prod-1)/a;
        
        if (already.find(b) != already.end())
            continue;
        
        already.insert(b);
        
    }
    
    printf("%d vs %d\n",(int)Ao.size(),(int)already.size());
    */
    return Ao.size();
    
    
}


int SolveEle(ll A,ll B) {
    
    
    ll a = 1;
    ll prod = A*B;
    int ans=0;
    
    // (prod-1)/na and (prod-1)/(na+1)
    
    
    // sum_{a=1 to prod-1}
    
    while(a <= prod-1) {
        
        // find largest na such that
        // (prod-1)/na-(prod-1)/a
        
        // a to na has the same b
        
        // (prod-1)/a == (prod-1)/na
        // (prod-1)/na >= x
        // na <= (prod-1)/x
        
        
        
        
        
        ll x = (prod-1)/a;
        
        ll na = (prod-1)/x;
        
        // a to na
        ans++;
        printf("%lld to %lld  :: %lld %lld\n",a,na,(prod-1)/a,(prod-1)/na);

        a=na+1;
        
    }
    if (A != B)
        ans--;
    return ans;
}


int Count(ll prod) {
    ll a = 1;
    int ans=0;
    
    // (prod-1)/na and (prod-1)/(na+1)
    
    
    // sum_{a=1 to prod-1}
    
    while(a <= prod-1) {
        
        // find largest na such that
        // (prod-1)/na-(prod-1)/a
        
        // a to na has the same b
        
        // (prod-1)/a == (prod-1)/na
        // (prod-1)/na >= x
        // na <= (prod-1)/x
        
        
        
        
        
        ll x = (prod-1)/a;
        
        ll na = (prod-1)/x;
        
        // a to na
        ans++;
        
        a=na+1;
        
    }
    return ans;
    
    
}


int main() {
    /*
    int prev = -1;
    for(int x=1;x<=1000;x++) {
        int curr = Count(x);
        if (curr != prev)
            printf("%d :: %d\n",x,curr);
        prev=curr;
    }
    
    
    for(int n=1;n<=1000;n++) {
        printf("%d\n",(n*n)/4+1);
    }
     */
    
    
    int Q;
    cin>>Q;
    for(int q=1;q<=Q;q++) {
        ll A,B;
        cin>>A>>B;
        
        ll low = 1;
        ll high = (1ll<<31)-1;
        while(low < high) {
            ll mid = (low + high + 1)/2;
            
            
            if ((mid*mid)/4+1 > A*B) {
                high=mid-1;
            } else {
                low=mid;
            }
            
            
        }
        
        printf("%lld\n",low-1-(A!=B));
        
        
        
    }
    return 0;
    
    while(1) {
        //cin>>A>>B;
        A=rand()%100+1;
        B=rand()%100+1;
        int worse_case_count=0;
        //Solve(1,A*B-1,&Boset,&worse_case_count);
        //cout << Solve(A,B) << endl;
        //cout << SolveEle(A,B) << endl;
        if (Solve(A,B) != SolveEle(A,B))
        printf("%d vs %d\n",Solve(A,B),SolveEle(A,B));
    }
    
}

Measured memory_bytes: 256