#include<bits/stdc++.h>
#define sjh0626s
#define code
using namespace std;
int n,s,e,vis[300010],d1,d2,d3;
queue<pair<int,int> >q;
void clear(){
queue<pair<int,int> >emp;
swap(emp,q);
}
int main(){
cin>>n;
while(n--){
clear();
memset(vis,0,sizeof(vis));
cin>>s>>e;
vis[s]=1;
q.push({s,0});
while(!q.empty()){
pair u=q.front();
q.pop();
d2=u.first+1,d1=u.first-1,d3=u.first*2;
if(d1==e||d2==e||d3==e){
cout<<u.second+1<<endl;
break;
}
if(d1>=0&&vis[d1]==0)q.push({d1,u.second+1});
if(d2<=300010&&vis[d2]==0)q.push({d2,u.second+1});
if(d3<=300010&&vis[d3]==0)q.push({d3,u.second+1});
}
}
sjh0626s code;
}