#include<bits/stdc++.h>
using namespace std;
bool book[400005];
struct node{
int x,step;
};
int main(){
int n,S,T;
cin>>n;
for(int i=0;i<n;i++){
cin>>S>>T;
queue<node> q;
memset(book,0,sizeof book);
node ss={S,0};
q.push(ss);
while(1){
node hh=q.front();
q.pop();
if(hh.x==T){
cout<<hh.step<<endl;
break;
}
for(int i=1;i<=3;i++){
int temp;
if(i==1) temp=hh.x+1;
if(i==2) temp=hh.x-1;
if(i==3) temp=hh.x*2;
if(book[temp]==1) continue;
if(temp<0||temp>T)continue;
book[temp]=1;
int hhh=hh.step+1;
node hhhh={temp,hhh};
q.push(hhhh);
}
}
}
return 0;
}