#include<bits/stdc++.h>
using namespace std;
struct node{
int w,step;
}q[5000010];
int n,s,e,d,j,head=1,tail=1;
int main(){
cin>>j;
while(j--)
{
cin>>s>>e;
if(s==e)
{
cout<<0;
return 0;
}
q[tail].w=s;
q[tail].step=0;
book[s]=1;
tail++;
while(head<tail)
{
node t=q[head];
head++;
int ta,tb,tc;
ta=t.w+1;
tb=t.w-1;
tc=2*t.w;
if(ta==e||tb==e||tc==e)
{
cout<<t.step+1<<endl;
break;
}
if(ta>100000)
continue;
else
{
if(book[ta]==0)
{
book[ta]=1;
q[tail].w=ta;
q[tail].step=t.step+1;
tail++;
}
}
if(tb<0)
continue;
else
{
if(book[tb]==0)
{
book[tb]=1;
q[tail].w=tb;
q[tail].step=t.step+1;
tail++;
}
}
if(tc>100000)
continue;
else
{
if(book[tc]==0)
{
book[tc]=1;
q[tail].w=tc;
q[tail].step=t.step+1;
tail++;
}
}
}
}
}