#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=1e7+15;
ll dx[3]={0,1,-1},a[MAXN],b[MAXN],stl[MAXN],T;
struct node{
ll w,step;
};
node x;
queue<node>q;
ll fuckccf,tot,ans;
void bfs(){
for(ll i=1;i<=T;i++){
x.w=a[i],x.step=0;
stl[a[i]]=1;
q.push(x);
while(!q.empty()){
ll o=q.front().w;
ll p=q.front().step;
q.pop();
for(ll j=1;j<=3;j++){
ll xx;
if(j<=2)
xx=o+dx[j];
else
xx=o*2;
if(xx>=0&&xx<=100000&&!stl[xx]){
node pre;
pre.w=xx;
pre.step=p+1;
q.push(pre);
stl[xx]=1;
if(xx==b[i])
cout<<q.back().step<<endl;
}
}
}
}
}
int main(){
scanf("%lld",&T);
for(ll i=1;i<=T;i++){
scanf("%lld%lld",&a[i],&b[i]);
if(a[i]==b[i]) printf("0\n");
bfs();
}
return 0;
}