rt
#include<bits/stdc++.h>
using namespace std;
queue<int> l;
queue<int> q;
bool r[1000000];
int main(){
int t;
cin>>t;
while(t--){
memset(r,0,sizeof(r));
int a,b;
cin>>a>>b;
l.push(a);
q.push(0);
while(l.front()!=b){
if(l.front()<b){
if(!r[l.front()+1]){
l.push(l.front()+1);
q.push(q.front()+1);
r[l.front()+1]=1;
}
if(!r[l.front()*2]){
l.push(l.front()*2);
q.push(q.front()+1);
r[l.front()*2]=1;
}
}
if(!r[l.front()]-1){
l.push(l.front()-1);
q.push(q.front()+1);
r[l.front()-1]=1;
}
l.pop();
q.pop();
}
cout<<q.front()<<endl;
while(!q.empty()){
l.pop();
q.pop();
}
}
return 0;
}