#include<bits/stdc++.h>
using namespace std;
long long f[100001][3],a[100001],t,w;
void abc(long long x,long long y)
{
memset(a,0,sizeof(a));
memset(f,0,sizeof(f));
t=0;
w=1;
a[x]=1;
f[1][1]=x;
f[1][2]=0;
while(t<w)
{
t++;
for(int i=1;i<=3;i++)
{
int nx;
if(i==1)
nx=f[t][1]+1;
if(i==2)
nx=f[t][1]-1;
if(i==3)
nx=f[t][1]*2;
if(nx>=0)
{
if(a[nx]==0)
{
w++;
a[nx]=1;
f[w][1]=nx;
f[w][2]=f[t][2]+1;
if(nx==y||x==y)
{
if(x==y)
cout<<0<<endl;
else
cout<<f[w][2]<<endl;
return ;
}
}
}
}
}
}
int main()
{
long long x,y,s;
cin>>s;
while(s)
{
s--;
cin>>x>>y;
abc(x,y);
}
return 0;
}
RE,求助